Re: Bandwidth Limiting
Re: Bandwidth Limiting
- Subject: Re: Bandwidth Limiting
- From: Wade Tregaskis <email@hidden>
- Date: Mon, 31 Mar 2003 20:07:02 +1000
What is a good way of limiting an applications outgoing (TCP)
bandwidth?
If you know the limit you want (in something like bytes per second),
then simply don't write more than n bytes per second. If your code is
threaded, you can simply sleep for the required time. If it's not
threaded, use a timer or similar mechanism to "come back" to your
transmit code after some suitable interval.
So long as the granularity is small enough (1 second or shorter pauses)
this will in most cases translate to fairly consistent, reduced
bandwidth. If the granularity is too great, you'll end up saturating
the link in short bursts, which is a pretty bad scenario.
If you want a percentage of available bandwidth, you're up for a much
harder job. First you need to determine the maximum bandwidth using
some method, then translate that to a bytes-per-interval type figure,
and apply a suitable mechanism as previously discussed.
Alternatively, if you want to ensure there is always a certain amount
of free bandwidth available, you can simply time how long it takes to
transmit each block of some size. Then only transmit a smaller amount
per that time interval, using a bytes-per-second operation. You'll
want to re-calibrate your setup every once in a while, to make sure
you're not saturating the link (in the case that other apps have
increased their usage) or under-utilizing it (in the case that other
apps have reduced their usage).
Ultimately your particular requirements determine what approach you can
use, and your existing communications code will determine how exactly
you go about doing it.
Wade Tregaskis
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.