Bandwith Shaping

F

flamesrock

Just curious - is there an easy way to shape bandwith in python. If I
wanted to have a max download speed for instance

-thanks
 
P

phil

flamesrock said:
Just curious - is there an easy way to shape bandwith in python. If I
wanted to have a max download speed for instance

-thanks
Interesting normally bandwidth shaping is an IP stack function

in the Kernel.

You are receiving a download within a python program?
And want to slow it down?
You could put a sleep(.01) in your receive loop.
That's about as fine as sleep gets, i've read.

But those packets ( I assume TCP ) are going to stack up somewhere,
the sender is gonna keep trying and retrying. In other words
you are increasing overall load to someone's router and the
network.
Someone correct me if I'm drunk on this.
 
H

Heiko Wundram

Am Mittwoch, 4. Mai 2005 20:11 schrieb phil:
But those packets ( I assume TCP ) are going to stack up somewhere,
the sender is gonna keep trying and retrying. In other words
you are increasing overall load to someone's router and the
network.

This is not true, as TCP tries to adjust its sending speed at the sender end
to the receiving speed at the receiver end (it raises speed until packets
start getting dropped, and when they are, it starts decreasing send speed
again).

Of course, this requires a proper TCP implementation, but any operating system
should have one.

What you said, with a sleep(.01) is actually not quite the way to go. What you
could do is something like the following:

MAX_RATE = 1*1024 # (1k)
MAX_SEND = 1024
data = "blabber"
sent = 0
starttime = time.time() - 0.01
while data:
curtime = time.time()
if sent / ( curtime - starttime ) > MAX_RATE:
time.sleep(0.5)
continue
newsent = sock.send(data[:MAX_SEND])
data = data[newsent:]
sent += newsent
Someone correct me if I'm drunk on this.

See above. ;)

--
--- Heiko.
listening to: Pearl Jam - Man Of The Hour
see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQBCeT1Df0bpgh6uVAMRAsYuAJsGuQh+cKGhMPizKZQsBhEhmv15egCcC2A/
/vn+cQhJptSLBGIHcj4iPE4=
=cYxi
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top