I'm using WCF for downloading audio data from database. I need to set maximum download speed.
How can it be done in WCF?
Thanks!
WCF handles throttling through the ServiceThrottlingBehavior class.
How to throttle a Wcf service
WCF provides a throttling behavior to manage server load and resource consumption (with the following properties):
MaxConcurrentCalls. Limits the number of concurrent requests that can be processed by all service instances. The default value is 16.
MaxConcurrentInstances. Limits the number of service instances that can be allocated at a given time. For PerCall services, this setting matches the number of concurrent calls. For PerSession services, this setting matches the number of active session instances. This setting doesn t matter for Single instancing mode, because only one instance is ever created. The default value for this setting is 2,147,483,647.
MaxConcurrentSessions. Limits the number of active sessions allowed for the service. This includes application sessions, transport sessions (for TCP and named pipes, for example), reliable sessions, and secure sessions. The default value is 10.
I don't think there is a built-in mechanism to control bandwidth. You would need to implement a custom stream. You use a thread to write the the stream. You can then control how much data to write each second. For example, you could write 250Kb, and then perform a thread sleep for one second.
See also: Concurrency and Throttling Configurations for WCF Services
Ok, insane late-friday shot in the dark: Scott Gu blogged about a new bit-rate throttling module for IIS 7 Here: http://weblogs.asp.net/scottgu/archive/2008/03/18/iis-7-0-bit-rate-throttling-module-released.aspx
It's actually intended for media files, but out of the box, it's triggered by the extension. By itself, this may not be enough -- you are serving the files from a service -- .svc, and you probably don't want to throttle all of your service calls. (if you don't mind throttling them all, it might work out of the box -- just set a rule on .svc.
What's more interesting though, is this post: http://learn.iis.net/page.aspx/149/bit-rate-throttling-extensibility-walkthrough/ This guy talks about how to customize the throttler.
You can do it based on response content (he has examples of reading the bit-rate inside of a media file).
Or, about 3/4 of the way down the article, look for this heading: "Setting the Server Variables Programmatically"
He describes how to build an http module/handler -- you could theoretically use that to trigger IIS's throttling based upon a URL (like the url to your media server service)
Never tried this -- total WAG before I go home for the weekend. Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With