0

I have an asp net core 2.0 mvc webpage using MySql, and the first request from a MySql database takes anywhere from 5-10 seconds to load, but any subsequent requests were much faster, about half a second each. Is there a way to load the MySql dependency when kestrel starts, so there is no lag-time on the webpage?

I've read about Assembly Injections, but those were based around core 1.0. How would I achieve this in core 2.0?

R. StackUser
  • 2,005
  • 4
  • 17
  • 24

1 Answers1

1

There is nothing to stop you from creating the DbContext at the end of your Startup.cs and reading some dummy data. On the other hand, what is 5 - 10 seconds among friends especially when it is only your very first friend to hit the website. After all, that will generally be the person or process that deploys the app, making sure that everything went ok.

GlennSills
  • 3,977
  • 26
  • 28
  • It turns out it was the MySQL database doing a reverse-dns lookup that took so long, and if it wasn't connected to again within a few minute timespan, it would lose the host information and take 5-10 seconds again with the lookup. I ended up creating a timer every few minutes to do an open/close db connection with MySQL that did the trick. Thanks for giving the idea – R. StackUser Oct 10 '17 at 18:47
  • 1
    That is actually a real long time for that lookup. – GlennSills Oct 13 '17 at 23:41
  • Yes it is, it's an old version of mysql I don't have any control over, but now any webpage db queries are instant as long as the db connection is opened once every few minutes. – R. StackUser Oct 15 '17 at 00:09