Trevor Bye
Trevor Bye

Reputation: 708

EF6 slow first query implications on deployment

Knowing that Entity Framework is slow on a cold query (first query after model compilation), I am doing some of the standard work around methods to speed it up. Mainly pre-compiled views as well as making a dummy http request on the client side as soon as the application loads to trigger a query to start the model process.

My question here is specifically around how this works for a deployed application. For example, if I deploy this on Azure, is it the first cold query for the entire application that will trigger the model compilation, or will this slow cold query happen for each individual user that uses the application? In simple terms, does it happen once and only once, or every time a user hits the site for a new session?

Upvotes: 1

Views: 161

Answers (1)

Joel Oughton
Joel Oughton

Reputation: 486

The EF slow start is triggered from the first request/s coming into the web server that requires database services.

A couple points to note,

  • If you deploy to an Azure web app, ensure that the 'AlwaysOn' application setting is enabled. If not, after a given time period the web app will be suspended and the next request will trigger another cold start.
  • Similarly if you deploy to a VM with IIS you'll need to check the application recycling settings.
  • When you deploy a new version of the application code, the process will need to be restarted which will cause another slow start.

A good approach to mitigate such slow starts is by using deployment slots and pre-warming slots before sending actual user traffic to it. This is straightforward to achieve using Azure Web App deployment slots.

Upvotes: 1

Related Questions