为什么每隔几秒就会创建一个新的AppDomain(WCF / IIS 7)? [英] Why is a new AppDomain being created every few seconds (WCF/IIS 7)?

查看:205
本文介绍了为什么每隔几秒就会创建一个新的AppDomain(WCF / IIS 7)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调试一些淘气的MT代码。最近,最疯狂的事情(在添加大量日志记录之后)似乎是在我的单工作进程,单机器IIS托管的WCF服务上,在开始时为前几个请求创建了几个应用程序域,然后每个几秒钟就创建了另一个。



下面的每一行大致记录下面的堆栈跟踪:

  AddItem(WCF服务方法)
调用SomeRepositoryClass.Open(为此请求创建类的实例)
调用WritePlanBufferManager构造函数(静态实例),在lock构造中访问(on static readonly object field)

Log(A = AppDomain.CurrentDomain.Id,T = Thread.CurrentThread。 ManagedThreadId):

 第1行:[21:21:21.7544122 A:002 T:011]为appdomain 2 $创建新的WritePlanBufferManager b $ b第2行:[21:21:31.0299427 A:004 T:008]为appdomain 4创建新的WritePlanBufferManager 
第3行:[21:21:36.5912608 A:006 T:0 12]为appdomain创建新的WritePlanBufferManager 6
第4行:[21:21:37.9533387 A:008 T:010]为appdomain创建新的WritePlanBufferManager 8
第670行:[21:21:41.1065191 A:010 T:020]为appdomain 10创建新的WritePlanBufferManager
行1336:[21:21:43.4236516 A:012 T:020]为appdomain 12创建新的WritePlanBufferManager
2002行:[21:21:45.8347895 A :014 T:020]为appdomain创建新的WritePlanBufferManager 14
第2656行:[21:21:48.2479276 A:016 T:020]为appdomain创建新的WritePlanBufferManager 16
第3322行:[21:21: 50.9600827 A:018 T:020]为appdomain 18创建新的WritePlanBufferManager
行3988:[21:21:53.2752151 A:020 T:010]为appdomain创建新的WritePlanBufferManager 20
行4654:[21: 21:55.7353558 A:022 T:020]为appdomain 22创建新的WritePlanBufferManager
第5320行:[21:21:58.0414877 A:024 T:007]为appdomain创建新的WritePlanBufferManager 24
第5984行:[ 21 :22:00.5546315 A:026 T:020]为appdomain创建新的WritePlanBufferManager 26
第6650行:[21:22:02.9327675 A:028 T:020]为appdomain创建新的WritePlanBufferManager 28
第7316行: [21:22:05.4109092 A:030 T:020]为appdomain 30
创建新的WritePlanBufferManager ....更多

我正在尝试解决其他问题的很多,但我想最初将问题限制在一个AppDomain上。



这些 WritePlanBufferManager 对象中的每一个都用于创建多个(~13)线程,用于延迟/异步排队和处理项目。 / p>

服务配置是标准的,最小的,开箱即用的。 Web.config非常空,没有WCF配置。



App Pool有最大工作进程数= 1,快速失败保护/启动/关闭/ Ping全部禁用。该服务受到来自单个客户端,单线程的请求的打击。



所以,基本问题 - 为什么我会获得多个AppDomain,为什么经常创建其他AppDomain?






更新:好像我的AppDomains正在卸载,所有线程都在中止后几秒钟(大约一分钟)。但是,在App Pool上没有CPU限制,几天的空闲超时,1个最大工作进程,禁用Ping(以及设置为几天的超时),禁用Rapid-Fail保护并关闭所有Process Recycling选项。



所以,问题就变成了,为什么我的AppDomain被卸载 - 事件日志中什么都没有 - 因此我的线程被中止了?

解决方案

听起来像你的服务 InstanceContext 配置为每次调用或每次会话。 WCF确实实现了一个实例缓存机制,因此您可以看到该进程启动。



如果您想要一个真正的单例实例,那么您需要将InstanceContext设置为single(和ConcurrencyMode基于您的问题信息多线程)。获取单例实例的另一种方法是编写代码以使用此构造函数 ServiceHost。



我在营地里不鼓励在生产中使用单件WCF服务实例,因为我相信WCF框架可以更好地完成通过每次调用实例化处理请求,而不是通过滚动我自己。 YMMV:)


I'm trying to debug some mischievous MT code. The most recent, most crazy thing (after adding extensive logging) seems to be that on my single-worker-process, single-machine IIS-hosted WCF service, several app domains are created at the start for the first few requests and then every few seconds another one is created.

Each line below is logged from roughly the following stack trace:

AddItem (WCF service method)
calls SomeRepositoryClass.Open (instance of class was created for this request)
calls WritePlanBufferManager constructor (static instance), accessed in lock construct (on static readonly object field)

Log (A=AppDomain.CurrentDomain.Id, T=Thread.CurrentThread.ManagedThreadId):

    Line 1: [21:21:21.7544122 A:002 T:011] Created new WritePlanBufferManager for appdomain 2
    Line 2: [21:21:31.0299427 A:004 T:008] Created new WritePlanBufferManager for appdomain 4
    Line 3: [21:21:36.5912608 A:006 T:012] Created new WritePlanBufferManager for appdomain 6
    Line 4: [21:21:37.9533387 A:008 T:010] Created new WritePlanBufferManager for appdomain 8
    Line 670: [21:21:41.1065191 A:010 T:020] Created new WritePlanBufferManager for appdomain 10
    Line 1336: [21:21:43.4236516 A:012 T:020] Created new WritePlanBufferManager for appdomain 12
    Line 2002: [21:21:45.8347895 A:014 T:020] Created new WritePlanBufferManager for appdomain 14
    Line 2656: [21:21:48.2479276 A:016 T:020] Created new WritePlanBufferManager for appdomain 16
    Line 3322: [21:21:50.9600827 A:018 T:020] Created new WritePlanBufferManager for appdomain 18
    Line 3988: [21:21:53.2752151 A:020 T:010] Created new WritePlanBufferManager for appdomain 20
    Line 4654: [21:21:55.7353558 A:022 T:020] Created new WritePlanBufferManager for appdomain 22
    Line 5320: [21:21:58.0414877 A:024 T:007] Created new WritePlanBufferManager for appdomain 24
    Line 5984: [21:22:00.5546315 A:026 T:020] Created new WritePlanBufferManager for appdomain 26
    Line 6650: [21:22:02.9327675 A:028 T:020] Created new WritePlanBufferManager for appdomain 28
    Line 7316: [21:22:05.4109092 A:030 T:020] Created new WritePlanBufferManager for appdomain 30
    ....many more

There's plenty of other stuff I'm trying to work out, but I'd like to limit my problems to one AppDomain at a time, initially.

Each of these WritePlanBufferManager objects are used to create several (~13) threads for delayed/async queuing and processing of items.

The service config is bog-standard, minimal, out-of-the-box. Web.config is pretty much empty, and has no WCF config.

App Pool has Maximum Worker Processes = 1, Rapid Fail Protection/startup/shutdown/Ping all disabled. The service is being hammered with requests from a single client, single thread.

So, the basic question - why am I getting multiple AppDomains, why are additional AppDomains created frequently?


Update: It seems as if my AppDomains are being unloaded and all threads aborted after a few seconds (approx. one minute). However, on the App Pool there's no CPU limit, an idle timeout of several days, 1 maximum worker process, Ping is disabled (and timeouts set to several days), Rapid-Fail protection is disabled and all Process Recycling options are turned off.

So, the question becomes, why are my AppDomain(s) being unloaded - nothing in the event log - and as such my threads being aborted?

解决方案

Sounds like your service InstanceContext is configured for either per call or per session. WCF does implement an instance caching mechanism so you're seeing that process spin up.

If you want a true singleton instance implementation then you need to set InstanceContext to single (and ConcurrencyMode to multi-threaded based on your question info). Another way to get a singleton instance is to write code to use this constructor of the ServiceHost.

I'm in the camp that discourages the use of a singleton WCF service instancee in production because I trust the WCF framework to do a much better job of handling requests through per-call instancing than I can by rolling my own. YMMV :)

这篇关于为什么每隔几秒就会创建一个新的AppDomain(WCF / IIS 7)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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