zoukankan      html  css  js  c++  java
  • 真正解决ASP.NET每一个页面首次访问超级慢的问题

    原文:http://www.afuhao.com/article_articleId-219.shtml
    摘要:ASP.NET页面首次打开很慢,但别的页面如果没有访问过,去访问也会慢。你也许认为它是在编译ASPX,或者加载一些东西。不过我发现不是这样的。

    用过ASP.NET的人都知道吧,页面首次打开很慢。

    本来网站第一次启动就慢,但别的页面如果没有访问过,去访问也会慢。


    好吧,你也许认为它是在编译ASPX,或者加载一些东西。

    我也这样认为过。


    不过我发现不是这样的。

    1.bin目录里面你放多少它加载多少,如果放一些无效的DLL,比如在32位下面放一些纯64位的DLL,就会直接报错;

    2.aspx页面解析非常快,那么转成CS也是一瞬间,编译更不用说,不应该是卡上2-5秒,1秒是可以接受的;


    那么要做的就是不让它干这些坏事,总之我从来都不觉得它会老老实实的给你服务。


    禁止证书的验证过程:
    1、在下面aspnet.config文件中加入下面内容: 
        32位系统:C:WindowsMicrosoft.NetFrameworkv2.0.50727aspnet.config
        64位系统:C:WindowsMicrosoft.NETFramework64v2.0.50727aspnet.config

       有4.0,甚至4.5的自己多改几个地方,如果是64位的系统,可能需要以管理员身份打开编辑器,再打开这个文件,否则无法保存的。


    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <configuration>   
    3.     <runtime>  
    4.         <generatePublisherEvidence enabled="false"/>  
    5.     </runtime>  
    6. </configuration>  


    对"Network Service"帐号下运行的所有程序禁止证书检查

        不会的话就忽略吧。

        导入以下注册表内容,自己先另存为*.reg文件吧,如果会手工操作的话,就手工来吧。


    1. Windows Registry Editor Version 5.00  
    2.   
    3. [HKEY_USERSS-1-5-20SoftwareMicrosoftWindowsCurrentVersionWinTrustTrust ProvidersSoftware Publishing]  
    4.   
    5. "State"=dword:00023e00  


    然后记得重启一下应用程序池(实在不知道,就重启IIS服务),再去看看你的网站,首次加载快吗?其它页面访问快吗?



    忍受不了时,就再也不用忍受!




    下面是专业的分析记录,看不懂就当没见过吧。。。

    1. 详细分析  
    2.   
    3. ==========  
    4.   
    5. 这个时候如果我们抓取一个hang dump的话,页面所对应的managed callstack往往如下,很明显它正在加载一个Assembly  
    6.   
    7. 0:022> !CLRStack  
    8.   
    9. OS Thread Id: 0xeb4 (22)  
    10.   
    11. Child-SP RetAddr Call Site  
    12.   
    13. 000000001af1c900 000007fef91747c3 System.Reflection.Assembly.InternalLoad(System.Reflection.AssemblyName, System.Security.Policy.Evidence,  
    14.   
    15. System.Threading.StackCrawlMark ByRef, Boolean)  
    16.   
    17. 000000001af1c990 000007ff0141f0f9 System.Reflection.Assembly.Load(System.Reflection.AssemblyName)  
    18.   
    19. 000000001af1c9d0 000007fef9fdd502 Microsoft.SharePoint.Portal.WebControls.StringResourceManager..cctor()  
    20.   
    21. 000000001af1db50 000007ff014135e2 Microsoft.SharePoint.Portal.WebControls.MySiteLinkUserControl.SetControl()  
    22.   
    23. 000000001af1dce0 000007fef398e04f Microsoft.SharePoint.Portal.WebControls.MySiteLinkUserControl.OnInit(System.EventArgs)  
    24.   
    25. 000000001af1de80 000007fef398f3af System.Web.UI.Control.InitRecursive(System.Web.UI.Control)  
    26.   
    27. 000000001af1dee0 000007ff014133c8 System.Web.UI.Control.AddedControl(System.Web.UI.Control, Int32)  
    28.   
    29. 000000001af1df50 000007ff0134115e Microsoft.SharePoint.WebControls.DelegateControl.AddControlResilient(System.Web.UI.Control)  
    30.   
    31. 000000001af1dff0 000007fef398fb22 Microsoft.SharePoint.WebControls.DelegateControl.CreateChildControls()  
    32.   
    33. 000000001af1e170 000007ff01341024 System.Web.UI.Control.EnsureChildControls()  
    34.   
    35. 000000001af1e1d0 000007fef398e04f Microsoft.SharePoint.WebControls.DelegateControl.OnInit(System.EventArgs)  
    36.   
    37. 000000001af1e210 000007fef398e147 System.Web.UI.Control.InitRecursive(System.Web.UI.Control)  
    38.   
    39. 000000001af1e270 000007fef398e147 System.Web.UI.Control.InitRecursive(System.Web.UI.Control)  
    40.   
    41. 000000001af1e2d0 000007fef398e147 System.Web.UI.Control.InitRecursive(System.Web.UI.Control)  
    42.   
    43. 000000001af1e330 000007fef398e147 System.Web.UI.Control.InitRecursive(System.Web.UI.Control)  
    44.   
    45. 000000001af1e390 000007fef398e147 System.Web.UI.Control.InitRecursive(System.Web.UI.Control)  
    46.   
    47. 000000001af1e3f0 000007fef398a935 System.Web.UI.Control.InitRecursive(System.Web.UI.Control)  
    48.   
    49. 000000001af1e450 000007fef398a1f0 System.Web.UI.Page.ProcessRequestMain(Boolean, Boolean)  
    50.   
    51. 000000001af1e520 000007fef398a11b System.Web.UI.Page.ProcessRequest(Boolean, Boolean)  
    52.   
    53. 000000001af1e580 000007fef398a0b0 System.Web.UI.Page.ProcessRequest()  
    54.   
    55. 000000001af1e5e0 000007fef3991557 System.Web.UI.Page.ProcessRequest(System.Web.HttpContext)  
    56.   
    57. 000000001af1e640 000007fef395567b System.Web.HttpApplication+CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()  
    58.   
    59. 000000001af1e6f0 000007fef39634b5 System.Web.HttpApplication.ExecuteStep(IExecutionStep, Boolean ByRef)  
    60.   
    61. 000000001af1e790 000007fef3954733 System.Web.HttpApplication+ApplicationStepManager.ResumeSteps(System.Exception)  
    62.   
    63. 000000001af1e840 000007fef3958a54 System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(System.Web.HttpContext, System.AsyncCallback,  
    64.   
    65. System.Object)  
    66.   
    67. 000000001af1e8a0 000007fef395863c System.Web.HttpRuntime.ProcessRequestInternal(System.Web.HttpWorkerRequest)  
    68.   
    69. 000000001af1e930 000007fef395726c System.Web.HttpRuntime.ProcessRequestNoDemand(System.Web.HttpWorkerRequest)  
    70.   
    71. 000000001af1e970 000007fef9fdd502 System.Web.Hosting.ISAPIRuntime.ProcessRequest(IntPtr, Int32)  
    72.   
    73. 其实它所要加载的Assembly名字如下  
    74.   
    75. Microsoft.SharePoint.Portal.intl  
    76.   
    77. 此线程所对应的native callstack如下  
    78.   
    79. 0:022> k20  
    80.   
    81. Child-SP RetAddr Call Site  
    82.   
    83. 00000000'1af1a208 000007fe'fdc610ac ntdll!ZwWaitForSingleObject+0xa  
    84.   
    85. 00000000'1af1a210 000007fe'f5dfa2fa KERNELBASE!WaitForSingleObjectEx+0x79 00000000'1af1a2b0 000007fe'f5df76fa cryptnet!CryptRetrieveObjectByUrlWithTimeout+0x263  
    86.   
    87. 00000000'1af1a5b0 000007fe'f5df4646 cryptnet!CryptRetrieveObjectByUrlW+0x20f 00000000'1af1a7a0 000007fe'f5df9c34 cryptnet!RetrieveObjectByUrlValidForSubject+0x162 00000000'1af1a8d0 000007fe'f5df4243 cryptnet!RetrieveTimeValidObjectByUrl+0x2de 00000000'1af1a9c0 000007fe'f5df3c72 cryptnet!CTVOAgent::GetTimeValidObjectByUrl+0x2e3 00000000'1af1ab20 000007fe'f5df38ad cryptnet!CTVOAgent::GetTimeValidObject+0x7cf  
    88.   
    89. 00000000'1af1ad00 000007fe'f5df3810 cryptnet!FreshestCrlFromCrlGetTimeValidObject+0x61  
    90.   
    91. 00000000'1af1ad70 000007fe'f5df99fc cryptnet!CryptGetTimeValidObject+0xb0 00000000'1af1adf0 000007fe'f5df345d cryptnet!GetTimeValidCrl+0x4b7  
    92.   
    93. 00000000'1af1af30 000007fe'f5df3f82 cryptnet!GetBaseCrl+0x7d 00000000'1af1afc0 000007fe'f5df3d58 cryptnet!MicrosoftCertDllVerifyRevocation+0x238  
    94.   
    95. 00000000'1af1b110 000007fe'fdb157c7 cryptnet!CertDllVerifyRevocation+0x28  
    96.   
    97. 00000000'1af1b160 000007fe'fdb1552e crypt32!VerifyDefaultRevocation+0x398 00000000'1af1b250 000007fe'fdb15c09 crypt32!CertVerifyRevocation+0x144  
    98.   
    99. ...  
    100.   
    101. 00000000'1af1bcc0 000007fe'f9e46c27 mscorwks!PEFile::CheckSecurity+0x39b924  
    102.   
    103. 00000000'1af1bd50 000007fe'f9e5eb5d mscorwks!PEAssembly::DoLoadSignatureChecks+0x37  
    104.   
    105. 00000000'1af1bd90 000007fe'f9e52ff8 mscorwks!PEAssembly::PEAssembly+0x12d 00000000'1af1be00 000007fe'f9e40b9d mscorwks!PEAssembly::DoOpen+0x11c 00000000'1af1c130 000007fe'f9f24a3e mscorwks!PEAssembly::Open+0x71  
    106.   
    107. 从这些函数名我们知道它正在做一些证书检查之类的事情。而实际上它正在等待下面的这个线程。  
    108.   
    109. 0:036> kn  
    110.   
    111. # Child-SP RetAddr Call Site  
    112.   
    113. 00 00000000'2409e1c8 000007fe'fdc610ac ntdll!ZwWaitForSingleObject+0xa  
    114.   
    115. 01 00000000'2409e1d0 000007fe'f5d7f38e KERNELBASE!WaitForSingleObjectEx+0x79  
    116.   
    117. 02 00000000'2409e270 000007fe'f5d80a27 winhttp!IsWpadEnabledForConnectedNetworks+0x1f2  
    118.   
    119. 03 00000000'2409e340 000007fe'f5d806dc winhttp!ReadWinInetProxySettings+0x1c3  
    120.   
    121. 04 00000000'2409e3c0 000007fe'f5dfae42 winhttp!WinHttpGetIEProxyConfigForCurrentUser+0x28a  
    122.   
    123. 05 00000000'2409e510 000007fe'f5df9237 cryptnet!InetGetProxy+0x11e  
    124.   
    125. 06 00000000'2409e600 000007fe'f5df983d cryptnet!InetSendAuthenticatedRequestAndReceiveResponse+0x190  
    126.   
    127. 07 00000000'2409f770 000007fe'f5df9d9c cryptnet!InetSendReceiveUrlRequest+0x57e  
    128.   
    129. .....  
    130.   
    131. 0:036> .frame 7  
    132.   
    133. 07 00000000'2409f770 000007fe'f5df9d9c cryptnet!InetSendReceiveUrlRequest+0x57e [d:w7rtmdssecuritycryptoapipki porinetsp.cpp @ 2603]  
    134.   
    135. 0:036> dv  
    136.   
    137. hInetSession = 0x00000000'218211f0  
    138.   
    139. pwszUrl = 0x00000000'1f8abe50 "http://crl.microsoft.com/pki/crl/products/CSPCA.crl"  
    140.   
    141. dwRetrievalFlags = 1  
    142.   
    143. pCredentials = 0x00000000'00000000  
    144.   
    145. pcba = 0x00000000'2409fab0  
    146.   
    147. ppfnFreeObject = 0x00000000'2409fb38  
    148.   
    149. ppvFreeContext = 0x00000000'2409fb30  
    150.   
    151. pAuxInfo = 0x00000000'1f8abd78  
    152.   
    153. phInetRequest = 0x00000000'00000000  
    154.   
    155. 我们可以看到,当时我们抓取dump的时候它正在尝试连接http://crl.microsoft.com/pki/crl/products/CSPCA.crl


  • 相关阅读:
    廖大python实战项目第六天
    廖大python实战教程第七天
    廖大python实战项目第五天
    Map的遍历方法及字符计数
    事务详解
    java设计模式详解
    程序员常见一些英文缩写
    Hibernate小笔记
    Myeclipse有关的问题
    hibernate对象的三种状态及转换
  • 原文地址:https://www.cnblogs.com/jincieryi/p/9630063.html
Copyright © 2011-2022 走看看