一个疑惑

来源:互联网 发布:centos 网卡dhcp配置 编辑:程序博客网 时间:2024/04/29 00:19

学习ASP.NET有些时候了,对于每次的首次运行时的挺慢的速度都没有特别在意。然后在看书时看到有这么一段:

The first time you access the ASP.NET page ... the most remarkable thing you will see differentiating it from the traditional ASP version is the amount of time it takes for the page to load. It is slower. Quite a bit slower, in fact. Any subsequent access to that page, however, will be markedly faster. The overhead you will see on the first access is the launching of the ASP.NET worker process plus the parsing and compilation of the .aspx files into an assembly.

这段话中说到的asp.net worker process就是aspnet_wp.exe。在任务管理器中是可以看到这个进程的。只是不明白,asp.net与传统的asp之间的一个显著的差别就是asp.net的页面是需要首先编译才能运行的。这就是我在项目的bin目录中总可以看到一个.dll文件。那么首次调用的开销来自哪里?加载aspnet_wp的开销吗?这段话解开了我的疑惑:

...once a page is accessed for the first time (or any page within a particular directory is accessed), subsequent rendering of that page is serviced by executing compiled code.

 这让我想起另外一个服务器端的脚本语言JSP来了。.jsp也是在第一次被调用时被编译成一个applet类。所以也会象上面说到的那样第一次调用时会明显感觉到速度的延迟。而接下来的调用将会是速度如飞了。不过在tomcat中会有一个临时目录来存放编译生成的.class,IIS中这个编译后的页面文件又是存放在哪儿呢。另外既然如此,那又为什么asp.net必须先编译才能使用?不明白。