ASP.NET 2.0-4.0 Web 应用程序初始启动速度极慢。
(抱歉,如果这是一个很长的问题,它说得很具体)
我工作的公司有很多网站,这些网站已经运行了一段时间没有任何问题。这些应用程序是 ASP.NET 2.0、3.5 和 4.0 的混合体,全部使用 ADO.NET 连接到 SQL Server Standard 实例(在同一 Web 服务器上),全部由 IIS7 托管。
当我们迁移到升级的网络服务器时,问题就开始了。我们尽一切努力使用完全相同的设置来设置服务器、数据库实例和 IIS(除了不同的计算机名称,以及我们已从 SQLExpress 升级到 Standard),据我们所知,我们做到了。两台服务器都运行 Windows Server 2008 R2(应用了所有当前更新),并接受了默认安装。
当启动这些应用程序之一时,问题非常明显。当您到达我们应用程序的登录页面时,页面本身加载速度非常快。即使您从一台不可能缓存页面且禁用 IIS 缓存的新计算机加载页面,情况也是如此。当您输入登录信息并单击登录按钮时,问题实际上就可见了。由于我们数据库的设计(不是很好),登录过程必须访问多个数据库,理论上最多 150 个独立的数据库,但实际上通常是 2 个。即使只打开 2 个数据库(最少),也会出现问题。这不是一个伟大的设计,但我们现在必须忍受它。
当尝试最初打开与数据库的连接时,整个过程每次都会停止大约 20 秒,无论您连接的是 2 个数据库还是 40 个数据库。我已经针对该进程运行了 .NET 探查器 (jetbrains dottrace),并且我可以从中获取的唯一信息是对 sqlconnection.open() 的一个或所有调用占了 90% 的时间。这种情况只发生在首次使用该应用程序时,但由于 IIS 似乎无视我们为其设置的回收设置,并在空闲几分钟后回收该应用程序,导致问题再次出现,因此问题变得更加复杂。
我还尝试使用 SQL Server 探查器来查看哪些数据库操作是导致速度变慢的原因,但由于所有其他数据库活动(事实上,我必须在我们的生产服务器上执行此操作,因为问题不会发生)在我们的测试环境中)我无法确定导致停止的确切操作。我会尝试在深夜进入并关闭生产站点来运行 SQL 分析器,但我可能无法立即执行此操作。
在研究这个问题的过程中,我尝试了几种解决方案
我认为这可能是一个名称解析问题,我尝试修改网络服务器上的主机文件,并为连接字符串提供一个IP地址而不是服务器名称解决,没有区别。我听说 LLMNR 协议会导致这样的问题,但我认为尝试通过 IP 连接或解析主机文件应该可以消除这种可能性,但我承认我从未尝试过实际关闭 LLMNR。
我增加了 IIS 中的空闲超时、回收间隔等,但这似乎没有得到尊重,更不用说解决问题了。这让我相信有一个设置覆盖了计算机上的 IIS 应用程序设置。
多个其他代码修复,但没有任何区别。是否是 SqlServer 设置导致了该问题?
其他我现在忘记的东西。
任何想法、经验或任何东西都可以帮助我解决这个问题,我将不胜感激!
(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.
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.
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.
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.
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.
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.
Any ideas, experience or whatevers would be greatly appreciated in helping me solve this problem!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您仍在本地计算机上运行 SQL 实例,我建议您使用非 tcp 连接。 SQL Server 支持多种协议,其中 TCP、命名管道和共享内存是比较常见的。
命名管道
共享内存
我个人更喜欢共享内存。请记住,您需要启用这些协议,为了避免配置错误,我建议您禁用所有不使用的协议。
请参阅http://msdn.microsoft.com/en-us/library/ms187892.aspx
IIS 重置
在 IIS7 中,有两种方法可以配置空闲超时。两者都首先单击“应用程序池”部分,然后右键单击相应的应用程序域。如果您单击“回收...”选项,则会出现一项设置。另一个是在“进程模型”部分下的“高级设置...”中,您会发现“空闲超时(分钟)”,将其设置为零会禁用进程超时。后一个选项对我们有用。
如果我是你,我会首先解决这个问题,因为即使你没有 20 秒的延迟,重新启动应用程序域和/或工作进程总是很痛苦。
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.
Named Pipes
Shared Memory
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
IIS Reset
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.
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.
一些想法:
回应,或者您是否看到类似的延迟?
只是根据您的问题描述,我从哪里开始寻找一些初步想法。我希望这有帮助。祝一切顺利!
Some ideas:
response, or are you seeing a similar delay?
Just some initial thoughts on where I'd start to look based upon your problem description. I hope this helps. Good luck with things!
由于 IIS 不尊重回收设置:重新启动 IIS/重新启动是否会更改行为?
With IIS not respecting recycling settings: did restarting IIS/rebooting change the behavior?