global.asax 上的 Application_Start 速度缓慢会导致死锁
global.asax 上的 Application_Start 代码需要 2-3 分钟才能完成(长数据库查询等)
每当我发布网站的新版本时,我都会在 aspnet_isapi.dll 上遇到死锁,并且应用程序无法启动。
它启动的唯一方法是当我禁用从 Internet 访问 IIS 时,再次重新启动应用程序并启动它。对该站点进行一次调用(以便 global.asax)正常工作。
我不明白为什么当应用程序启动时收到大量页面/文件请求时会发生死锁。我知道 global.asax 上的 Application_Start 仅触发一次,并且我猜想所有其他客户端都会等到事件完成,所以我看不出它出现死锁的原因。
有什么想法吗?
更新:
大约需要 4-5 分钟...... 该代码进行数据库查询并将它们附加到应用程序变量(以供以后使用)。 这是我的专用服务器上的虚拟服务器。只有一台其他机器在运行,不会占用太多资源。 我收到事件 ID 2262 - ISAPI '...\aspnet_isapi.dll' 报告自身运行状况不佳,原因如下:“检测到死锁”。
有一个 SQL 查询占用了大部分时间。我可以在不同的进程(Windows 服务/等)上执行此查询,但问题是我不明白为什么会发生...... 如果将来我必须在 Application_Start 中放入一些耗时的代码,会发生什么情况?
My Application_Start code on the global.asax takes 2-3 minutes to finish (long db queries, etc)
Whenever I publish a new version of the site, I get deadlocks on aspnet_isapi.dll and the application doesn't start.
The only way for it to start is when I disable the IIS from being accessed from the internet, restart the application again & make one call to the site (in order for the global.asax) to work.
I don't understand why the deadlock happens when I get lots of page/files requests when application starts. I know that Application_Start on global.asax fires just once so, and I guess that all other clients just wait until the event completes, so I don't see a reason for it to have a deadlock.
Any thoughts?
Update:
It takes more like 4-5 minutes...
The code is makes db queries and attach them to the Application variable (for later use).
it's a virtual server on a dedicated server of mine. only one other machine is on that does not take much resources.
I get Event ID 2262 - ISAPI '...\aspnet_isapi.dll' reported itself as unhealthy for the following reason: 'Deadlock detected'.
There is one SQL query that takes most of the time. I can execute this query on a different process (windows service / etc) but the problem is that I don't understand why it happens....
What will happen if in the future I'll have to put some time consuming code inside the Application_Start?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这种方法有几个问题。
首先 - 加载这么多数据并将其粘贴在应用程序中似乎过多。我可以在这么长时间内查询数百万条记录,因此我会检查您的索引和查询以确保这确实是必要的。您要加载哪些类型的数据必须进入应用程序?
还请记住,您将增加应用程序的工作内存,这在某些时候可能会导致它根据 IIS 工作进程设置进行重置。
Application_Start 应尽快完成,以便运行时知道加载的所有内容都正常。我相信你的僵局不是典型场景中的僵局,而是“我认为它被卡住”场景中的僵局。
如前所述 - 一种选择是将处理拉出到另一个线程中。但请注意,当您的应用程序空闲一段时间时,它将被关闭。虽然您可以在 IIS 中更改这些设置,但我真的会考虑重新考虑数据的加载。为什么不按需从数据库中查询呢?您可以在数据库端使用此数据创建一个新的索引视图(以及其他建议)
There's several problems with this approach.
First - to load that much data and stick it in the application seems excessive. I can query millions of records in that much time so I would check your indexes and queries to make sure this really is necessary. What sort of data are you loading that has to go into application?
Remember also you will be increasing the working memory of the application which at some point could cause it to be reset based on the IIS worker process settings.
Application_Start should finish as quick as possible so the runtime knows everything loaded ok. I believe your deadlock isn't a deadlock as in a typical scenario but as in a 'I think its stuck' scenario.
As mentioned - one option is to pull your processing out into another thread. However note that when your application goes idle for a while it will be shut down. You can change these settings in IIS though, but I would really consider rethinking this loading of data. Why not query on demand from the database? You could create a new indexed view with this data on the database side (amongst other suggestions)