问题
I have a web application written in ASP.Net 3.0 using C#, the production machine is a windows server 2003 with IIS 6.0 and sql server 2005.
Application Structure
The following shows the structure of my ASP.net web application:
root application in IIS (//localhost/es) includes the common pages, for instance: master pages, theme, user control, images folder. number of sub-projects under the root application (//localhost/es/sub-project). delete web.config in sub-projects assemble files of sub-projects is under bin folder of root application (sub-project properties >> compile >> build output path: ..\bin\ my application is a 3–tier web application(Biasness layer ,Data layer and Presentation layer. Also, every aspx page has its code behind cs file)
IIS Settings
Application pool
Recycling Worker Process after "1740 in minutes"
Idle timeout worker processes after being idle "20 in minutes"
Ping worker process every "30 seconds"
Startup time limit for worker processer "90 Seconds"
Shoutdown time limit for worker processer "90 Seconds"
Application Configuration
Cache limited ASP files in memory "500"
Cache limited ASP files on disk "2000"
Deploying Application:
I publish the web application with all its files to production server.
The Problem :
The application runs pretty slow at the first time, it takes upwards 10 seconds to load, however every at the next time a page is requested it's be faster. I believe that the first time a page is requested, it compiles and it usually takes more time than the other requesting, because the page is in the Cache Memory. The question here is why it's take along time when compiling the page at first time?
Attempts to solve the Issue :
I tried to do the following :
- Deploying a copy of the required files to production server.
- Changed IIS settings, changed Idle timeout shut down of worker process
- Turn off Tracing
- Turn off Session State
- Disable View State of a Page
- Set debug=false in web.config
- Creating a hello world sub-project under the root application , it takes 5 seconds .
- Creating separate hello word web application , as above it takes long time to load.
- Remove the code in the page_load event handler , but it didn't affect on the performance.
- Publish only the needed file of the root application (no code written in the code behind), and all file in the source code of sub-project (code is in the code behind) ,
However, the application still starts of slow but then it gets faster.
Please help to diagnose and solve this problem.
回答1:
In addition to what sky said, you could run a "warmup script" as the last step of your deployment process. Although this won't speed up the time needed for the first compilation, using such a script would at least prevent users seeing a slow startup. Have a look here for an example of such a script: http://programmerramblings.blogspot.com/2008/09/aspnet-site-warmup.html
Another reason why the very first request to your application is slow could be that IIS has to start the asp.net worker process during the very first request. This should however not affect first requests to other pages.
回答2:
publish the website, which precompiles, as opposed to copying it.
The behavior you are experiencing is normal.
回答3:
I had the same in ruby on rails application with passenger but I found a nice tool ( http://www.wekkars.com ) that just prevents the webserver to go to sleep.
回答4:
You can also use Auto start application feature which is available for .net framework 4 web applications. For more info visit here.
回答5:
try pre-compiling your site:
http://msdn.microsoft.com/en-us/library/ms227972.aspx
回答6:
VBscript + Dos Batch file... run every 1 hr
Dim strNewTime , strSiteName
strNewTime = Now()
strNewTime = Replace(strNewTime, "/","")
strNewTime = Replace(strNewTime, " ","")
strNewTime = Replace(strNewTime, ":","")
strSiteName = "https://www.yoursite.com/userlogin.aspx?dummytime=" + strNewTime
Dim oXMLHTTP
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.6.0")
oXMLHTTP.Open "GET", strSiteName, False
oXMLHTTP.Send
If oXMLHTTP.Status = 200 Then
' working
ELSE
CALL SendEmail("!!! www - web site is NOT working... " + strSiteName + " *** ")
End If
Set oXMLHTTP = Nothing
回答7:
There will always be a slight delay on first load of any .NET application due to CLR component in .NET Framework platform. Because JIT(Just in Time) residing inside CLR (Runtime Environment for ASP.NET) converts Intermediate Language (IL) to native machine code, it will always take little bit longer on the first execution for the .net applications.
A detailed video on this specific issue can be viewed on:
https://www.youtube.com/watch?v=ruf4U9_Rbss&index=1&list=PL8598C97BA1D871C1
Hope it helps.
回答8:
For asp.net applications running on IIS 7.0 and lesser versions, writing a warmup program or script is a best way to prevent the app pool idle timeouts. This warmup trigger can be setup from the same application or from the external websites or programs. You can find different ways to achieve the same in this article
回答9:
There is no way around this. You will always get a slight delay on first load as the site compiles.
来源:https://stackoverflow.com/questions/2221292/asp-net-application-runs-slow-at-first-time