First request is very slow after website sits idle with ASP.NET MVC 3 (IIS7) - asp.net

I developed a project in ASP.Net MVC 3, my hosting is using iis7 (Win Web Serv 2008 R2), and the first request after the website sit's idle (during about 1-2 hours) is very slow.
I use VPS with 512Mb RAM. Can this be related with a too little RAM?
Can anyone help me with possible causes of such behaviour?

After a certain amount of inactivity IIS unloads the AppDomain. And then the first request loads the application once again which is slower. You could try to configure this period in the properties of IIS but there might also be other causes that an application unloads such as for example a certain threshold of CPU or memory usage is reached. Those thresholds are also configurable in IIS.
That's not something specific for ASP.NET MVC. It's true for all ASP.NET applications in general.

We had also this problem with ruby and passenger that takes the app out of memory after a while, but I found a nice application that fixed this issue for us without changing anything in the server configuration, the app is called wekkars, and you can find it here: http://www.wekkars.com

Related

Why session get expired

We have an application (ASP Dot Net , Framework 4.0) in production which is deployed on IIS 7.5 window server 2012. Every day this application gets around 4000 requests, but the problem we are facing for the last couple of days is that some of the users complain their session gets expired. We have checked the application and don't see any error that can get the session expired. We've checked the IIS setting and pool setting, but we don't see any reason fair enough to sort out the issue.
Please help us in this regard to get this sorted out.
Probably I need to give more detail that helps you resolve my issue.
We work in professional organisation where we run many application on IIS for our clients. The issue we receiving is coming on one of the same application we build for our new client and deployed on IIS 8.0 server 2012.
In web config of our application time out is for one hour and further we make sure that we shouldn't route the user to session expire page if any other error comes. Now after making these changes we are pretty sure that issue should not be due to application configuration or due to the structure of it.
Now we are concern about the IIS. The different thing this time is we are using IIS 8.0 not IIS 7.5 which we are using on our all different servers for different applications.
Some of the IIS configuration you might be interested
we have dedicated pool for the application further pool is configured 2.0 because application is on the framework 3.5.
maximum worker process = 1
Pool recycle in 28 hours
Let me know if you could guide me anything specifically if that is related to IIS 8.0 because we are thinking of reverting back to 7.5, its our production application and clients are keep complaining about it.
The Life time of a session of a user is set by the developer / yourself. So you have privilege to set the time a user session time out at the desired time. Here is the format of th declaration in the web.config.
<sessionState mode="Off|InProc|StateServer|SQLServer"
cookieless="true|false"
timeout="number of minutes"
stateConnectionString="tcpip=server:port"
sqlConnectionString="sql connection string"
stateNetworkTimeout="number of seconds"/>
You can set the creation of cookies to true or false
Decide / dictate where the session information needs to be stored(server, database..)
These are some of the links that can help.
MSDN
MSDN2
I guess, you might have allocated the default application pool for this application in the IIS and the same application pool might have been shared among other applications too.
Step1: You should allocate separate application pool for each site in the IIS.
Step2: in application pool --> advanced settings --> Change the maximum worker process count to 1
If the above solution is not working, better try the solution which is given in https://technet.microsoft.com/en-us/library/cc781036(WS.10).aspx
Hope this helps.

Recycle and reload application pool on IIS7

Is there a way to recycle and afterwards reload an application pool?
My problem has been slow performance when logging in to my web application. I found out that the "Idle Time-out(minutes)" was sat to 20 by default. This caused the application to terminate when idle so that it can start up again on the next visit. After searching the web i found out that this value could be sat to 0 so it won't terminate. However, the first visit after recycling, an app pool have to create a new w3wp.exe worker process which is slow because the app pool needs to be created, ASP.NET or another framework needs to be loaded, and then the application needs to be loaded. Source right here
This means that every time the app recycles, the first visitor have to wait longer then the other visitors when logging in, doing some stuff and log out.
The web application is using the ISS from Dynamics AX 2009.
Sorry I thought you are working on IIS 7.5
But there was a beta for this in IIS7 actually.
I think you are looking something along the lines of this
A warmup module for IIS 7.5
"IIS Application Initialization for IIS 7.5 enables website administrators to improve the responsiveness of their Web sites by loading the Web applications before the first request arrives. By proactively loading and initializing all the dependencies such as database connections, compilation of ASP.NET code, and loading of modules, IT Professionals can ensure their Web sites are responsive at all times even if their Web sites use a custom request pipeline or if the Application Pool is recycled. While an application is being initialized, IIS can also be configured to return an alternate response such as static content as a placeholder or "splash page" until an application has completed its initialization tasks."
Download Link
http://www.iis.net/downloads/microsoft/application-initialization
And also have a look at this; which basically talks about using warm up classes which comes with ASPNET 4
http://weblogs.asp.net/gunnarpeipman/archive/2010/01/31/asp-net-4-0-how-to-use-application-warm-up-class.aspx
Checkout the suspend option.
IIS now has
Idle Time-out Action : Suspend setting
Suspending is just freezes the process and it is much more efficient than the destroying the process. Because it uses the same process and does not create another one after waking up.

How do I decrease first load time in ASP.net MVC 2?

I have an ASP.net MVC 2 application that runs well locally. However when I move the files to my production server, I get a first time lag of about 30 seconds, I assume this is a first compile. After that the application works fine. Then after about 20-30 minutes of non use, the applications takes another 30 seconds or so to load.
I did try to precompile the code, but there is still a lag during the first load.
Are there any trick to getting the application to work faster on the first load?
I am using ASP.net 3.5, IIS 6 , visual studio 2010, MVC 2.
Thanks
Scott Gu has a good blog post here
EDIT:
There is a similar post here on serverfault, which might be useful.
I decided to write a Windows Service application to call my pages every 10 minutes, so far it's working well.
Essentially, the application pool is idle and is automatically shutting down the worker process. Then, when you try to access the page, it needs to start up the worker process and get everything ready.
If you're running under Server 2003, you can tell it not to shut down the worker process. Benson Yu has a good response here:
http://forums.asp.net/p/1307768/2666610.aspx
Essentially, go to IIS manager, find your asp.net 3.5 application pool that hosts your application, and modify it's performance properties to either not shut down the worker process, or to have a longer timeout.

How to speed up Visual Studio Webserver (Cassini)?

for my webapp the integrated Visual Studio Server (Cassini) ist much slower than IIS. How can I speed up Cassini so that i dont have to wait for 3s for every small page?
Are you seeing this on a Web Application Project or a Website Project?
If it's a Website, then the issue just may be that the Development Server needs to compile each page the first time it's executed. Are subsequent requests of the same page faster?
If it's a Web Application Project then Visual Studio compiles it all before the Development Server runs it. In this case, are you sure it's the Development Server? Is there the same delay for EVERY page in the application?
Also, Are you sure it isn't disk or database latency?
Determine why you think the web server is the culprit.
How did you determine that it was the web server? How did you measure this 3 seconds? Is it on every page, or just certain pages? Is it continuous, or does it get better after a while?
Determine what aspect of the slow web server is the problem.
Is there a lot of CPU in use? Memory? Are there other things happening when this happens? When you're using IIS, are you running on the same computer that had the slow Cassini? Is everything else the same? Same database server? Same hard disks in use?
You've got to narrow things down, as in any performance analysis.

How to keep ASP.NET assemblies in AppDomain alive?

Scenario: I've an n-Tier enterprise ASP.NET application deployed using Web Deployment Projects. All tiers produce independent assemblies that is consumed by the ASP.NET application.
Problem: When I run the app. for the first time after deployment it takes lot of time to load dependent assemblies in memory. But once loaded its lighting fast app. In case if there are no users accessing the app, IIS unloads the assemblies from the memory and when a user tried to access the app on a later instance it goes on loading all the assemblies once again taking the same amount of time to load as it takes to do so for the first time.
I'm looking for a solution that enables me to keep my assemblies loaded into memory persistently overriding the volatile nature of assemblies towards memory residency.
Or any other solution that lets my users happily use the app resolving the mentioned problem.
In IIS 6, go to the Application Pools section, and right-click > Properties on the pool which hosts the ASP.NET application in question. Go to the Performance tab and uncheck "Shutdown worker processes after being idle for:"
In IIS 7, go to the Connections pane and find Application Pools, and select Advanced Settings for the pool which hosts your application. Find the "Idle Timeout" property and set it to "0" (this disables it).
The default is 20 minutes of inactivity. By unchecking the box, once your AppDomain is loaded by the worker process, it will never die (unless you kill the process or something of course). By default, IIS will recycle the process when it reaches some limit, such as a memory cap, but it will also start a new one and "phase over" all incoming requests until the old one is unused, so as to minimize disruption.
I've also written a small c# class which will keep your ASP.NET application alive (alternate archived version) under normal circumstances. Since it runs within the application, obviously it can't stop IIS or anything else from explicitly killing the process, but it will keep the application "hot", e.g. the app will never go idle long enough for IIS to decide to shut it off.
If you do not have direct control over your IIS configuration (shared host, for example) your best bet is to have a small application running on a separate system - say, an always-on workstation - which hits your site every x minutes to keep the application pool from timing out. Nothing fancy - a simple WebRequest and a while() loop in a console application will do.
One of the advantages of ASP .net is the posibility to create static (shared) instances of objects.
To avoid the necessity of an external process you can create an static timer in (per example) global.asax which calls for a page on the domain with a simple WebRequest. On this way the site keeps alive himself until a manual reset of the pool is done.
I wrote a little C# console application that keeps my 4 sites alive every 10 mins via windows task scheduler. Life is once again good. We do not run the app from 2-5am just so the serves can do any cleanups of memory, if it even matters. for our sites there is rarely anyone on at those hours anyway.

Resources