简体   繁体   English

IIS。 是否可以将网站配置为限制连接数 = 1,但是所有新连接都将放在队列中?

[英]IIS. Is it possible to configure the website to have limit number of connections = 1 however all new connections would be placed in Queue?

I have an ASP.NET Web Service (ASMX) which is using a very fragile C library that is messing up the memory in case if it is used concurrently. I have an ASP.NET Web Service (ASMX) which is using a very fragile C library that is messing up the memory in case if it is used concurrently.

So I decided to remove all concurrency by setting the following attributes for my ASMX webservice:因此,我决定通过为我的 ASMX Web 服务设置以下属性来删除所有并发:

[ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Single, InstanceContextMode = InstanceContextMode.Single)]

Unfortunately, it hasn't helped me, so I investigated that the issue is on the IIS side, that it is allowing the concurrent connections + it is even having its settings for the concurrent request limitation: limit 1 is configured不幸的是,它并没有帮助我,所以我调查了问题出在 IIS 端,它允许并发连接 + 它甚至设置了并发请求限制:已配置限制 1

But, once a new(second) connection request is established, instead of receiving HTTP Error 503: "The service is unavailable".但是,一旦建立新的(第二个)连接请求,而不是接收 HTTP 错误 503:“服务不可用”。 I would like to put that request in the queued state to wait till the connection will be free again.我想将该请求放入队列中的 state 等待连接再次空闲。

I know that Queue length is connected to the max connection limit and it can be configured in the application pool: Queue length config我知道队列长度连接到最大连接限制,它可以在应用程序池中配置:队列长度配置

So my question is: Is it possible to configure the website on IIS in a way that the maximum number of concurrent connections is set to 1, Queue length is set to 100 in a way when 1000 concurrent connection requests come up, the first request will be processed, next 99 will be in the queue and the rest 900 will be returned directly to the customer "HTTP Error 503."所以我的问题是:是否可以在 IIS 上配置网站,将最大并发连接数设置为 1,队列长度设置为 100,当 1000 个并发连接请求出现时,第一个请求将被处理,下一个 99 将在队列中,rest 900 将直接返回给客户“HTTP 错误 503”。 The service is unavailable.服务不可用。 "? “?

Thank you in advance and sorry for my English.提前谢谢你,对不起我的英语。

EDIT: I'm using IIS 10.0, Application pool: .NET CLR version 2.0 and Managed Pipeline mode is Classic.编辑:我正在使用 IIS 10.0,应用程序池:.NET CLR 2.0 版和托管管道模式是经典。

Unfortunately, I didn't find a way to fix it via IIS configuration regardless CPU number, so I solved my issue with that fragile C library by adding mutex on the service level call:不幸的是,无论 CPU 数量如何,我都没有找到通过 IIS 配置修复它的方法,所以我通过在服务级别调用上添加互斥锁解决了我与那个脆弱的 C 库的问题:

Mutex singleCallMutex = new Mutex(false, "singleCallMutex");
singleCallMutex.WaitOne();

//C Library call

singleCallMutex.ReleaseMutex();

So technically I have multiple concurrent requests, but they are executed one by one(In my case there will be a small amount of clients so I don't need to worry about connection timeouts if something, I just needed to solve concurrent request corner case).所以从技术上讲,我有多个并发请求,但它们是一个一个执行的(在我的情况下会有少量的客户端,所以如果有什么我不需要担心连接超时,我只需要解决并发请求的极端情况)。

Thanks to all of you who were helping me on that one, your answers truly helped me to find the way out!感谢所有帮助我的人,您的回答确实帮助我找到了出路!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM