第一次运行ASP.Net应用程序时运行缓慢 [英] ASP.Net application runs slow at first time

查看:101
本文介绍了第一次运行ASP.Net应用程序时运行缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用C#用ASP.Net 3.0编写的Web应用程序,生产机器是带有IIS 6.0和sql server 2005的Windows Server 2003.

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.

应用程序结构

以下显示了我的ASP.net Web应用程序的结构:

The following shows the structure of my ASP.net web application:

根应用程序包括公用页面,例如:母版页,主题,用户控件,图像文件夹. 根应用程序下的子项目数(//localhost/es/sub-project). 删除子项目中的web.config 子项目的汇编文件位于根应用程序的bin文件夹下(子项目属性>>编译>>构建输出路径:.. \ bin \ 我的应用程序是3层Web应用程序(Biasness层,Data层和Presentation层.而且,每个aspx页面的代码都在cs文件后面)

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设置

应用程序池 "1740分钟后"后的回收工人流程 空闲"20分钟"后空闲的超时工作进程 Ping Worker每隔30秒处理一次
工人处理器的启动时间限制为"90秒" 工人处理器的关闭时间限制为"90秒"

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"

应用程序配置
在内存"500"中缓存有限的ASP文件

Application Configuration
Cache limited ASP files in memory "500"

在磁盘"2000"上缓存有限的ASP文件

Cache limited ASP files on disk "2000"

部署应用程序:

我将Web应用程序及其所有文件发布到生产服务器.

I publish the web application with all its files to production server.

问题:

该应用程序在第一次运行时运行非常慢,需要花费10秒钟以上的时间来加载,但是,每当下一次请求页面时,它就会更快.我认为,第一次请求页面时,它会进行编译,并且通常比其他请求要花费更多的时间, 因为该页面在高速缓存中. 这里的问题是,为什么在第一次编译页面时会花费一些时间?

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?

尝试解决此问题:

我尝试执行以下操作:

  • 将所需文件的副本部署到生产服务器.
  • 更改了IIS设置,更改了工作进程的空闲超时关闭
  • 关闭跟踪
  • 关闭会话状态
  • 禁用页面的查看状态
  • 在web.config中设置debug = false
  • 在根应用程序下创建一个hello world子项目,这需要5秒钟.
  • 创建单独的hello word Web应用程序,如上所述,它需要很长时间才能加载.
  • 删除page_load事件处理程序中的代码,但不影响性能.
  • 仅发布根应用程序所需的文件(没有代码写在后面的代码中),所有文件都在子项目的源代码中(代码在后面的代码中),
  • 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.

推荐答案

除了天空所说的那样,您还可以运行热身脚本"作为部署过程的最后一步.尽管这不会加快第一次编译所需的时间,但是使用这样的脚本至少可以防止用户看到启动缓慢的情况. 在这里查看此类脚本的示例: http://programmerramblings.blogspot.com/2008/09/aspnet-site -warmup.html

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

对应用程序的第一个请求很慢的另一个原因可能是IIS必须在第一个请求期间启动asp.net worker进程.但是,这不应影响对其他页面的首次请求.

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.

这篇关于第一次运行ASP.Net应用程序时运行缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆