简体   繁体   中英

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.

So I decided to remove all concurrency by setting the following attributes for my ASMX webservice:

[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

But, once a new(second) connection request is established, instead of receiving HTTP Error 503: "The service is unavailable". I would like to put that request in the queued state to wait till the connection will be free again.

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." 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.

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:

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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