Wednesday, May 13, 2009

Increasing the speed of rTorrent downloads

I use rtorrent to get all my *cough* legal software downloads, and I found a way to optimize the source code of the libtorrent libraries to increase speeds in rtorrent.

I run this in FreeBSD, but its cross portable to most *nix'es...

BSD uses the ports system, and luckily all source files get dumped into /usr/ports/distfiles - I unzipped the libtorrent-0.12.2.tar.gz file into /usr/ports/distfiles/libtorrent-0.12.2.

I modified the following files:

in ./configure

set PEER_NAME to UT161

PEER_NAME "UT161"

this tells all trackers that your client is uTorrent 1.6.1 - which is widely accepted as a "good" version for private trackers and general public domain.

next, edit the ./src/protocol/peer_connection_leech.cc file:

old line #:114 if (cachedTime - m_timeLastRead > rak::timer::from_seconds(240))
new line #:114 if (cachedTime - m_timeLastRead > rak::timer::from_seconds(40))

This will drop an inactive client after 40 seconds instead of 4 minutes, allows faster uptake of seeds and peers.

next, edit ./src/download/download_wrapper.cc:

old line #:272 if (ticks % 4 == 0) {
new line #:272 if (ticks % 1 == 0) {

This will clear ncurses connected clients after 1 tick instead of 4 (1 tick equals 30 seconds)

next, edit ./src/torrent/tracker.cc:

old line #:49 m_normalInterval(1800),
new line #:49 m_normalInterval(600),

This will reconnect to the tracker every 10 minutes to check for new seeds/leechers instead of every 30 minutes.

next, edit ./src/protocol/peer_connection_leech.cc:

old line #:153 if (!download_queue()->canceled_empty() && m_downStall >= 6)
new line #:153 if (!download_queue()->canceled_empty() && m_downStall >= 2)

This will request new file pieces from peers every 2 ticks instead of 6

on BSD, I had to make sure openssl was installed (/usr/ports/security/openssl)

then the installation of libtorrent:
/usr/ports/distfiles/libtorrent-0.12.2>./configure --prefix=/usr/local; make && make install

once thats done, just install rtorrent itself: /usr/ports/net-p2p/rtorrent> make all install

for added performance, I setup my .rtorrent.rc file thus:

bind = xxx.xxx.xxx.xxx (Your local IP address that rtorrent binds to)
ip = xxx.xxx.xxx.xxx (the *Misreported* IP given to trackers he he!)
check_hash = yes (Hash check completed files for consistency)
directory = /root/.incoming (download directory)
session = /root/.session (Session directory, if rtorrent crashes, it will recover from torrents in here)
peer_exchange = yes (exchange tracker and peer info with connected systems)
upload_rate = 1 (I limit uploads to 1kb/sec)
download_rate = 60 (I limit downloads to 60kb/sec)
max_peers = 500 (maximum amount of connected peers per torrent)
dht = on (DHT for trackerless clients, helps a bit)

hash_read_ahead = 8 (FreeBSD Specific)
hash_max_tries = 5 (FreeBSD Specific)
hash_interval = 10 (FreeBSD Specific)

tos=lowdelay (Set TCP Type-Of-Service to lowdelay, best possible peers)
use_udp_trackers = yes (Useless if behind a firewall)

max_memory_usage = 2147483648 (2Gb maximum physical memory used)

A torrent that I was struggling with at about 1.1 Kb/sec shot up to 15Kb/sec after these changes - I can definately see much better speeds. These changes will also help on shaped bandwidth, where torrents are throttled by ISPS.

No comments:

Post a Comment