Asp.net 4.0,首次请求目录下的文件时响应很慢
原文:Asp.net 4.0,首次请求目录下的文件时响应很慢
1. 问题起因
2. 尝试过的处理思路
3. 解决方法
1. 问题起因
一个从VS2003(.Net Framework 1.1)升级到.net framework 4.0的项目,每次编译或者部署到服务器上后,首次请求任何一个目录下的默认页面时,都要耗时3~5秒;而以前使用.net framework 1.1的时候,没有这个问题。
我在页面上开启Trace="true"来跟踪,发现页面的处理时间并不久(IIS重启,首次打开页面时截获的信息):
但是IIS日志中,显示首次请求页面的耗时接近4.635秒。后续连续刷新页面,处理时间比较正常。。
虽然耗时比较久,但页面能够打开;然后我重启IIS,再次打开站点,用VS附加W3WP.exe来进行调试,再次打开这个页面的时候,发现抛出异常了:发生了 System.ArgumentException, Message=已存在具有相同键的条目。
1: 发生了 System.ArgumentException
2: Message=已存在具有相同键的条目。
3: Source=System
4: StackTrace:
5: 在 System.Collections.Specialized.ListDictionary.Add(Object key, Object value)
6: InnerException:
7: System.dll!System.Collections.Specialized.ListDictionary.Add(object key, object value) + 0x134 字节
8: System.Web.dll!System.Web.UI.ParsedAttributeCollection.AddFilteredAttribute(string filter, string name, string value) + 0xba 字节
9: System.Web.dll!System.Web.UI.TemplateParser.ProcessAttributes(System.Text.RegularExpressions.Match match, out System.Web.UI.ParsedAttributeCollection attribs = {System.Web.UI.ParsedAttributeCollection}, bool fDirective = false, out string duplicateAttribute = null) + 0x221 字节
10: System.Web.dll!System.Web.UI.TemplateParser.ProcessBeginTag(System.Text.RegularExpressions.Match match = {System.Text.RegularExpressions.Match}, string inputText) + 0x68 字节
11: System.Web.dll!System.Web.UI.TemplateParser.ParseStringInternal(string text, System.Text.Encoding fileEncoding) + 0x3d0 字节
12: System.Web.dll!System.Web.UI.TemplateParser.ParseString(string text, System.Web.VirtualPath virtualPath, System.Text.Encoding fileEncoding) + 0x6f 字节
13: System.Web.dll!System.Web.UI.TemplateParser.ParseFile(string physicalPath, System.Web.VirtualPath virtualPath) + 0x115 字节
14: System.Web.dll!System.Web.UI.TemplateParser.ParseInternal() + 0x57 字节
15: System.Web.dll!System.Web.UI.TemplateParser.Parse() + 0x64 字节
16: System.Web.dll!System.Web.Compilation.BaseTemplateBuildProvider.CodeCompilerType.get() + 0x6f 字节
17: System.Web.dll!System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(System.Web.Compilation.BuildProvider buildProvider) + 0x42 字节
18: System.Web.dll!System.Web.Compilation.WebDirectoryBatchCompiler.CompileNonDependentBuildProviders(System.Collections.ICollection buildProviders) + 0xca 字节
19: System.Web.dll!System.Web.Compilation.WebDirectoryBatchCompiler.Process() + 0x5d 字节
20: System.Web.dll!System.Web.Compilation.BuildManager.BatchCompileWebDirectoryInternal(System.Web.Hosting.VirtualDirectory vdir, bool ignoreErrors) + 0x48 字节
21: System.Web.dll!System.Web.Compilation.BuildManager.BatchCompileWebDirectory(System.Web.Hosting.VirtualDirectory vdir, System.Web.VirtualPath virtualDir, bool ignoreErrors) + 0xbc 字节
22: System.Web.dll!System.Web.Compilation.BuildManager.CompileWebFile(System.Web.VirtualPath virtualPath = {System.Web.VirtualPath}) + 0x5d 字节
23: System.Web.dll!System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(System.Web.VirtualPath virtualPath = {System.Web.VirtualPath}, bool noBuild, bool allowCrossApp, bool allowBuildInPrecompile, bool throwIfNotFound, bool ensureIsUpToDate) + 0x141 字节
24: System.Web.dll!System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(System.Web.HttpContext context, System.Web.VirtualPath virtualPath, bool noBuild, bool allowCrossApp, bool allowBuildInPrecompile, bool throwIfNotFound, bool ensureIsUpToDate) + 0x70 字节
25: System.Web.dll!System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(System.Web.VirtualPath virtualPath, System.Web.HttpContext context, bool allowCrossApp, bool throwIfNotFound) + 0x7e 字节
26: System.Web.dll!System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(System.Web.VirtualPath virtualPath, System.Type requiredBaseType = {Name = "Page" FullName = "System.Web.UI.Page"}, System.Web.HttpContext context = {System.Web.HttpContext}, bool allowCrossApp) + 0x35 字节
27: System.Web.dll!System.Web.UI.PageHandlerFactory.GetHandlerHelper(System.Web.HttpContext context, string requestType, System.Web.VirtualPath virtualPath = {System.Web.VirtualPath}, string physicalPath) + 0x20 字节
28: System.Web.dll!System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(System.Web.HttpContext context, string requestType, System.Web.VirtualPath virtualPath, string physicalPath) + 0x29 字节
29: System.Web.dll!System.Web.HttpApplication.MapHttpHandler(System.Web.HttpContext context, string requestType, System.Web.VirtualPath path, string pathTranslated = "。。。。。。。。。。\\order\\default.aspx", bool useAppConfig) + 0xa8 字节
30: System.Web.dll!System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() + 0x81 字节
31: System.Web.dll!System.Web.HttpApplication.ExecuteStep(System.Web.HttpApplication.IExecutionStep step = {System.Web.HttpApplication.MapHandlerExecutionStep}, ref bool completedSynchronously = true) + 0xb9 字节
32: System.Web.dll!System.Web.HttpApplication.ApplicationStepManager.ResumeSteps(System.Exception error) + 0x13e 字节
33: System.Web.dll!System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(System.Web.HttpContext context, System.AsyncCallback cb, object extraData) + 0xf8 字节
34: System.Web.dll!System.Web.HttpRuntime.ProcessRequestInternal(System.Web.HttpWorkerRequest wr = {System.Web.Hosting.ISAPIWorkerRequestInProcForIIS7}) + 0x1a2 字节
35: System.Web.dll!System.Web.HttpRuntime.ProcessRequestNoDemand(System.Web.HttpWorkerRequest wr) + 0x7d 字节
36: System.Web.dll!System.Web.Hosting.ISAPIRuntime.ProcessRequest(System.IntPtr ecb, int iWRType) + 0xfd 字节
37: [应用程序域转换]
38: [本机到托管的转换]
2. 尝试过的处理思路
我Attach到w3wp上去后,首次访问目录下的默认页面,catch到ArgumentException异常,然后根据异常信息,追踪到 TemplateParser.ParseFile -> ParseString -> ParseStringInternal -> ProcessBeginTag;然后我就尝试了下列努力:
1. 该目录下默认文件的<%@Page ....%>定义,属性与其他文件并没有任何不同(除了CodeBehind和Inherits的值),我把页面里面的内容一点儿一点儿删掉,最后是剩下空内容(只剩下head、body、form几个元素)、空后台代码,问题还依旧存在。
2. 我在这个目录下面,新建了一个页面(VS2010自动生成的,没有添加任何元素或标签),然后把这个新文件作为该目录默认页,发现问题还是存在。
3. 在第2步的基础上,打开新默认页后,我在URL中直接输入旧的默认页,页面瞬间刷出来了。然后我就纠结了,这延时,与页面内容毛的关系都木有,这异常信息也太坑爹了。
4. 出于尝试一下,我试下该目录下的其他文件,首次访问会不会变慢。于是重启IIS,然后发现首次访问该目录中的第一个文件(不论首次访问的是哪个文件),都会耗时数秒;如果Attach到w3wp,都会Catch到这个异常。
5. 项目是从.net framework 1.1(VS2003)上直接升级过来的,以前03的版本,木有这个问题。然后google“asp.net 4.0 slow”,找到下面这个:
Slow Performance — ASP .NET ASPNET_WP.EXE and CSC.EXE Running After Clicking Redirect Link
6. The very first time that the page is load, then the asp.net compile a lot of pages, almost every one found on the same dir, including modules, and dlls found on bin.也就是说,在首次请求一个目录下的某个文件时,会把该目录的所有文件都编译一下。这样做的好处是,把一个目录的编译操作都集中在首次访问上,后续请求会比较快;但这样带来的问题是,如果编译时间比较久,那第一个发起请求的人就杯具了。于是在配置文件中,设置batch="false",然后问题消失,首次请求的速度提上来了,attach上去也没有异常了。
3. 解决方法
部署的时候,记得在配置文件中,把debug和batch关闭,把optimizeCompilations打开:
<compilation targetFramework="4.0" debug="false" batch="false" optimizeCompilations="true">
Asp.net 4.0,首次请求目录下的文件时响应很慢的更多相关文章
- linux下编译qt5.6.0静态库(使用./configure --help来看看都有哪些参数。超详细,有每一个模块的说明。如果改变了安装的目录,需要到安装目录下的bin目录下创建文件qt.conf)(乌合之众)good
linux下编译qt5.6.0静态库 linux下编译qt5.6.0静态库 configure生成makefile 安装选项 Configure选项 第三方库: 附加选项: QNX/Blackberr ...
- .net core 读取本地指定目录下的文件
项目需求 asp.net core 读取log目录下的.log文件,.log文件的内容如下: xxx.log ------------------------------------------beg ...
- [转帖]/proc/sys目录下各文件参数说明
/proc/sys目录下各文件参数说明 https://blog.csdn.net/luteresa/article/details/68061881 一.前言 本文档针对OOP8生产环境,具体优 ...
- [转帖]linux /proc目录下的文件为何无法用vi编辑保存
linux /proc目录下的文件为何无法用vi编辑保存 https://blog.51cto.com/xlogin/1216914 学习一下 之前看过书 这一点 没太仔细看.. xlogin关注8人 ...
- ftp下载目录下所有文件及文件夹内(递归)
ftp下载目录下所有文件及文件夹内(递归) /// <summary> /// ftp文件上传.下载操作类 /// </summary> public class FTPH ...
- Linux下使用shell实现上传linux下某个目录下所有文件到ftp
首先我们需要搞清楚单个文件怎么上传,把这个单文件上传到ftp上的实现命名为一个:upload_to_ftp_command.sh 之后,需要弄清楚怎么实现遍历一个目录下的所有文件的,把这个遍历某个目录 ...
- Java中删除文件、删除目录及目录下所有文件(转)
原文链接:Java中删除文件.删除目录及目录下所有文件 知识点:File.delete()用于删除“某个文件或者空目录”!所以要删除某个目录及其中的所有文件和子目录,要进行递归删除,具体代码示例如下: ...
- (实用篇)PHP不用递归遍历目录下所有文件的代码
<?php /** * PHP 非递归实现查询该目录下所有文件 * @param unknown $dir * @return multitype:|multitype:string */ fu ...
- Java递归列出目录下全部文件
Java递归列出目录下全部文件 /** * 列出指定目录的全部内容 * */ import java.io.*; class hello{ public static void main(String ...
随机推荐
- myeclipse中间classpath
myeclipse中间classpath这是一个非常重要的问题 myeclipse是搜索寻找在按照时间其,和myeclipse有一个特殊的文件来保存classpath信息.这也是别人的项目文件的副本时 ...
- WebGL 在 OpenGL ES 指令 iOS 在 C 分歧版指令分析
WebGL 中 OpenGL ES 指令与 iOS 中 C 版指令的差异简析 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途 ...
- Team Foundation Server 2015使用教程--团队项目删除
- [搜索] hdu 4016 Magic Bitwise And Operation
主题链接: http://acm.hdu.edu.cn/showproblem.php?pid=4016 Magic Bitwise And Operation Time Limit: 6000/30 ...
- HTTP 长连接 使用场景
offer 80 非常多应用譬如监控.即时通信.即时报价系统都须要将后台发生的变化实时传送到client而无须client不停地刷新.发送请求. 在 多好科技的那位技术指导问我这个是由于他们做物连网, ...
- Spark1.0.0 学习路径
2014-05-30 Spark1.0.0 Relaease 经过11次RC后最终公布.尽管还有不少bug,还是非常令人振奋. 作为一个骨灰级的老IT,经过非常成一段时间的消沉,再次被点燃 ...
- Node.js可以做些什么?
就像 JavaScript 至client天生,Node.js 生于网络.Node.js 我们可以做更多的不是开发一个网络 站这么简单,采用 Node.js.您可以轻松地开发: 具有复杂逻辑的站点 ...
- Oracle 数据导出到PowerDesigner
原文:Oracle 数据导出到PowerDesigner [一]配置ODBC win7 :控制面板(查看方式:小图标)→管理工具→数据源(ODBC) 在[ODBC数据源管理器]面板下,在默认[用户DN ...
- Scrapy研究和探索(五岁以下儿童)——爬行自己主动多页(抢别人博客所有文章)
首先.在教程(二)(http://blog.csdn.net/u012150179/article/details/32911511)中,研究的是爬取单个网页的方法.在教程(三)(http://blo ...
- Hadoop之——HBase注意事项
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/46447573 1.HBase(NoSQL)的数据模型 1.1 表(table) 存 ...