I have an ASP.NET app running in IIS. The first time a call to the application is made, it can sometimes take extremely long (e.g. 80 seconds), whereas the second time it's very quick
I know this has to do with the app first starting and possibly needing to gather resources etc. However, the problem is that I can run the same identical app on another machine and the load time for the first call is significantly less.
So I'm wondering what factors on the machine would affect this load time?
Thanks for any assistance
I agree with Steve's comment. FYI this slow response on initial request will happen every time the app pool has been idle for a while too. You can combat this by disabling the app pool from shutting down when idle. I think the default is 20 mins, this is a setting in IIS.
Then you will only suffer the problem every time the app pool recycles. You can stop this happening but I don't advise it. Interesting article on this here http://weblogs.asp.net/owscott/archive/2013/04/06/why-is-the-iis-default-app-pool-recycle-set-to-1740-minutes.aspx Recycling the app pool every now and again protects you from memory leaks. However you can pro actively spin up the app pool by setting up a scheduled task that runs a batch file to make a request to the website on detection of an app pool recycle.
This ensures that your site is always spinning and good to go for every request.
ASP.NET only compiles when the page is requested for the first time. This means that on first load the page is being compiled and then displayed. This can be solved by following the precompile instructions from Microsoft.
http://msdn.microsoft.com/en-us/library/ms227972%28v=vs.90%29.aspx
EDIT: I realized that I didn't answer the question that you were really asking.
There are a few things that could affect the first load:
1) The browser you are using may not be as efficient at displaying the type of content on the page (assuming different browsers).
2)If the machines aren't running on the same internet connection(and even if they are speeds vary between wifi/ethernet) this could be affecting the overall speed.
3)The specs on the machines themselves can be making a difference, browsers still take up resources to run, and as such a faster computer could display quicker (although it wouldn't make a giant difference).
4)You said the app was running on IIS, but you didn't specify whether it was a local (test) server or a deployed server. If it's local the specs of the machine again come into play, and in a giant way. Booting an IIS server, deploying the app and then displaying pages (what happens when you click run in VS or similar) can take very different amounts of time depending on the machine.
Related
I'm working on a legacy application built on ASP.NET Webforms and .NET Framework 4.6.2.
The application's initial page is very slow to start on my local machine and I'm trying to troubleshoot it. I put a breakpoint on Global.asax Application_Start method, and it's taking quite some time even before the breakpoint is hit. I'd like to know how can I track exactly what happens before the Application_Start event (what calls are made, external libraries used, etc.), from the moment I make the first request to the server, so I can get a starting point to improve the performance. Thanks in advance.
Well, while in VS create (or open) some aspx page with JUST hello world on it. Does that page take a long time to load?
And to be fair, create a brand new blank asp.net webforms project, and find out if that project also is slow to load.
In other words, this just might mean your computer is slow.
When you hit f5, then:
The project code is compiled. Then a bunch of information is "copied", setup, then configured for IIS to launch. Then a WHOLE web server is launched (IIS express), then the web page is loaded, and then IIS processes that page, and then it is rendered.
In other words, a BOATLOAD of startup stuff occurs. Once that WHOLE big web server is spooled up, then and only then does your application start and all that jazz start.
If you can navigate to another page (say from the menu bar (assuming your application has one), and then BACK to that supposed page that loads slow? Does that page load slow the 2nd time you hit that page?
If that is the case, then your computer might be slow, starved for memory, or even starved for processing to start up the WHOLE system of stuff required to run that whole web server.
if once the page is displayed, and everything runs normal, then this is not a slow loading web page, but in fact a slow load WHOLE web site, and in actual use and production of the system, then it not really slow anymore is it?
So, say if your computer only has 8 gig, and say a low or slow laptop processor, then startup of all the "enormous" moving parts required to run a whole web server system might be the issue, and NOT that the page load is really slow.
And since the production system will not be re-loading from 100% scratch each time a whole web server system, then you may well not have a slow system, but only a slow "first time" startup.
So, do other web site projects based on .net framework, and asp.net pages start out slow?
And is this a asp.net web site, or is this a asp.net web site (application) project?
So, quite a bit of "hand stands" will occur on first run and load of the web site. So, this could be your computer, and not really that the web site is slow.
Having stated the above?
I have some found web site projects RATHER slow to load, and this is especially in the case of a asp.net web site application. (as opposed to web site's, which tend to load a WHOLE lot faster - about 1 second, and the other was taking about 18-23 seconds on my old laptop (it was starved for processing).
On a older laptop, I was seeing about 18-23 seconds delay after hitting f5. On my newer laptop, I have about 2, sometimes 3 seconds delay from the time I hit f5 in code or markup to see the results and web site running.
So, often IIS has to be loaded and started, maybe SQL server started, and even more bits and parts. All of these things can take a LONG time on your dev box, but on a production server, all of those things are running all the time.
So, it not clear if you have a very slow web site, slow loading "specific" web page, or you just talking about the overall slow loading time for "any" first page to display, and then after that, everything is fine? In other words, it is f5 to start things going is the slow point in time.
And you didn't even note how long of a delay and time here?
Are you talking about 5 seconds, or 50 seconds?
Right click on your task bar, task manager.
Here is me hitting f5 on my laptop. Note the 6 cores go 100% max speed and power during that startup.
I do know that on my laptop, when I hit f5, then all 6 cores (12 threads) jumps about about 2ghz to 4 ghz, and all 6 cores are pinned for those 2-3 seconds while that whole web server is created, configured, and THEN started, and then the page in question has to load.
So, here you can see that hitting f5, the web page "starts" almost instant, and then about 4 seconds more.
(the processor usage is somewhat high - part of that is due to running the screen capture for this screen shot).
So, as "soon" as I hit f5, you can see the processor jump above 20%. I count about < 1 second for the browser to appear. Then about 4 more seconds. And the above is a slower to load page. And as soon as the page displays, then you see the cpu drop down.
As noted, try creating a new asp.net web site "application". A web site, they tend to load < 1 second. In fact above is the "by far" slowest startup I have. Most are about 1-2 seconds from hitting f5.
A asp.net web site application? They take longer - the whole site has to be compiled each time, and the .dll's have to be created.
Sometimes, it simple things like some virtual folder mapped to a location that does not exist (so on startup, a non existing folder or path name can take some time to "time out".
so, how fast does a new test project (create a new asp.net web site application (create a application, not a web site). I find that web sites load fast - even on computers with limited hardware.
However, asp.net web "applications" tend to load a WHOLE lot slower. (and thus more ram, and more cpu, and more cpu cores makes a HUGE difference in startup times).
Performance is a real art form in our industry. But, a few more details such as do all "application" sites start slow on your dev box, or JUST this one, and by how much compared to other sites.
Often, a delay can be network connection to a database, and say little or nothing to do with startup, but some network delay in say connecting to sql server which may well be some kind of network connection.
So, all first pages slow, or just one page?
does a new asp.net web site application (application is important here - not just web site) also startup slow? (if yes, then this is not specific to your site, is it???).
And using task manager - do you see high cpu usage during that startup (f5), or is it low? (this then suggests network and connection delays - not cpu and memory and performance issues.
So, a lot more trouble shooting here is required, but then again, we have little idea as to what testing you done so far, such as testing another web site application on your computer - and does it have things like authentication and sql server logon's involved.
I mean, we can have some issues with a car that will not start. So, we don't just yet swap out the engine, re-do the fuel injection system, and then ONLY to find out we forgot to put in a new battery, and that was the issue all along.
So, do a few tests - get some base-lines of say a test site - use one of the templates that has the "default" bootstrap menu, master pages etc. How fast does that start? Since if that site ALSO starts slow, then attempts at troubleshooting the existing site will be in vain, since all sites load slow - not just the "one" site your working on.
Sometimes my MVC 4 application starts very slowly, but all the following requests come up quickly. It's running on IIS 8 and it uses Forms authentication.
The first start-up might take 20 seconds or so. I'm not 100% sure how long does it take to get a slow start-up again, but I guess it's more than an hour.
It's the same issue as described here:
MVC slow if site has been idle
So checking out the Application Pool recycling thing, I stopped the application pool, started it again, then browsed to the address, but it still came up quickly. I then ran the Powershell command (Get-Process -Id ).StartTime on the IIS, and it told me that last recycling for this application pool was when I started it.
I suppose that exludes the pool recycling?
The project is using Devexpress MVC layout, and I have removed all the assemblies/references that I don't need, but I didn't notice much difference afterwards.
The other applications on this IIS are made with Web forms, and they always come up quickly. The other applications also don't have the Forms authentication.
As a workaround I'm about to make a service that opens the address every 30 minutes or so, but still would be interested to figure out the real cause.
Any ideas?
Its may happen sometimes if configuration is not made properly.
You can use following techniques for improving performance.
1. Enable compression;
2. Optimize caching;
3. Optimize CSS;
4. Optimize HTML;
5. Optimize images;
6. Optimize callback management;
7. Optimize data management.
Please find a link here for more details how can we improve performance of website while using devexpress.
Devexpress support describes a lot about each small points regarding performance.
https://www.devexpress.com/Support/Center/Question/Details/K18541
Firstly let me apologise, as I don't really know how to phrase the question.
The issue I'm having is trying to keep my database 'alive' while users come to my site. An example being, if I build my c# asp.net application and publish it, then try and navigate to it, it takes a while to respond (which I get, I understand it, this isn't an issue for me) the problem is if some person hasn't been to the site for a while, it seems to take a while again, like a session timer has passed, I'm not sure if this is something to do with App Pool recycling?
I've tried to run a scheduled task to hit the database (trying to keep it responsive) every 15 minutes, but this doesn't seem to work, it works well every 15 minutes for say 5 hours, and then I receive a message on a random call that the request has taken over 4 seconds to respond and therefore fails.
My question then, how do I keep my connection to the database / the site responsive so that each time a person requests it, the site loads quickly, rather than having to 'start up'
Kind regards as always
I suggest to increase connection pool size in your connection string.
This looks like what you want:
Keep an ASP.NET IIS website responsive when time between visits is long: Keep an ASP.NET IIS website responsive when time between visits is long
You might consider IIS application auto-start?
Some web applications need to load large amounts of data, or perform expensive initialization processing, before they are ready to process requests. Developers using ASP.NET today often do this work using the “Application_Start” event handler within the Global.asax file of an application (which fires the first time a request executes). They then either devise custom scripts to send fake requests to the application to periodically “wake it up” and execute this code before a customer hits it, or simply cause the unfortunate first customer that accesses the application to wait while this logic finishes before processing the request (which can lead to a long delay for them).
ASP.NET 4 ships with a new feature called “auto-start” that better addresses this scenario, and is available when ASP.NET 4 runs on IIS 7.5
Here is my problem:
I have just been brought onto a massive asp.net C# project and I've been charged with fixing some performance issues (not my area of expertise). More specifically after 5 - 7 redirects/ajax calls the web server stops responding and the whole page (and eventually the browser) freezes.
I don't think this is a coding issue as I've set up break points in a few pages (Page_Load method) and after the 5 requests it does not even reach the break points.
I don't believe this is related to this issue as I've increased the browser's maximum connections per server parameter and I got the same behavior. Furthermore after these 5 request in one browser IE, the application stops working in FF as well.
This is not a resource issue as the w3wp.exe process never exceeds 500MB memory.
One thing I've noticed when using Fiddler and other tools to monitor the requests is that the server takes a very long time when loading image files (png, jpg). I don't know if this is relevant.
I've enabled failed request tracing on the server and the only thing I've noticed is that some request fail with a 401 error even dough I've set Anonymous Authentication to enabled.
Here is the exact message
MODULE_SET_RESPONSE_ERROR_STATUS
ModuleName ManagedPipelineHandler
Notification 128
HttpStatus 401
HttpReason Unauthorized
HttpSubStatus 0
ErrorCode 0
ConfigExceptionInfo
Notification EXECUTE_REQUEST_HANDLER
ErrorCode The operation completed successfully. (0x0)
This message is sometimes thrown with ModuleName: ScriptModule
I have already wasted 2 days on this thing and I'm running out of ideas so any suggestions would be appreciated.
Like any large generic problem, your best bet in diagnosing the issue is to figure out how to break down the issue into smaller parts, how to hypothesize the issues, and how to validate or invalidate your hypotheses. My first inclination would be to hypothesize that the server-side processes in this particular are taking a long time, causing your client requests to block, making the whole thing seem frozen.
From there, I would attempt to replicate the long running server side processes by creating isolated client side tests - perhaps if the URLs are HTTP gets, I would test the same URLs individually. If they were HTTP posts, I'd create an isolated test form if feasible to see what happens with each request. If a long running server side process is found then you have a starting point.
If there are no long running server side processes then it may be JavaScript / client side coding issues that need to be looked into. But definitely when you're working a large, unfamiliar project, your best bet is to figure out how to break down the issue into smaller components that can then be tested
I solved the issue finally. Here is what I did:
Experimented with IIS settings and App_Pool recycling and noticed that there is nothing wrong with the way it handles requests that actually reach it.
I focused on the Http.sys module and noticed that in the log files there were a lot of Timer_ConnectionIdle and Client_Reset errors.
After some more experimentation and a lot of Google searches, I accidentally found this answer and it solved my issue. As the answer suggests the problem was caused by the AVG antivirus installed and incorrectly configured on the server.
Thanks for all the help and suggestions.
If it's ajax calls that are causing your browser to freeze, make sure they are not blocking ajax calls.
Just appending to Shan's answer, which is a good one.
First off, there is obviously a code issue as this is by no means 'normal' behavior for IIS.
That said, you must isolate it as Shan indicated. For example, given the server itself no longer accepts connections then we can pretty well eliminate javascript as the source of the problem and relegate it to being just a symptom.
Typically when a worker process spins into space like this it is due to either an infinite loop or an issue where multiple threads are trying to lock the same resource. I bet if you let it run long enough IIS itself will timeout, kill and restart the process.
With that in mind you want to look for any type of multithreaded garbage (which I highly recommend you don't do in a web server) or for anything that indicates a tight infinite loop. A loop is going to become apparent if you execute the requests individually. A multi-threaded issue will only show up if you happen to get a collision.
Run various performance counters on the web server. Also, once it locks up, let it sit that way for awhile. Once IIS performs it's own reset on the worker process go look for indicators in the event log.
We have a server farm of about 40 servers that we roll code to every couple weeks. One thing we noticed when we roll the code live is after deploying the assemblies and performing an IIS reset and put it back in the BigIp (F5) and it receives traffic the server will lockup for about 10 minutes and clients will just spin until an eventual timeout.
Looking at the perfmon we can see a dramatic spike in number of finally's and number of pinned objects btw which lead me to investigate memory issues.
So one thing I started looking into it our Unity IoC configuration. In the global.asax.cs we are registering about 15 interfaces where most are using the ContainerControlledLifetimeManager to manage the lifetime. Normally there is never a problem with the code except in this ten minute window so my first thought was a memory or resource management issue.
Does anyone know if you have to explicitly Dispose() of your Unity Container or is this handled by Unity automagically somehow? I noticed today that there was no Dispose wiring in place for Application_End so my thought was maybe when the servers are brought back on after the IIS reset there is a Unity or object resource issue until the GC comes around and frees the memory (the ten minutes it takes to come up).
Any help is appreciated!
Performing an iisreset will kill the currently running w3wp.exe process, so it's unlikely that not properly disposing of unity objects in Application_End would cause performance issues on startup. It is possible that the old web process doesn't properly release file system or other resources the new web process depends upon, but I think you'd see file access or some other errors if that were the case.
Since you're performing an iisreset, I would look closely at the code that runs when the application starts for the first time. Maybe there are some components that take alot of time to start up (i.e., say there is a singleton type class that downloads and caches a bunch of stuff from the database) that are causing the slow down, possibly only when combined with the stress of handling all of the waiting HTTP requests. Also, keep in mind that ASP.NET will incur a bunch of overhead as it compiles the application to be used the first time. Since it seems that your web application is behind a load balancer, you may want to come up with a way to "prime" the application on each individual web server before you add that web server back to the load balancer, which could be accomplished by just loading a page locally on that web server. Priming the application would allow the web app initialize itself without having to handle any outside requests, which should improve the startup time.
Long story short, I would investigate startup issues and see what I could tune there before I focused on shutdown issues.