-
Notifications
You must be signed in to change notification settings - Fork 7
/
stress.py
52 lines (45 loc) · 1.37 KB
/
stress.py
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
# run as: python3 stress.py <n_workers> <users_per_client> <n_rounds> <url> <sleep/nosleep>
import sys
import subprocess
import opuslib
import numpy as np
import tempfile
import random
from multiprocessing import Pool
import time
import json
PACKET_INTERVAL = 0.6 # 600ms
def summarize(timing):
return min(timing), max(timing), sum(timing)/len(timing)
def run(n_workers, users_per_client, n_rounds, url, should_sleep):
n_workers = int(n_workers)
processes = []
for i in range(n_workers):
processes.append(subprocess.Popen(
["python3", "stress_helper.py", n_rounds, users_per_client,
"stress%s" % i, url, should_sleep],
stdout=subprocess.PIPE))
timings = []
for process in processes:
process.wait()
result_text = process.stdout.read()
try:
timings.append(json.loads(result_text))
except:
print("Failure:", result_text)
should_sleep = {"sleep": True,
"nosleep": False}[should_sleep]
if should_sleep:
all_timings = []
for timings in timings:
all_timings.extend(timings)
print("[min=%.0f max=%.0f avg=%.0f]" % summarize(all_timings))
else:
total = 0
for timing in timings:
est = PACKET_INTERVAL * 1000 * len(timing) / sum(timing)
print("est %.0f clients" % est)
total += est
print("total: %.0f clients" % total)
if __name__ == "__main__":
run(*sys.argv[1:])