I have a standard ASMX web service which uses a lock object to process the first request it receives and reject other requests that come in before processing completes. The web service is hosted on a Windows Server 2003 box with a single-core processor.
To test whether this works as expected, I wrote a client that spawns 100 threads. Each thread makes an asynchronous POST call to the web server (i.e., HttpWebRequest.BeginGetResponse()).
From my own logging, what I’m seeing on IIS is that two threads are spawned. Let’s say thread IDs 1 and 7. Thread 1 is assigned a small number of requests. It accepts and processes them, one after another. Thread 7 is assigned a large number of requests. It rejects them.
Does anyone have theories on the following:
- Why are two threads spawned? And not four or a hundred?
- Why does there seem to be thread discrimination? Thread 1 looks like it has control of the lock object at all times.