5

i wrote an app that sync's local folders with online folders, but it eats all my bandwidth, how can i limit the amount of bandwidth the app use? (programatically)?

stoic
  • 4,700
  • 13
  • 58
  • 88
  • How often do you check for updates? And how often do you *need* to check? Decreasing the update interval will probably help a lot. – Tomas Aschan Jun 17 '10 at 14:10
  • 4
    Duplicate Question. See --> http://stackoverflow.com/questions/847422/how-to-programatically-limit-bandwidth-usage-of-my-c-windows-forms-application – Refracted Paladin Jun 17 '10 at 14:10

3 Answers3

2

Take a look at http://www.codeproject.com/KB/IP/MyDownloader.aspx

He's using the well known technique which can be found in Downloader.Extension\SpeedLimit

Basically, before more data is read of a stream, a check is performed on how much data has actually been read since the previous iteration . If that rate exceeds the max rate, then the read command is suspended for a very short time and the check is repeated. Most applications use this technique.

gda2004
  • 718
  • 13
  • 32
Polity
  • 36
  • 1
0

Try this: http://www.netlimiter.com/ It's been on my "check this out" list for a long time (though I haven't tried it yet myself).

JMarsch
  • 21,484
  • 15
  • 77
  • 125
0

I'd say "don't". Unless you're doing something really wrong, your program shouldn't be hogging bandwidth. Your router should be balancing the available bandwidth between all requests.

I'd recommend you do the following:

a) Create md5 hashes for all the files. Compare hashes and/or dates and sizes for the files and only sync the files that have changed. Unless you're syncing massive files you shouldn't have to sync a whole lot of data.

b) Limit the sending rate. In your upload thread read the files in 1-8KB chunks and then call Thread.Sleep after every chunk to limit the rate. You have to do this on the upload side however.

c) Pipe everything through a Gzip stream. (System.IO.Compression) For text files this can reduce the size of the data that needs to be transfered.

Hope this helps!

Timothy Baldridge
  • 10,455
  • 1
  • 44
  • 80
  • thanx... your compression and sending rate comments will definately come in handy aswell. my folders can be up to 30 gig... and the limit needs to be set on the app itself. "Refracted Paladin" pointed me in the right direction for programmaticly setting rate. – stoic Jun 17 '10 at 16:19