3
votes

I have a WCF service hosted in a windows service, InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple

The nettcp binding is configured with listenbacklog="512" and service behavior is configured with maxConcurrentCalls="512"

Both server and client are running on quad processor boxes doing nothing else.

My test client uses an auto-generated proxy and makes 25 async calls on 25 threadpool threads. Although the thread count is slow to ramp up to all 25, it immediately spawns 10 threads and then starts an additional thread every second or so. The WCF Server spawns 2-3 threads to service the requests. The work done by the service's function takes a few hundred milliseconds. It takes about 20 seconds of wall-clock time for all of the client calls to complete.

I've profiled the WCF server and it spends most of its time in ThreadStart_Context calling waitone()

Can somebody tell me why its so slow?

1
Ok, it looks like instantiating 75 clients just takes a long time. That's why my client wasn't spawning threads as fast as I thought it should. It was also impacting any service function calls made during this time by threads that already instantied its clients. If I let it build all of the client objects, then begin making calls, it works quickly. - silent tone

1 Answers

0
votes

I think that the reason for this behaviour is the ThreadPool that WCF is using. It does not spawn threads too often (2 per second after reaching minimum). So you can try increasing the minimum size of the ThreadPool (please read about the consequences of this step first though). Or you can check if it's possible to use a replacement for ThreadPool in this case.