3 # Test network throughput.
6 # 1) on host_A: throughput -s [port] # start a server
7 # 2) on host_B: throughput -c count host_A [port] # start a client
9 # The server will service multiple clients until it is killed.
11 # The client performs one transfer of count*BUFSIZE bytes and
12 # measures the time it takes (roundtrip!).
26 if sys
.argv
[1] == '-s':
28 elif sys
.argv
[1] == '-c':
35 sys
.stdout
= sys
.stderr
36 print 'Usage: (on host_A) throughput -s [port]'
37 print 'and then: (on host_B) throughput -c count host_A [port]'
43 port
= eval(sys
.argv
[2])
46 s
= socket(AF_INET
, SOCK_STREAM
)
49 print 'Server ready...'
51 conn
, (host
, remoteport
) = s
.accept()
53 data
= conn
.recv(BUFSIZE
)
59 print 'Done with', host
, 'port', remoteport
65 count
= int(eval(sys
.argv
[2]))
68 port
= eval(sys
.argv
[4])
71 testdata
= 'x' * (BUFSIZE
-1) + '\n'
73 s
= socket(AF_INET
, SOCK_STREAM
)
81 s
.shutdown(1) # Send EOF
83 data
= s
.recv(BUFSIZE
)
86 print 'Raw timers:', t1
, t2
, t3
, t4
, t5
87 print 'Intervals:', t2
-t1
, t3
-t2
, t4
-t3
, t5
-t4
89 print 'Throughput:', round((BUFSIZE
*count
*0.001) / (t5
-t1
), 3),