Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### Running Benchmarks

#### HTTP(S) Announce Peer + Torrent
For this benchmark we use the tool [wrk](https://github.com/wg/wrk).

To run the benchmark using wrk, execute the following example script (change the url to your own tracker url):

wrk -c200 -t1 -d10s -s ./wrk_benchmark_announce.lua --latency http://tracker.dutchbits.nl

53 changes: 53 additions & 0 deletions tests/wrk_benchmark_announce.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
-- else the randomness would be the same every run
math.randomseed(os.time())

local charset = "0123456789ABCDEF"

function hexToChar(hex)
local n = tonumber(hex, 16)
local f = string.char(n)
return f
end

function hexStringToCharString(hex)
local ret = {}
local r
for i = 0, 19 do
local x = i * 2
r = hex:sub(x+1, x+2)
local f = hexToChar(r)
table.insert(ret, f)
end
return table.concat(ret)
end

function urlEncode(str)
str = string.gsub (str, "([^0-9a-zA-Z !'()*._~-])", -- locale independent
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
return str
end

function genHexString(length)
local ret = {}
local r
for i = 1, length do
r = math.random(1, #charset)
table.insert(ret, charset:sub(r, r))
end
return table.concat(ret)
end

function randomInfoHash()
local hexString = genHexString(40)
local str = hexStringToCharString(hexString)
return urlEncode(str)
end

-- the request function that will run at each request
request = function()
path = "/announce?info_hash=" .. randomInfoHash() .. "&peer_id=-lt0D80-a%D4%10%19%99%A6yh%9A%E1%CD%96&port=54434&uploaded=885&downloaded=0&left=0&corrupt=0&key=A78381BD&numwant=200&compact=1&no_peer_id=1&supportcrypto=1&redundant=0"
headers = {}
headers["X-Forwarded-For"] = "1.1.1.1"
return wrk.format("GET", path, headers)
end