3

I have an application which does file upload and download. I also am able to limit upload/download speed to a desired level (CONFIGURABLE), so that my application does not consume the whole available bandwidth. I am able to achieve this using the libcurl (http) library.

But my question is, if I have to limit my upload speed to say 75% of the available upload bandwidth, how do I find out my available upload bandwidth programatically? preferably in C/C++. If it is pre-configured, I have no issues, but if it has to be learnt and adapted each time, like I said, 75% of the available upload limit, I do not know who to figure it out. Same is applicable to download. Any pointers would be of great help.

Sandeep
  • 1,237
  • 1
  • 14
  • 29

1 Answers1

3

There's no way to determine the absolute network capacity between two points on a regular network. The reason is that the traffic can be rerouted in between, other data streams appear or disappear or links can be severed.

What you can do is figure out what is the available bandwidth right now. One way to do it is to upload/download a chunk of data (say 1MB) as fast as possible (no artificial caps), and measure how long it takes. From there you can figure out what bandwidth is available now and go from there.

You could periodically measure the bandwidth again to make sure you're not too way off.

Sorin
  • 11,863
  • 22
  • 26
  • 1
    My question was precisely about knowing available bandwidth. I already know the bytes/sec that it took for my previous transfer (say 1Mb data file was uploaded in 20 seconds at the rate of 52428bytes per second). But now how do you know how much more bandwidth you have access to. My question comes from this link [link](https://www.dropbox.com/help/26/en) and from the line "Specifically, Dropbox automatically throttles itself to 75% of your maximum upload speed to prevent any noticeable slowdown in browsing. " – Sandeep Nov 25 '13 at 11:50
  • @sandeep, yes your observation is correct. With this approach you will never be able to use more bandwidth available. I think, periodically you should kick off few requests without bandwidth capping to recalculate value of total bandwidth available to you. – Ashish May 09 '14 at 15:58
  • U can check speed test command-line ulitity to calculate bandwidth periodically .( https://github.com/sivel/speedtest-cli) – Ashish May 21 '14 at 09:14
  • thanks for suggesting the command line utility, but I was looking for more of an API. – Sandeep May 22 '14 at 13:25