Skip to content

Commit 6a63611

Browse files
committed
Partially update the benchmark script
It's still not working, but it's not a Python2 script anymore.
1 parent 2ab6454 commit 6a63611

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

src/scripts/benchmark.py

+20-28
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
#!/usr/bin/python
22

3-
from __future__ import print_function
4-
5-
import commands
63
import json
74
import os
85
import subprocess
96
import sys
107
import time
118

12-
LWAN_PATH = './build/testrunner/testrunner'
9+
LWAN_PATH = './src/bin/testrunner/testrunner'
1310
for arg in sys.argv[1:]:
1411
if not arg.startswith('-') and os.path.exists(arg):
1512
LWAN_PATH = arg
@@ -33,25 +30,25 @@ def clearstderrline():
3330

3431

3532
def weighttp(url, n_threads, n_connections, n_requests, keep_alive):
36-
keep_alive = '-k' if keep_alive else ''
37-
command = 'weighttp %(keep_alive)s ' \
38-
'-t %(n_threads)d ' \
39-
'-c %(n_connections)d ' \
40-
'-n %(n_requests)d ' \
41-
'-j ' \
42-
'%(url)s 2> /dev/null' % locals()
43-
4433
clearstderrline()
45-
sys.stderr.write('*** %s\r' % command)
46-
47-
output = commands.getoutput(command)
48-
49-
return json.loads(output)
50-
51-
52-
def weighttp_has_json_output():
53-
output = commands.getoutput('weighttp -j')
54-
return not 'unknown option: -j' in output
34+
sys.stderr.write(f'*** Running weighttp on {url}: threads: {n_threads} ' \
35+
f'conns: {n_connections} reqs: {n_requests} ' \
36+
f'{"keep-alive" if keep_alive else ""} \r')
37+
38+
command = [
39+
'./src/bin/tools/weighttp',
40+
'-k' if keep_alive else '',
41+
'-t', n_threads,
42+
'-c', n_connections,
43+
'-n', n_requests,
44+
'-j',
45+
url
46+
]
47+
print(command)
48+
output = subprocess.run(command, capture_output=True)
49+
output.check_returncode()
50+
51+
return json.loads(output.stdout)
5552

5653

5754
def steprange(initial, final, steps=10):
@@ -151,11 +148,6 @@ def log(self, keep_alive, n_connections, rps, kbps, _2xx, _3xx, _4xx, _5xx):
151148

152149

153150
if __name__ == '__main__':
154-
if not weighttp_has_json_output():
155-
print('This script requires a special version of weighttp which supports JSON')
156-
print('output. Get it at http://github.com/lpereira/weighttp')
157-
sys.exit(1)
158-
159151
plot = cmdlineboolarg('--plot')
160152
xkcd = cmdlineboolarg('--xkcd')
161153
n_threads = cmdlineintarg('--threads', 2)
@@ -183,7 +175,7 @@ def log(self, keep_alive, n_connections, rps, kbps, _2xx, _3xx, _4xx, _5xx):
183175
status = results['status_codes']
184176

185177
output.log(keep_alive, n_connections, results['reqs_per_sec'],
186-
results['kbyte_per_sec'], status['2xx'], status['3xx'],
178+
results['kBps_per_sec'], status['2xx'], status['3xx'],
187179
status['4xx'], status['5xx'])
188180
sleepwithstatus('Waiting for keepalive connection timeout', keep_alive_timeout * 1.1)
189181

0 commit comments

Comments
 (0)