C# ASP.NET 2.0-4.0 Web 应用程序的初始启动速度极慢。
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8807331/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ASP.NET 2.0-4.0 Web Applications experiencing extremely slow initial start-up.
提问by Caleb
(Sorry if this is a really long question, it said to be specific)
(对不起,如果这是一个很长的问题,它说是具体的)
The company I work for has a number of sites, which have been running for some time with no problems. The applications are a mix of ASP.NET 2.0, 3.5, and 4.0, all using an ADO.NET to connect to a SQL Server Standard instance (on the same webserver) all being hosted with IIS7.
我工作的公司有许多站点,这些站点已经运行了一段时间,没有出现任何问题。这些应用程序是 ASP.NET 2.0、3.5 和 4.0 的混合体,都使用 ADO.NET 连接到 SQL Server Standard 实例(在同一 Web 服务器上),所有实例都由 IIS7 托管。
The problem began when we moved to an upgraded webserver. We made every effort to set up the server, db instance and IIS with the exact same settings (except for the different machine name, and the fact that we had upgraded from SQLExpress to Standard), and as far as we could tell, we did. Both servers are running Windows Server 2008 R2 (all current updates applied), and received a default install.
当我们转移到升级的网络服务器时,问题就开始了。我们尽一切努力使用完全相同的设置来设置服务器、数据库实例和 IIS(除了不同的机器名称,以及我们从 SQLExpress 升级到标准的事实),据我们所知,我们做到了. 两台服务器都运行 Windows Server 2008 R2(应用了所有当前更新),并获得了默认安装。
The problem is very apparent when starting up one of these applications. When you reach the login page of our application, the page itself loads extremely fast. This is true even when you load the page from a new machine that could not possibly have the page cached, with IIS caching disabled. The problem is actually visible when you enter your login information and click the login button. Because of the (not great)design of our databases, the login process must access a number of databases, theoretically up to 150 separate DBs, but in practice usually 2. The problem occurs even when only 2 databases (the minimum) are opened. Not a great design, but we have to live with it for now.
启动这些应用程序之一时,问题非常明显。当您到达我们应用程序的登录页面时,页面本身的加载速度非常快。即使您从不可能缓存页面的新机器加载页面时也是如此,并且禁用了 IIS 缓存。当您输入登录信息并单击登录按钮时,问题实际上是可见的。由于我们数据库的(不是很好)设计,登录过程必须访问多个数据库,理论上最多 150 个单独的 DB,但实际上通常是 2 个。即使只打开 2 个数据库(最少)也会出现问题。不是一个伟大的设计,但我们现在必须忍受它。
When trying to initially open a connection to the database, the entire process stops for about 20 seconds every time, regardless of whether you are connecting to 2 dbs or 40. I have run a .NET profiler (jetbrains dottrace) against the process, and the only information I could take from it was that one or all of the calls to sqlconnection.open() was accounting for 90% of the time. This only happens on first-use of the application, but the problem is compounded by the fact that IIS seems to disregard the recycling settings we have set for it, and recycles the application after a few minutes of idle, causing the problem to occur again.
当尝试最初打开与数据库的连接时,整个过程每次都会停止大约 20 秒,无论您是连接到 2 dbs 还是 40。我已经针对该过程运行了 .NET 分析器(jetbrains dottrace),并且我能从中得到的唯一信息是对 sqlconnection.open() 的一次或全部调用占了 90% 的时间。这只发生在第一次使用应用程序时,但问题更复杂的是IIS似乎无视我们为其设置的回收设置,并在空闲几分钟后回收应用程序,导致问题再次发生.
I also tried to use the SQL Server profiler to see which database operations were the cause of the slowdown, but because of all the other DB activity, (and the fact that I had to do this on our production server, because the problem doesnt occur in our test environments) I couldn't pin down the exact operation that was causing the stoppage. I will try coming in late at night and shutting down the production sites to run the SQL profiler, but I might not be able to do this right away.
我还尝试使用 SQL Server 探查器查看导致速度下降的数据库操作,但由于所有其他数据库活动,(以及我必须在我们的生产服务器上执行此操作的事实,因为问题没有发生在我们的测试环境中)我无法确定导致停机的确切操作。我将尝试在深夜进入并关闭生产站点以运行 SQL 分析器,但我可能无法立即执行此操作。
In the course of researching the problem, I have tried a couple solutions
在研究问题的过程中,我尝试了几种解决方案
Thinking it might be a name resolution problem, I tried modifiying both the hosts file on the webserver as well as giving the connectionstrings an IP address instead of the servername to resolve, with no difference. I have heard of the LLMNR protocol causing problems like this, but I think trying to connect by IP or resolving with the hosts file should have eliminated that possibility, tho i admit I never tried actually turning off LLMNR.
I have increased the idle timeouts, recycling intervals etc in IIS, but this doesn't even seem to be respected, much less solving the problem. This leads me to believe there is a setting overriding the IIS application settings on the machine.
multiple other code fixes, none of which made any difference. Is a SqlServer setting causing the problem?
other stuff that i forgot by now.
认为这可能是名称解析问题,我尝试修改 web 服务器上的主机文件,并为连接字符串提供 IP 地址而不是要解析的服务器名称,没有任何区别。我听说过 LLMNR 协议会导致这样的问题,但我认为尝试通过 IP 连接或使用主机文件解析应该已经消除了这种可能性,但我承认我从未尝试过实际关闭 LLMNR。
我增加了 IIS 中的空闲超时、回收间隔等,但这似乎没有得到尊重,更不用说解决问题了。这让我相信有一个设置覆盖了机器上的 IIS 应用程序设置。
多个其他代码修复,没有任何区别。SqlServer 设置是否导致了问题?
我现在忘记的其他东西。
Any ideas, experience or whatevers would be greatly appreciated in helping me solve this problem!
任何想法,经验或任何东西都将非常感谢帮助我解决这个问题!
采纳答案by csharptest.net
I would advise using a non-tcp connection if you are still running the SQL instance on the local machine. SQL Server supports several protocols, tcp, named pipes, and shared memory are the more common.
如果您仍在本地计算机上运行 SQL 实例,我建议您使用非 tcp 连接。SQL Server 支持多种协议,tcp、命名管道和共享内存是比较常见的。
Named Pipes
命名管道
Data Source=np:computer\instance
Shared Memory
共享内存
Data Source=lpc:computer\instance
Personally I prefer the Shared Memory. Remember you need to enable these protocols, and to avoid configuration mistakes I suggest you disable all you are not using.
我个人更喜欢共享内存。请记住,您需要启用这些协议,并且为了避免配置错误,我建议您禁用所有未使用的协议。
see http://msdn.microsoft.com/en-us/library/ms187892.aspx
请参阅http://msdn.microsoft.com/en-us/library/ms187892.aspx
IIS Reset
IIS 重置
In IIS7 there are two ways to configure the idle-timeout. Both begin by clicking on the "Application Pools" section and right-clicking the appropriate app domain. If you click the "Recycling..." option there is one setting. The other is in "Advanced Settings..." under the section for "Process Model" you will find "Idle Time-out (minutes)" which set to zero disables the process timeout. This later option is the one that works for us.
在 IIS7 中,有两种方法可以配置空闲超时。两者都首先单击“应用程序池”部分并右键单击相应的应用程序域。如果您单击“回收...”选项,则只有一种设置。另一个是在“进程模型”部分下的“高级设置...”中,您会发现“空闲超时(分钟)”设置为零禁用进程超时。这个后面的选项对我们有用。
If I were you I'd solve this problem first as restarting the appdomain and/or worker process is always painful even if you don't have a 20 second lag.
如果我是你,我会先解决这个问题,因为即使你没有 20 秒的延迟,重新启动 appdomain 和/或工作进程总是很痛苦。
回答by David Hoerster
Some ideas:
一些想法:
- from the web server, can you ping the db server and get a "normal" response, or are you seeing a similar delay?
- if you're seeing a delay, run a tracert to see if you can nail down where the slowness is occurring
- try using a tool like QueryExpress (http://www.albahari.com/queryexpress.aspx) which doesn't require an install to run. You can download this EXE and run it from your web server. See if you can connect to your db using this and run queries in a normal fashion.
- Try something like SysInternals' TcpView (http://technet.microsoft.com/en-us/sysinternals/bb897437) to take a look at your open connections and see what activity is happening on your server and how much data is being sent to and received from your db server.
- 从 Web 服务器,您能否 ping 数据库服务器并获得“正常”响应,或者您是否看到类似的延迟?
- 如果您看到延迟,请运行 tracert 以查看是否可以确定发生缓慢的位置
- 尝试使用不需要安装即可运行的 QueryExpress (http://www.albahari.com/queryexpress.aspx) 之类的工具。您可以下载此 EXE 并从您的 Web 服务器运行它。看看您是否可以使用它连接到您的数据库并以正常方式运行查询。
- 尝试使用类似 SysInternals 的 TcpView (http://technet.microsoft.com/en-us/sysinternals/bb897437) 来查看您打开的连接并查看您的服务器上正在发生的活动以及发送到的数据量并从您的数据库服务器收到。
Just some initial thoughts on where I'd start to look based upon your problem description. I hope this helps. Good luck with things!
根据您的问题描述,我只是对我从哪里开始寻找的一些初步想法。我希望这有帮助。祝你事事顺利!
回答by Leon
With IIS not respecting recycling settings: did restarting IIS/rebooting change the behavior?
IIS 不遵守回收设置:重新启动 IIS/重新启动是否改变了行为?

