-1

This issue has been opened several times before, but has not been resolved. The first query is recognized as slow and the performance of the queries increases significantly later. The project I'm working on is a multi-user Project. It's not possible to tell users to use it that way. I'm having serious problems with this. What can be done to speed up the initial query?

  • https://stackoverflow.com/questions/30423838/entity-framework-very-slow-to-load-for-first-time-after-every-compilation/30424382#30424382 and https://www.fusonic.net/developers/2014/07/09/3-steps-for-fast-entity-framework-6-1-code-first-startup-performance/ – rene Jan 17 '20 at 13:02

2 Answers2

0

You can improve performance setting publish config to "Precompile during publishing". It's is a simple way to get a faster initial request. Config to precompile

What happens, however, is that in the first database request, Entity Framework starts the model and it takes additional time, you can avoid this by making some query in the start-up of application. more here

It's maybe a problem with the application pool configuration in IIS, you can set to keep always on, and avoid the slow after a few minutes, more here.

fsbflavio
  • 664
  • 10
  • 22
0

I have done what @fsbflavio has suggested along with the App pool stuff and my first query is still always slow. Every query after the first query is fine.

I know this should not be my answer but until I find a better solution the following has worked for me.

My answer was to create a powershell script and to create a scheduled task to call it. For my situation, our servers are restarted nightly. So, I only need to schedule this to run upon restart and all queries work the rest of the day. Users of our web app no longer have to wait 10+ seconds for the first query.

Invoke-WebRequest -Uri "https://MY_URL/api/WakeUp" -Headers  @{"accept"="text/plain"; "apiKey"="MY_API_KEY"}
Ben
  • 1,820
  • 2
  • 14
  • 25
  • 1
    I 've edited my answer, see the link about the first query in startup application, it's a workaround option too. – fsbflavio Jan 17 '20 at 13:30
  • @fsbflavio - Thanks. I am working on a new application right now. I will add that to the Application_Start and see what happens. Much easier than the powershell script. To be honest, I haven't had to think about this for quite some time now because the powershell script just works but I would much prefer a code solution. – Ben Jan 17 '20 at 13:42