How to limit / throttle bandwidth with *multiple* connections
Posted
by Led
on Stack Overflow
See other posts from Stack Overflow
or by Led
Published on 2009-05-18T20:02:20Z
Indexed on
2010/05/14
8:34 UTC
Read the original article
Hit count: 442
I'm writing an app in C# that downloads concurrently (in different threads) using multiple connections to multiple servers, and I'd like to be able to limit the used bandwidth.
For a single connection the solution would be simple; I'd use the solution posted here : http://www.codeproject.com/KB/IP/Bandwidth_throttling.aspx which calculates a sleep-time for the single connection.
I'd like to know what the best way is to do this for multiple connections.
Using the ThrottledStream posted above and dividing the bandwidth (say 2MB/sec) evenly among the connections isn't right, if I'd have 3 very slow connections and 1 very fast one they'd all be capped to 512kb/sec, so the fast one won't go above 512kb/sec and the other 3 wouldn't even make that.
The preferred solution I think is to cap only the fastest connection(s) so the slower connections are used optimally.
Does anyone have any experience with this, example code or any advice ?
© Stack Overflow or respective owner