I am using ASP.Net4 MVC2 for my application. The first person using the application usually experiences a long wait before the application responds. After that the application is pretty responsive. If the application is idle for 15 minutes, the same person or the next person using the application will experience long wait again. It looks like the application compiles after being idle for 15 minutes. Can someone tell me where I should look to trouble shoot the problem? Thanks.
It is almost certainly the case that what you are experiencing is app pool recycling. It's true it takes some time to re-initialize after the pool has been recycled, but it shouldn't take all that long. How long is a "long wait"? A second? Several? In IIS you can configure how regularly your app pool recycles. For IIS 7, right-click on your app pool and choose "Advanced Settings" then look at "Idle Time-out". You may consider increasing this value. (Or set to 0 to disable completely.)
You need to accurately diagnose the problem first before you start implementation solutions. First have to verify if it is, in fact, an app pool recycle. You can start by adding this section to your web.config:
<healthMonitoring>
<rules>
<add name="Application Lifetime Events Default"
eventName="Application Lifetime Events"
provider="EventLogProvider"
profile="Default"
minInstances="1"
maxLimit="Infinite"
minInterval="00:01:00"
custom="" />
</rules>
</healthMonitoring>
It will log an event to the windows event log anytime asp.net recycles itself. It will also gives a reason for the recycle (e.g., someone poked web.config, etc.). If it is a recycle, then you need to figure out why it is recycling. Is it because IIS is set to do it no matter what? Is it because your app is not handling memory correctly and memory pressure is causing asp.net to want to recycle itself? These questions must be answered first.
First determine if it is a recycle by adding to above configuration and why. Once you get the answer you can check memory, etc.
Have a look at the IIS7 application warmup extension.
http://www.iis.net/download/ApplicationWarmUp
Related
I have an MVC project, and I'm looking at speeding things up. One thing I'm scratching my head over is the BeginProcesRequest() which I have no control over. Using New Relic I found that this method is, on average consuming 90% of the time required for the transaction to complete.
The code in my controller is pretty simple. It has a look for an action session for the user and redirects to their dashboard if it finds one. there isn't any database calls on the actual page. The only written is:
if (Session["UserID"] != null)
// Perform actions
The BeginProcessRequest() method takes almost 4 seconds as you can see in the screenshot
This can't be something unique to my site? I'm using a small EC2 instance for the server, and although there are other applications running on the site the CPU and memory stay pretty much at 0 throughout the request.
EDIT - Reviewed the following post:
What happens in BeginProcessRequest()?
However as my application is idle when the most time consuming requests take place I can't see how it could be related to competing threads.
I think the issue was with IIS, as after I changed the property of idle time-out in the application pool to be one day it now seems to load much faster on initial start.
I also explicitly disabled the session state on my home controller, and ensured that SQL Server's auto close parameter was set to off.
I have an Active X control, which when first called or loaded in my asp.net application, is really slow to load. However, after the first load, it is really quick!!
My question is this, "How do I make my Active X control, when first called, load much faster? Is there away to preload the active x to the page so when it is used or called, it doesn't take so long to load?"
I have checked to see whether my active x is being called correctly by my javascript code, and it does. All my Active X does is to make a call to Outlook and to set some user properties. Not much.
Please help, but it has been doing my head in for days.
This is a known issue with the .Net Framework 1.1, 2.0, 3.0 and 3.5 You have a few options. Upgrade to the 4.0 Framework, preferably with IIS 7 which has the ability to ping your site and deep it alive. If you are not able to upgrade you could also use a ping utility to keep your site "alive". Basically what this does is it hits your site every few minutes so that you do not encounter the 20 min. default timeout period of you application domain. When you application domain times out it is reloaded on the next request, hence the slowness you are experiencing.
http://www.spikesolutions.net/ViewSolution.aspx?ID=c2b7edc0-5de1-4064-a432-05f6eded3b82
I have one doubt here , I have one asp.net MVC web application and every night we are recylcing the applciation pool from IIS. Now when the next day first request comes it is taking time to get response.
First request it is taking time because app domain is not loaded (application is not started) to start web application it takes some time.
Now the question is does the just in time compiler will come here again ?
Means every morning it needs to recompiled by JIT again ?
Yes, the application will be compiled from IL to executable code again after the recycle: Throwing away the appdomain will also loose the JITed native images.
You could, for instance, avoid some of the compilation by putting dependent assemblies that don't change often in the GAC, and use NGEN on them. That could possible speed up things a bit.
JITting will normally not have a huge performance hit. Cold startup of the IIS process, starting your AppDomain and loading your assemblies from disk will probably have much higher impact. Also, your application might have some custom startup logic in the global.asax file (reading stuff from db). And don't forget your database might have to wake up as well.
I used System.Timers.timer in global.as in asp.net to set a timer for scheduling execute a
function
let' say transferMoney().
But it seems that this timer might stop after several hours unexpected.
And this cause that all the actions are pending.
I want to know whether there are any better methods to set up a timer in asp.net, MVC 1.0?
Thanks in advance!
It might just be because the application got recycled. Global.ashx is not really the right place to do long running tasks because if your AppDomain gets recycled your timer will die. I suggest making a job windows service instead.
Edit: Well, it's fairly easy to create a windows service project in Visual Studio just do [File] > [Add] > [New Project...] > [Windows] > [Windows Service] and you will get the stub code for the project.
It's hard to come up with a complete example so i suggest you google it. ;) There are tons of samples out there for you to look at.
This article on CodeProject seems to be a good introduction to Windows Services.
Any timer you'll use in ASP.NET apps will eventually "terminate", but this a very expected behavior due to process recycling.
The timer will never work because IIS will reschedule the worker process regularly based on Application Pool settings, so when it recycles your timer will get destroyed and you might need to reopen it.
You can put a check on whether timer object is still available or not, if not available then create it !!, using any other timer object will not work. But this still has a problem, because if you dont have any web request for particular period of time, it will still get destroyed. Best is to setup a ping monitor from other place which can keep your website alive.
You can't reliably run a timer in ASP.NET. If there are no requests coming in, the IIS can shut down the application, and it will not start until the next request arrives.
Why do you think that you need a timer? In most web applications this is not needed at all to do periodical updates unless they depend on an external source.
If you are just moving data around inside your application, the actual transactions doesn't have to happen at an exact interval, you only have to calculate what the result would be if they had happened. Whenever a request comes in, you calculate how many transactions would have happened since the last request, and do them to catch up to the current state.
If your transactions rely on an external source so that they actually has to run at a specific time, you simply can't do it with ASP.NET alone. You need an application that runs outside IIS, for example started periodically by the windows scheduler.
You could try the system.threading.timer
http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx
Got a slightly odd one here.
We have an MVC site that is experiencing some instability. Once a week for the last couple of weeks the site has gone down. We have found that all we need to do to bring the site back up again is 'touch' the web config file (i.e. open it and save it, with no changes). This brings the site back to life immediately and keeps it alive for another week or so.
The site has custom error pages set up so we can't actually see the error that is being thrown, and there is nothing appearing in the IIS logs.
It looks like some kind of memory leak problem, however .NET garbage collector should manage this, right?
Any ideas?
Thanks,
Pat
You should have some kind of logging so that you can see what error you get. I usually use elmah. That will give you the full error message and stack trace. It's pretty hard to say what the problem is without knowing the error. But it can be a memory leak of some kind. Do you use a lot of unmanaged code? The garbage collector can't handle everything.
Touching the web.config forces recompilation and refreshes the app pool. My guess is something is knocking out your app pool, whatever it is will be in the event logs, i suggest you check there.