I guess the designers of WCF really want to discourage some of the uses of the framework - I can't really understand some of their choices, if that was not the case.

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 it is 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 :)


 
Sunday, June 15, 2008 11:42:51 AM (GMT Standard Time, UTC+00:00)
Those aren't the only ones. The default reader quotas are completely useless in most scenarios I've had to deal with.
Sunday, June 15, 2008 12:40:11 PM (GMT Standard Time, UTC+00:00)
Tomas, I totally agree, I just gave a couple of examples.
Another example is the message size default for net.tcp etc.

Arnon
Wednesday, June 18, 2008 8:01:48 PM (GMT Standard Time, UTC+00:00)
Hi,

I would disagree. The WCF team had put some limitations in place
to protect people from DOS attacks. Now the questions is
what the limits should be. I think that they should be
as small as possible because this gives developers an opportunity to hit those limits early, preferably on one of their dev racks instead in production.
But I agree that these limits should be much better advertised :).
Sunday, July 20, 2008 4:45:38 PM (GMT Standard Time, UTC+00:00)
Yeah, I totally agree these are BS values. They sure as hell aren't going to protect anyone from DOS attacks because they aren't reasonable. After hitting these limits early on in dev, everyone is just going to pump them up to something insanely high so they don't run into it again. WCF is generally used behind the firewall... when's the last time you had someone DOS you there? In any case, these limits just make you DOS yourself by default which is a pretty retarded way to "prevent" DOS attacks.
Comments are closed.