views:

246

answers:

2

Is it worth to set the service with ConcurrencyMode.Multiple and InstanceContextMode.Single attributes to save some performance when using named pipes ?

I mean when I do so I have to bother with multithreading issues.

+2  A: 

Is it worth it? That depends on how much you value the performance gain, compared to how difficult it is to implement.

How good is the performance gain? That depends on the application. Only you can answer that question by measuring.

As always with performance, you must measure.

If it's fast enough already, don't bother.

If it isn't fast enough, measure where the application spends its time. In most applications that involve out-of-process resource access (e.g. database access), the bottleneck is here, rather than in a WCF service's InstanceContextMode.

However, you don't write what kind of application is your WCF service, so it may make a difference in your case.

Mark Seemann
This application isn't done yet. It's in a early development stage. And what do you mean with "what kind of application is your WCF service" ?
I meant that as your question stands right now, your service could do anything, because you didn't describe what it's supposed to do. It could access a database, offer computationally intensive services or perhaps provide simple communication relay services. The performance characteristics will be influenced by what it needs to do.
Mark Seemann
+2  A: 

I automatically use ConcurrencyMode.Multiple for my WCF services, because I normally expect a service to be able to handle multiple requests at the same time. To me, this seems like the most intuitive behaviour for a service (ie: it would be strange if I called a web service and had to wait for 10 outstanding requests from other users before I was attended to).

Using ConcurrencyMode.Single forces the service to process a single request at a time (in the event of multiple requests they are queued). This, potentially, will slow requests down.

But it depends on what each request does. Simple math calculations or string manipulations going to be so fast that the overhead of WCF will be your main bottleneck. If your service queries or modifies some sort of database, the time to do the database operation is likely to be your bottleneck. But if the database is small, or your only expecting a small number of clients, you'll probably never notice the difference. If you're pulling data from 5 web services and doing some complex merging operations, this might be a problem.

Unless you know you'll have multiple simultaneous requests, run with ConcurrencyMode.Single until some sort of objective performance criteria cannot be met. Then, you'll need to do the usual benchmarking to figure out what part of your service is the slowest. Speed that bit up. If it happens that ConcurrencyMode.Single is the slow bit, go for multiple instead!