Rant: WCF Defaults Limit Concurrency/Scalability
I guess the designers of Windows Communication Foundation (WCF) really want to discourage some of the uses of the framework -- otherwise, I can't really understand some of their choices.
For instance, when you create a stateful service (InstanceContextMode=InstanceContextMode.Single) the default concurrency behavior is single threaded. In this mode, WCF will serialize all the calls to the service and messages will wait/time-out. While easier to program, this has no real-life use except maybe for demo applications in Teched presentations.
Luckily you can override that and set ConcurrencyMode = ConcurrencyMode.Multiple and get a multithreaded service but the default is useless at best. By the way beware of the ConcurrencyMode.Reentrant since in this setting you still have a single threaded service and WCF can accept calls when you call other services so you need to take care of multithreading but don't get the benefits.
Another example which is even worse, is the default for maximum number of connections for self-hosted services. This is limited to 10 -- yes, 10 -- concurrent connections. We found that out when we set up a service that had, lo and behold, 11 different services that interact with it. These services would call the service something like 10 times a second and occationally we got timeout exceptions. At first we figured we got something wrong with the multi-threading implementation. So we spent a couple of days going over the locks and releases, and what-not. Then we thought the problem was with the transport (net.tcp) so we changed that to http and still saw the same problems. Only then we figured out that, as I mentioned above, the default is 10 concurrent sessions.
To solve this problem you need to configure the Throtteling behavior of the service by using ServiceThrottlingBehavior. This class has three useful settings
The MaxConcurrentCalls property limits the number of messages that currently process across a ServiceHost.
The MaxConcurrentInstances property limits the number of InstanceContext objects that execute at one time across a ServiceHost.
The MaxConcurrentSessions property limits the number of sessions a ServiceHost object can accept.
<>
The default for MaxConcurrentCalls is 16, MaxConcurrentInstances int32.MaxValue and MaxConcurrentSessions is 10.
<>If you're using a self hosted service bump these up or you might DOS yourself like we did :)
Anyway, these defaults are a real barrier to scale and performance. Sure, you can change them easily, but you first have to know about them, and that's the probelm. Hopefully, my wasted time will help you avoid these problems :)

