2

I am using Entity framework 6.2.0 with WebAPI hosted on azure app service.

My database is not big with only two tables and I have a simple select query

Account account =  Db.Accounts.Where(p => p.Code == Code && p.PersonId == 
PersonId).Include("Options").FirstOrDefaultAsync();

What i am struggling with is, when I deploy this on azure. and whenever i make the first call to the api which uses above query or when there is a significant gap of few minutes or 1 hour between two calls, Above process takes a long time to complete .almost 20-25 seconds, The next call is in less than a second.

I have confirmed, that it's definitely not my network latency or something else that is slowing this down.

Does anyone have a clue what I can look at?

My entity framework implementation is database-first.

AndreasHassing
  • 687
  • 4
  • 19
Mandar Jogalekar
  • 3,199
  • 7
  • 44
  • 85
  • Is your Azure App Service set to "Always On"? If not, what you may be seeing is the application starting up on each "cold" request. Subsequent requests within the time limit of going into standby should be fast if this is the case, and be slow after a while. Setting Always On to true should solve the problem if you're experiencing those behaviors. – AndreasHassing Jun 12 '18 at 13:06
  • 1
    How to you profile it to detect that the cause is the query? It seems like the first query is doing something else (application startup, compiling views etc) – CodeNotFound Jun 12 '18 at 13:08
  • This could be caused by any number of factors. Are you even sure this query is what the issue is? Not an application pool spinning up or something totally unrelated to the DB? – Liam Jun 12 '18 at 13:29
  • you can write logs to check which part is taking more time – Dhaval Pankhaniya Jun 12 '18 at 13:35
  • yes my appService is in AlwaysOn mode. I have put in logs which are telling me it is only being slow while actually querying the DB and not on any other operations like startups.The same query in the database or using ssms though is executed in a second – Mandar Jogalekar Jun 13 '18 at 05:25