[p2p-hackers] Control network file transfer rate
David Barrett
dbarrett at quinthar.com
Thu Feb 23 17:55:35 UTC 2006
If you're using UDP I'd recommend just modeling yourself after TCP as it
works pretty darn well (and ensures your application is friendly with other
TCP applications out there). Though C++, the relevant class in iGlance is:
http://svn.iglance.com/svn/trunk/iglance/client/GTCP.h
http://svn.iglance.com/svn/trunk/iglance/client/GTCP.cpp
And a sample that uses it to do congestion-controlled, non-lossy file
transfers using a custom RTP profile:
http://svn.iglance.com/svn/trunk/iglance/client/GFileService.h
http://svn.iglance.com/svn/trunk/iglance/client/GFileService.cpp
This'll figure out the fastest you can possibly send to saturate an unknown
link speed. Granted, this isn't quite what you're asking for (you want to
achieve a fixed, predefined throughput), but it's something you'll need if
the specified "maximum throughput" is greater than the actual throughput.
Furthermore, to limit at a maximum throughput you might enforce a ceiling on
'cwnd' (the maximum number of unacknowledged packets you can have "in
flight" on the network at one point in time). I'm not precisely sure how
that'd work (congestion control full of notoriously tricky bugs) but it
might be something like:
MAX_CWND = (MAX_BYTES_PER_S * RTT_UNITS) / (PACKET_SIZE * latestRTT)
So if your RTT (round trip time) is measured in microseconds, you're
targeting 1KBps, you have 1KB packet size, and a 1000ms round-trip latency:
MAX_CWND = (1024 * 1000*1000) / (1024 * 1000*1000) = 1
In other words, you can send at most one 1KB packet before waiting for
acknowledgement. And because you can expect your acknowledgement in one
second, you can send another 1KB packet in another second, for a total
throughput of 1KB/s -- aka 1KBps. Or something like that.
-david
> -----Original Message-----
> From: p2p-hackers-bounces at zgp.org [mailto:p2p-hackers-bounces at zgp.org] On
> Behalf Of Yifei Zeng
> Sent: Thursday, February 23, 2006 1:32 AM
> To: p2p-hackers at zgp.org
> Subject: [p2p-hackers] Control network file transfer rate
>
> Hi all.
>
> I am writing a peer-to-peer file sharing application in Java.
>
> Could someone help me with how to control the download/upload rate of
> the file transfer (practically) through internet?
>
> just like the BitTorrent clients (Bitcomet, Azureus), most of them
> have the function for the user to set the download / upload rate limit.
>
> How should I do in java to achieve this? Can someone please give me
> some ideas or hints?
>
> I am currently using non-blocking IO and socket and for each file
> transfer between two peers there is a non-blocking socket associated
> with it. And my application only has single thread to achieve all
> socket read / write request.
>
> Thanks
>
> Yifei
> _______________________________________________
> p2p-hackers mailing list
> p2p-hackers at zgp.org
> http://zgp.org/mailman/listinfo/p2p-hackers
> _______________________________________________
> Here is a web page listing P2P Conferences:
> http://www.neurogrid.net/twiki/bin/view/Main/PeerToPeerConferences
More information about the P2p-hackers
mailing list