While not a direct instance management technique, throttling enables you to restrain client connections and the load they place on your service. Throttling allows you to avoid maxing-out your service and the underlying resources it allocates and uses.
The default throttling setting is unlimited. When engaged, if the throttling settings you configured are exceeded, Windows Communication Foundation automatically places the pending callers in a queue and serves them out of the queue in order. Throttling is done per service type—that is, it affects all instances of the service and all its endpoints. This is done by associating the throttle with every channel dispatcher the service uses.
With a per-session service, Max Instances is both the total number of concurrently active instances and the number of concurrent sessions. With a shared-session service, Max Instances is just the total number of concurrently active instances (since each shared instance can have multiple sessions). With a per-call service, the number of instances is actually the same as the number of concurrent calls. Consequently, the maximum number of instances with a per-call service is the minimum of Max Instances and Max Concurrent Calls. Max Instances is ignored with a singleton service since it can only have a single instance anyway.
Throttling is typically configured in the config file. This enables you to throttle the same service code differently over time or across deployment sites. The host can also programmatically configure throttling based on some run-time decisions.
Using the behaviorConfiguration tag you add to your service a custom behavior that sets throttled values.
<system.serviceModel>
<services>
<service type = "MyService"
behaviorConfiguration = "ThrottledBehavior">
...
</service>
</services>
<behaviors>
<behavior name="ThrottledBehavior">
<throttling
maxConcurrentCalls = "12"
maxConnections = "34"
maxInstances = "56"
/>
</behavior>
</behaviors>
</system.serviceModel>
The host process can programmatically throttle the service based on some run-time parameters. You can only do so before the host is opened. Although the host can override the throttling behavior found in the config file by removing the configuration and adding its own, you typically should provide a programmatic throttling behavior only when there is no throttling behavior in the config file.
The throttled values can be read at run time by service developers for diagnostics and analysis purposes. The service instance can access at run time its throttled properties from its dispatcher. First, obtain a reference to the host from the operation context. The host base class ServiceHostBase offers the read-only ChannelDispatchers property—a strongly typed collection of ChannelDispatcherBase objects. Each item in the collection is of the type ChannelDispatcher. ChannelDispatcher offers the property ServiceThrottle which contains the configured throttled values .
Conclusion
While every application is unique when it comes to scalability, performance, and throughput, Windows Communication Foundation does offer canonical instance management techniques that are applicable across the range of applications, thus enabling a wide variety of scenarios and programming models. Understanding Windows Communication Foundation instance management and choosing the right activation mode is critical.Yet applying each mode is surprisingly easy to accomplish. In addition, you can augment the straightforward modes with demarcating operations and instance deactivation.
My Guide to WCF
Juval Lowy is a software architect with IDesign providing Windows Communication Foundation training and architecture consulting. Juval is currently working on a comprehensive Windows Communication Foundation book. He is also the Microsoft Regional Director for the Silicon Valley. Contact Juval at www.idesign.net.
My Guide to WCF
Juval Lowy is a software architect with IDesign providing Windows Communication Foundation training and architecture consulting. Juval is currently working on a comprehensive Windows Communication Foundation book. He is also the Microsoft Regional Director for the Silicon Valley. Contact Juval at www.idesign.net.
No comments:
Post a Comment