File: rpc2-rtt-fixed.lua

package info (click to toggle)
rpc2 2.7%2Bdebian-5
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 2,852 kB
  • ctags: 2,661
  • sloc: ansic: 19,928; sh: 9,110; lex: 437; yacc: 416; makefile: 126; asm: 35
file content (60 lines) | stat: -rw-r--r-- 1,749 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
--
-- Fixed bandwidth 'estimator' where we know our network environment
--

print "loading fixed estimator"

--
-- Latencies are rough estimates based on the average reported by 'ping -c10'
-- bandwidth as kbits/sec
--
--[[ ppp modem
latency, bandwidth_tx, bandwidth_rx = time(0.200), 56, 56
--]]
-- [[ cable modem / adsl
latency, bandwidth_tx, bandwidth_rx = time(0.014), 364, 4000
--]]
--[[ 100mbit ethernet
latency, bandwidth_tx, bandwidth_rx = time(0.0006), 1e8, 1e8
--]]
--[[ gigabit ethernet
latency, bandwidth_tx, bandwidth_rx = time(0.00025), 1e9, 1e9
--]]

-- convert values
bandwidth_tx = bandwidth_tx / 8 -- bits/sec -> bytes/sec
bandwidth_rx = bandwidth_rx / 8 -- bits/sec -> bytes/sec

-- assume any delays are caused by concurrent data transfers
local concurrency = 1
local function estimate(host, bytes_sent, bytes_recv)
    local rto = bytes_sent / bandwidth_tx + bytes_recv / bandwidth_rx
    return rto * concurrency
end

function rtt_update(host, elapsed, bytes_sent, bytes_recv)
    local rto = estimate(host, bytes_sent, bytes_recv)
    -- print("uRTT", host.name, bytes_sent, bytes_recv, elapsed, latency + rto)

    -- try to estimate how many concurrent transfers there are
    if concurrency > 1 and elapsed < latency + rto then
	concurrency = concurrency - 1
    else
	while elapsed > latency + rto do
	    concurrency = concurrency + 1
	    rto = rto * 2
	end
    end
    -- print("concurrency", concurrency)
end

function rtt_getbandwidth(host)
    return bandwidth_tx / concurrency, bandwidth_rx / concurrency
end

function rtt_getrto(host, bytes_sent, bytes_recv)
    local rto = estimate(host, bytes_sent, bytes_recv)
    -- print("est", host.name, bytes_sent, bytes_recv, latency + rtt)
    return latency + rto
end