开发者

Slow Application_Start on global.asax makes a deadlock

开发者 https://www.devze.com 2023-03-23 08:18 出处:网络
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 d

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 开发者_StackOverflow社区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?


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号