Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

276 lines (217 sloc) 9.765 kb
Measuring Tor's performance as users experience it
The performance (latency and throughput) that Tor users experience depends
on numerous factors and is the subject of current research. In order to
evaluate progress in improving Tor's performance, we need to continuously
measure how fast Tor really is for our users. The primary purpose of these
measurements is to compare how performance evolves over time. This howto
uses a trivial SOCKS client to download files of various sizes over the Tor
network and write down how long substeps take. This setup can be extended
by Tor controllers that log which circuits were used and controllers that
influence guard node selection.
The following configuration parameters are used:
- 50 KB file, downloaded every 5 minutes, timeout of 4:55 minutes,
MaxCircuitDirtiness of 1 minute, SOCKS port 9020, no entry guards
- 1 MB file, downloaded every 30 minutes, timeout of 29:55 minutes, default
MaxCircuitDirtiness of 10 minutes, SOCKS port 9021, no entry guards
- 5 MB file, downloaded every 60 minutes, timeout of 59:55 minutes, default
MaxCircuitDirtiness of 10 minutes, SOCKS port 9022, no entry guards
This document explains:
1) how to setup Torperf to measure download times and a Tor controller
to log which circuits were used and
2) how to attach another Tor controller to influence guard node
1 Setting up Torperf to log download times and circuits
Create sample files of correct sizes and make them available somewhere via
$ dd if=/dev/urandom of=.50kbfile count=1 bs=50K
$ dd if=/dev/urandom of=.1mbfile count=1 bs=1M
$ dd if=/dev/urandom of=.5mbfile count=1 bs=5M
These files are available at (and
the other two file names). You may use these files, or you can use your
own files instead.
Check out and build torperf:
$ git clone git:// ~/torperf
$ cd ~/torperf
$ make
Create data directories for the Tor clients (every download uses its own
Tor client) and write torrc files:
$ mkdir torclient50kb
$ mkdir torclient1mb
$ mkdir torclient5mb
$ cat <<EOF >> torclient50kb/torrc
DataDirectory .
SocksPort 9020
MaxCircuitDirtiness 1 minute
UseEntryGuards 0
RunAsDaemon 1
Log notice file log
ControlPort 10020
CookieAuthentication 1
$ cat <<EOF >> torclient1mb/torrc
DataDirectory .
SocksPort 9021
UseEntryGuards 0
RunAsDaemon 1
Log notice file log
ControlPort 10021
CookieAuthentication 1
$ cat <<EOF >> torclient5mb/torrc
DataDirectory .
SocksPort 9022
UseEntryGuards 0
RunAsDaemon 1
Log notice file log
ControlPort 10022
CookieAuthentication 1
ControlPort and CookieAuthentication are configured so that we can attach
controllers to write additional statistics about the chosen paths (and
possibly influence guard node selection as described below).
Now we need to get TorCtl:
$ git clone git:// TorCtl
Write a start script to start the Tor clients and the controllers,
and execute it (line breaks are only for formatting purposes here):
$ cat <<EOF >> start-tors
cd ~/torperf/torclient50kb && tor -f ~/torperf/torclient50kb/torrc
cd ~/torperf/torclient1mb && tor -f ~/torperf/torclient1mb/torrc
cd ~/torperf/torclient5mb && tor -f ~/torperf/torclient5mb/torrc
sleep 5
cd ~/torperf/torclient50kb && python ../ 10020
../50kb.extradata &
cd ~/torperf/torclient1mb && python ../ 10021
../1mb.extradata &
cd ~/torperf/torclient5mb && python ../ 10022
../5mb.extradata &
$ chmod a+x start-tors
$ ./start-tors
Install the timeout tool:
$ sudo apt-get install timeout # Lenny
$ sudo apt-get install coreutils # Squeeze
Add crontab entries to start the regular requests (line breaks are only
for formatting purposes here):
$ crontab -e
*/5 * * * * timeout -2 295 ~/torperf/trivsocks-client /.50kbfile >> ~/torperf/
2,32 * * * * timeout -2 1795 ~/torperf/trivsocks-client /.1mbfile >> ~/torperf/
8 * * * * timeout -2 3595 ~/torperf/trivsocks-client /.5mbfile >> ~/torperf/
From now on, the three files,, and should
accumulate lines like this ( shown here; line breaks are only for
formatting purposes):
1244638801 612981
1244638801 612991
1244638801 613051
1244638801 613126
1244638801 613134
1244638814 282441
1244638814 282466
1244638817 164531
1244638826 335235
84 51466
The column headers might be:
startsec startusec
socketsec socketusec
connectsec connectusec
negotiatesec negotiateusec
requestsec requestusec
responsesec responseusec
datarequestsec datarequestusec
dataresponsesec dataresponseusec
datacompletesec datacompleteusec
writebytes readbytes
The 50kb.extradata, 1mb.extradata, and 5mb.extradata files should
accumulate lines like this (linebreaks for formatting reasons):
ok 1284059486 $ED16C4DD8E9BCACDE829E6B6571B58095383897A=PPrivCom030
with column headers:
ok|error timestamp firsthop secondhop thirdhop [fourthhop ...]
The first column indicates if this circuit was actually used to fetch
the data or if Tor chose a different circuit because this one was
problematic. For every error entry there should be a following ok
entry, unless the network of the torperf instance is totally dead or
the resource it wants to fetch is unavailable.
The timestamp will NOT necessarily match the timestamps in the .data file
exactly, because additional processing is necessary. You should allow
for up to a minute of slack when matching the two files up. See the script that fulfills this job.
Call it like this:
$ ~/torperf/consolidate-stats DATAFILE EXTRADATAFILE OUTFILE SLACK
Relays are written as $fingerprint=nickname for Named relays and as
$fingerprint~nickname for relays without the Named flag.
If everything works, you might want to let your system start these Tor
clients on system startup. On Debian, this can be done using a crontab
entry, too:
$ crontab -e
@reboot ~/torperf/start-tors 2>/dev/null
2 Setting up Torperf with modified guard node selection
Instead of using a vanilla Tor client, it is possible to attach a Tor
controller that makes the Tor client select its guards in specific ways.
This can help answer questions about the influence of guard nodes choices
on the overall performance of a Tor client.
The script provides that functionality. It will make Tor
choose guards from sets of the a) absolute fastest, b) absolute slowest,
c) best rated vs. advertised ratio or d) worst rated vs. advertised ratio
nodes. The ratio mechanisms provide a way to select the nodes that
the bandwidth authorities think stand out in their measurement.
Put together with a Tor that picks guards randomly, this allows five
different modes of operation for comparison.
To use this, you will want to run 15 Tor instances: 50kb, 1mb, 5mb
for the slow, fast, slowratio, fastratio, regular cases. You can
add a line like this to your start-tors script for each tor instance
(linebreak for formatting reasons):
cd ~/torperf/DATADIR && python ../ CONTROLPORT SPEED
Remember that for the regular case, you don't need extra
Check out the example_start-tors_fastslow.txt file for how that setup
might look.
Don't forget to add twelve entries to your crontab in addition to the
three entries above (linebreaks for formatting reasons):
1,6,11,16,21,26,31,36,41,46,51,56 * * * * timeout -2 295
/.50kbfile >> ~/torperf/ 2>/dev/null
2,7,12,17,22,27,32,37,42,47,52,57 * * * * timeout -2 295
/.50kbfile >> ~/torperf/ 2>/dev/null
3,8,13,18,23,28,33,38,43,48,53,58 * * * * timeout -2 295
/.50kbfile >> ~/torperf/ 2>/dev/null
4,9,14,19,24,29,34,39,44,49,54,59 * * * * timeout -2 295
/.50kbfile >> ~/torperf/ 2>/dev/null
8,38 * * * * timeout -2 1795 ~/torperf/trivsocks-client /.1mbfile >>
~/torperf/ 2>/dev/null
14,44 * * * * timeout -2 1795 ~/torperf/trivsocks-client /.1mbfile >>
~/torperf/ 2>/dev/null
20,50 * * * * timeout -2 1795 ~/torperf/trivsocks-client /.1mbfile >>
~/torperf/ 2>/dev/null
26,56 * * * * timeout -2 1795 ~/torperf/trivsocks-client /.1mbfile >>
~/torperf/ 2>/dev/null
20 * * * * timeout -2 3595 ~/torperf/trivsocks-client /.5mbfile >>
~/torperf/ 2>/dev/null
32 * * * * timeout -2 3595 ~/torperf/trivsocks-client /.5mbfile >>
~/torperf/ 2>/dev/null
44 * * * * timeout -2 3595 ~/torperf/trivsocks-client /.5mbfile >>
~/torperf/ 2>/dev/null
56 * * * * timeout -2 3595 ~/torperf/trivsocks-client /.5mbfile >>
~/torperf/ 2>/dev/null
Jump to Line
Something went wrong with that request. Please try again.