My ASP.net MVC 4 site gets slow on first request to SQL Server Express 2012 - asp.net-mvc

I have an ASP.net MVC 4 site and it gets slow on the first request.
It is not high slow but pages that use to long 1000-700 ms on load, the first time it longs 8-15seg. It occurs when i wait for 10 minutes for example and come back to make a request. The web site is not on production server yet. May it be when the app pool does not receive any request it goes to sleep?.
I have configured the new AutoStart mode in framework 4:
http://weblogs.asp.net/scottgu/archive/2009/09/15/auto-start-asp-net-applications-vs-2010-and-net-4-0-series.aspx
I think it may be the first request to the SQL Server Express 2012 (in the same server).
I have set the autoclose=off in the database.
What more can i do?. How could i see what is going on the first request to avoid that slow response?.

Thanks to every one who has apported to this question.
Finally i think it has to do with the idle time configuration in the App pool.
It was set 5 min (default) and i have set it 60 min. and now it goes fine!
Thanks to this question:
First request is very slow after website sits idle with ASP.NET MVC 3 (IIS7)

You can compile the views for faster performance.
The documentation is for MVC 3, but it should still work:
Compile Views in Asp.Net MVC 3 with Visual Studio

Related

ASP.NET in debug mode gets random timeouts against a local SQL Server 2019 database

This problem occurs only in debug mode with my ASP.NET MVC application. In release mode, everything is ok.
In debug mode, I can pass through my login process let's say 2 out of 10 times. All I usually get is a timeout on a Linq query (EF6) applied on a 50000 rows database table. Is there any options in Visual Studio that would explain this?
It usually takes a few (long) seconds between me clicking on a button and the controller's method being called. And when I'm debugging and try to execute a linq query, I get SQL Server timeouts a lot of times.
Deleting the web site cache helps a little but something else is wrong, probably with Visual Studio itself

ASP.NET caching startup values

I'm converting an application from C# WebForms to MVC.
The application gets settings from a centralized location using Web Services. These are settings you would typically find in a Web.Config, but the desire of the company is to store these values in a centralized location for all apps.
Currently, any time you request an application setting, it checks HttpContext.Cache to see if you've already retrieved the settings. If you haven't, it makes the web service call, and stores the settings (100+ objects that are essentially key/values) in the HttpContext.Cache. So the call to get application settings only occurs once.
Should I be looking at another way to do this? I was thinking the settings should just be a REST service call where you pass the key and get a value (the current service is an *.ashx which is really not ideal for exception handling amoung other reasons). But obviously this would result in more web requests. What is considered a best practice here? Is the current method fine and I should just leave the code working the same in the MVC app?
It is better to load all resources in one call:
fewer HTTP requests are better for performance. Http requests can have a latency around 50 ms thus it will take much longer to get all values one by one 50 x 100 = 5000 ms => 5 secs
if the external web service goes down then your application still works because you already downloaded and cached all values
I will keep the current solution if it works and focus on new things instead of rewriting a working code.

In MVC 3 and IIS 7.5 server intermittent page response issue

In our IIS 7.5 server(load balance server) system intermittently delays the page response of an ASP.NET MVC 3 application up to 90 seconds or so, even though same page renders in 0-1 second most of the times. This happens randomly to particular page, and for POST type requests. Not able to tack the issue through IIS or fiddler. The request is http 302 post and If I run the fiddler or in chrome the issue is not coming. I am currently using IE 8. Much appriciated for the help.
I found the issue, it is due to the double post call in Ajax.

First Web API session request is very slow

I'm writing an ASP.NET Web API application hosted on IIS7 (no special configuration).
My problem is that for each first request (on a new machine/new browser/after a while...) there is a long delay - even on requests that return constants!
I've read about "warming up" scripts but it's not the issue here. It seems like the web server is trying to create a session and it takes very long time. Any suggestions?
EDIT
I think the delay is caused by worker-process creation for each new session. Now the question is why is it so slow, and why doesn't the web server reuse living worker-processes to serve requests?
I have configured the application pool to limit worker processes to 5 with no timeout (set to 0). This caused the first five sessions to be slow on first requests (which I can live with) and now the worker processes are alive. But surprisingly, from time to time, the request is slow again!
If you are using Windows Server 2008 R2 you could configure the Auto-Start feature on the Application Pool. Also in the properties of the application pool you should disable it from being recycled at regular intervals. Bear in mind though that while this will limit the slowness, the application pool could still be recycled by IIS. With the Auto-Start feature it will be loaded again automatically in memory, but the code in your Application_Start will be executed on the next request. So you could still observe some slowness.
Another cause can be https. Our site can run with and without https. The delay at the first page (5 to 15 seconds) occurs only with using https. This post explains the issue with https and the fix:
https issue by the MCS team

Random Session Timeout in ASP.NET MVC3

i have an application which gets random session timeouts. (IIS 7.5 on Windows 2008 R2, .NET 4.0)
i tried the following:
checked the application log if the w3wp.exe process was crashed, but there is no entry.
disabled in the application pool the rapid fail protection
moved to the sql server state provider to be sure the loadbalancers sticky session is not
the problem. (we use a kemp loadmaster).
ensured that no other applications use the same application pool.
checked that exceptions in a thread of a called assembly is correctly handled. (simulated using throw new exception) and the error handling was correct.
ensured that the validationKey and decryptionKey is set in the webconfig on all 4 webservers to the same key.
i run now out of ideas how to spot this evil bug. any suggestions? i cannot reproduce the problem on my local machine in the debugger.
one point which is maybe important, the move from page 1 to page 2 where the session loss often happens, takes sometimes more than 120 seconds, because of a third party system which is connected via tcp socket.
HI Snoopy you linked to my question as they are similar,
As my appool was crashing I tried this solution. If your appool crash's this may help
http://support.microsoft.com/kb/911816
the solution stop fix hack kept my app-pool up but didn't fix the problem,
<configuration>
<runtime>
<legacyUnhandledExceptionPolicy enabled="true" />
</runtime>
If your app-pool is still intact you might try ELMAH as this helped me a lot
http://code.google.com/p/elmah/
you can use this code to get ELMAH to handle unmanaged exceptions
http://code.google.com/p/elmah/issues/detail?id=199
I am curious if it is MVC 3.0 problem with .net 4.0
as i have several very similar apps running using MVC 2.0 with no problems,
Only started when I moved to MVC 3.0
Does it happen on a single server? Sure sounds like an issue with the web-farm.
Can you alter your app so you don't use the 3rd-party app for testing?
You have to eliminate pieces until the failure goes away, then add stuff back. Restore 3rd party app, turn other servers back on, etc.

Resources