Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tune a WCF Service for better performance using ServiceThrottling

Tags:

c#

.net

wcf

Iam new to WCF Services.

We have a service which listens to an MSMQ. maxConcurrentInstances and maxConcurrentSessions is set to 1 for the service. which results lot of messages in the queue and messages are served slowly.

What is the difference between maxConcurrentInstances and maxConcurrentSessions attribute in the serviceThrottling element.

Currently it takes 10 Mins to serve 120 Messages which is very slow.

What should be the ideal value to improve the performance of the service.

Thanks in Advance

like image 451
Ananth Avatar asked Oct 07 '22 03:10

Ananth


1 Answers

maxConcurrentInstances: Maximum number of instances of the service class that can serve requests at the same time regardless of the concurrency mode and instance context mode.

maxConcurrentSessions: Maximum number of WCF sessions active at the same time.


Assuming the concurrency mode is set to NO multithreading.

IF Instance context mode = Per session 
   THEN  Max number of requests processed in parallel = Min(maxConcurrentInstances, maxConcurrentSessions)

IF Instance context mode = Per call 
   THEN Max number of requests processed in parallel = maxConcurrentInstances

IF Instance context mode = Single 
   THEN Max number of requests processed in parallel = 1

Assuming that concurrency mode is set to multithreading.

A single instance can now process several requests but you have to take care of the concurrency issues.


The important question is: how do you choose the instance context mode?

  • You are not confident with multithread programming: stick to PerSession or PerCall
  • You don't need to keep data at the service level between calls from the same client: Avoid PerSession
  • Creating a new instance of the service is very costly: Use Single but be prepare to deal with concurrency issues.

After that it is a matter of tuning the max number of instances (for PerCall) and sessions (for PerSession). Usually you start by setting it to an arbitrary number like 100 and see if it make thing faster. If it does, then fine. If not, check if your instances are sufficiently quick to create.

like image 78
Johann Blais Avatar answered Oct 13 '22 10:10

Johann Blais