多个应用程序域中的一个 ASP.NET 应用程序(偶然)或频繁的应用程序回收 [英] One ASP.NET app (accidentally) in multiple app domains or frequent app recycing

查看:31
本文介绍了多个应用程序域中的一个 ASP.NET 应用程序(偶然)或频繁的应用程序回收的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调试一个 ASP.NET 应用程序,它似乎随机丢失了一些静态字段的内容.我做了一些简单的自定义日志记录(因为即使是 log4net 也是不稳定的),并发现该应用程序正在加载到两个应用程序域中.这是日志中的一个片段:

I'm debugging an ASP.NET application which is seemingly randomly losing the content of some static fields. I did some simple custom logging (because even log4net was flaky), and found out that the application is being loaded into two app domains. Here is a snippet from the log:

6/27/2011 9:01:01 PM /LM/W3SVC/1/ROOT/MyApp-1-129537072581658334: log message 1
6/27/2011 9:01:01 PM /LM/W3SVC/1/ROOT/MyApp-1-129537072581658334: log message 2
6/27/2011 9:01:01 PM /LM/W3SVC/1/ROOT/MyApp-1-129537072581658334: log message 3
6/27/2011 9:01:01 PM /LM/W3SVC/1/ROOT/MyApp-1-129537072581658334: log message 4
6/27/2011 9:01:02 PM /LM/W3SVC/1/ROOT/MyApp-4-129537072620628334: log message 5 <-
6/27/2011 9:01:02 PM /LM/W3SVC/1/ROOT/MyApp-4-129537072620628334: log message 6
6/27/2011 9:04:50 PM /LM/W3SVC/1/ROOT/MyApp-1-129537074647228334: log message 7
6/27/2011 9:04:50 PM /LM/W3SVC/1/ROOT/MyApp-1-129537074647228334: log message 8

时间/日期后的项目为当前应用域名.

The item after the time/date is the current app domain name.

该应用程序只是一个普通的 ASP.NET(不是 MVC)应用程序,处理一些 AJAX 请求并将它们传递给一堆 ASP.NET 库.唯一不寻常的是,其中一个库使用了一些反射来查找一些类,然后这些类在单独的线程上实例化并运行它们.但它不会对应用程序域做任何明确的事情.

The application is just a regular ASP.NET (not MVC) application handling some AJAX request and passing them to a bunch of ASP.NET libraries. The only unusual thing is that one of the libraries uses a bit of reflection to lookup some classes which then instantiates and runs them on separate threads. But it does not do anything explicitly with app domains.

顺便说一下,日志文件中突出显示的行来自来自 ASPX 处理程序的 ASP.NET 应用程序本身(即不是来自那些单独的线程之一).

By the way, the highlighted row from the log file comes from the ASP.NET app itself (i.e. not from one of those separate thread) from an ASPX handler.

我是否正确解释了日志?如果是这样,什么会导致应用从多个应用域加载和提供服务?

Am I interpreting the log correctly? If so, what can cause an application to be loaded and served from multiple app domains?

这个问题本质上与这个问题有关:ASP.NET 应用程序状态与静态对象.但是,根据我今天所看到的,似乎不可能依赖静态字段.我可以将所有内容移动到 Application 对象,但我想同步会有点麻烦.我越来越相信应用程序做了一些非标准的事情.

This question is essentially related to this one: ASP.NET Application state vs a Static object. However, based on what I've seen today, it does not seem possible to rely on static fields. I could move everything to the Application object, but I guess a synchronization would be a bit cumbersome. I'm more and more convinced the application does something non-standard.

编辑 2: 我做了更多调查,似乎应用程序域和应用程序域之间始终存在 1-1 关系(这是我所期望的).所以我认为我看到的是回收.

Edit 2: I did a little bit more investigation, and it seems that there is always a 1-1 relation between application and app domains (which is something I would expect). So I think that what I'm seeing is recycling.

编辑 3: 经过更多的实验和探索,我启用了 IIS 健康监控(基于 http://blogs.msdn.com/b/tess/archive/2006/08/02/asp-net-case-study-lost-session-variables-and-appdomain-recycles.aspx),发现应用程序快速连续启动了两次.其实挺让人费解的.以下是日志事件:

Edit 3: After some more experiments and poking around, I enabled IIS health monitoring (based on http://blogs.msdn.com/b/tess/archive/2006/08/02/asp-net-case-study-lost-session-variables-and-appdomain-recycles.aspx), and found out that the application is started twice in a quick succession. It's actuall quite puzzling. Here are the log events:

Event code: 1003 
Event message: Application compilation is starting. 
Event time: 6/28/2011 8:34:31 AM 
Event time (UTC): 6/28/2011 3:34:31 PM 
Event ID: d42336b18c264516a4ba5aa1e62df276 
Event sequence: 1 
Event occurrence: 1 
Event detail code: 0 

Application information: 
    Application domain: /LM/W3SVC/1/ROOT/MyApp-1-129537488697736549 
    Trust level: Full 
    Application Virtual Path: /MyApp 
    Application Path: [snip]\MyApp\ 
    Machine name: US-SEA-R9759B2 

Process information: 
    Process ID: 7624 
    Process name: w3wp.exe 
    Account name: IIS APPPOOL\DefaultAppPool 

----

Event code: 1001 
Event message: Application is starting. 
Event time: 6/28/2011 8:34:33 AM 
Event time (UTC): 6/28/2011 3:34:33 PM 
Event ID: f7fbecb1ba1a4a24833016cec47458c6 
Event sequence: 1 
Event occurrence: 1 
Event detail code: 0 

Application information: 
    Application domain: /LM/W3SVC/1/ROOT-2-129537488729428362 
    Trust level: Full 
    Application Virtual Path: / 
    Application Path: [snip]\RootApp\ 
    Machine name: US-SEA-R9759B2 

Process information: 
    Process ID: 7624 
    Process name: w3wp.exe 
    Account name: IIS APPPOOL\DefaultAppPool 

----

Event code: 1001 
Event message: Application is starting. 
Event time: 6/28/2011 8:34:40 AM 
Event time (UTC): 6/28/2011 3:34:40 PM 
Event ID: 07a3dc31e8804caca1ddc3b2101962e3 
Event sequence: 1 
Event occurrence: 1 
Event detail code: 0 

Application information: 
    Application domain: /LM/W3SVC/1/ROOT-3-129537488807712839 
    Trust level: Full 
    Application Virtual Path: / 
    Application Path: [snip]\RootApp\ 
    Machine name: US-SEA-R9759B2 

Process information: 
    Process ID: 7624 
    Process name: w3wp.exe 
    Account name: IIS APPPOOL\DefaultAppPool 

----

Event code: 1001 
Event message: Application is starting. 
Event time: 6/28/2011 8:34:40 AM 
Event time (UTC): 6/28/2011 3:34:40 PM 
Event ID: db304b519a084fa797fbcfe66fbb0b48 
Event sequence: 1 
Event occurrence: 1 
Event detail code: 0 

Application information: 
    Application domain: /LM/W3SVC/1/ROOT/MyApp-4-129537488808502885 
    Trust level: Full 
    Application Virtual Path: /MyApp 
    Application Path: [snip]\MyApp\ 
    Machine name: US-SEA-R9759B2 

Process information: 
    Process ID: 7624 
    Process name: w3wp.exe 
    Account name: IIS APPPOOL\DefaultAppPool 

MyApp 应用程序位于另一个应用程序(RootApp)中.我期望的是两条日志消息:MyApp 启动和 RootApp 启动.

The MyApp application sits in another application (the RootApp). What I would expect would be two log messages: MyApp starting and RootApp starting.

推荐答案

您是否不小心将 AppPool 属性(性能选项卡)中的工作进程数设置为 2?

Did you accidentally set the number of worker processes in the AppPool Properties (Performance Tab) to 2?

在这些属性中,还可能有一个设置,让您的 AppPool 根据数量或请求或任何这些回收设置而过于频繁地回收

In those properties, there could also be a setting that let's your AppPool recycle far too often, based on number or requests or any of those recycling settings

这篇关于多个应用程序域中的一个 ASP.NET 应用程序(偶然)或频繁的应用程序回收的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆