WCF Tutorial
Lección 139 de 236 · Part 46 WCF throttling · Bases de datos
Part 46 WCF throttling
Link for all dot net and sql server video tutorial playlists
http://www.youtube.com/user/kudvenkat/playlists
Link for code samples used in the demo
http://csharp-video-tutorials.blogspot.com/2014/04/part-46-wcf-throttling.html
In this video we will discuss throttling in WCF with examples.
What is throughput?
Throughput is the amount of work done in a given time. In addition to Service Instance Context Mode and Concurrency Mode, Throttling settings also influence the throughput of a WCF service.
Throttling settings can be specified either in the config file or in code
Throttling settings in config file
[behaviors]
[serviceBehaviors]
[behavior name=”throttlingBehavior”]
[serviceThrottling
maxConcurrentCalls=”3″
maxConcurrentInstances=”3″
maxConcurrentSessions=”100″/]
[/behavior]
[/serviceBehaviors]
[/behaviors]
Throttling settings in code
using (ServiceHost host = new ServiceHost(typeof(SimpleService.SimpleService)))
{
ServiceThrottlingBehavior throttlingBehavior = new ServiceThrottlingBehavior
{
MaxConcurrentCalls = 3,
MaxConcurrentInstances = 3,
MaxConcurrentSessions = 100
};
host.Description.Behaviors.Add(throttlingBehavior);
host.Open();
Console.WriteLine(“Host started @ ” + DateTime.Now.ToString());
Console.ReadLine();
}
Please Note: ServiceThrottlingBehavior class is present in System.ServiceModel.Description namespace
With the above throttling settings a maximum of 3 concurrent calls are processed.
In addition to maxConcurrentCalls property, maxConcurrentInstances and maxConcurrentSessions may also impact the number of calls processed concurrently.
For example, if we set maxConcurrentCalls=”3″, maxConcurrentInstances=”2″, and maxConcurrentSessions=”100″,
With a PerCall instance context mode, only 2 calls are processed concurrently. This is because every call requires a new service instance, and here we are allowing only a maximum of 2 concurrent instances to be created.
With a Single instance context mode, 3 calls are processed concurrently. This is because with a singleton service there is only one service instance which handles all the requests from all the clients. With singleton maxConcurrentInstances property does not have any influence.
Please note: maxConcurrentSessions is the sum of all types of sessions, that is
1. Application sessions
2. Transport sessions
3. Reliable sessions
4. Secure sessions
Defaults:
Before WCF 4.0
MaxConcurrentCalls: 16
MaxConcurrentSessions: 10
MaxConcurrentInstances: MaxConcurrentCalls + MaxConcurrentSessions (26)
WCF 4.0 and later
MaxConcurrentCalls: 16 * processor count
MaxConcurrentSessions: 100 * processor count
MaxConcurrentInstances: MaxConcurrentCalls + MaxConcurrentSessions