-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrainer.py
78 lines (65 loc) · 2.67 KB
/
trainer.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""
this script tests the server's performance with multiple parameter to determine the best and optimal configuration
:param that are going to be tested
- TIMEOUT
- WINDOW SIZE
"""
import logging
import csv
from multiRunner import multiRunner
import progressbar
from src import WindowServer
import subprocess
from func_timeout import func_timeout
TIMEOUT_POOL = [x * 0.001 for x in range(5, 20)]
WINDOW_SIZE_POOL = range(5, 200, 10)
LOG_FILE = 'training_data/training.csv'
widgets = [
' [', progressbar.Timer(), '] ',
progressbar.Bar("=", "[", "]"),
' (', progressbar.ETA(), ') ',
]
progressbar.streams.wrap_stderr()
Fieldnames = ['Window', 'Timeout', 'Transmission rate', 'time', 'DroppedSegments']
logging.getLogger().disabled = True
def trainer():
with progressbar.ProgressBar(max_value=len(TIMEOUT_POOL) * len(WINDOW_SIZE_POOL), widgets=widgets,
redirect_stdout=True, redirect_stderr=True) as bar:
Counter = 0
Results = []
with open(LOG_FILE, 'w', newline='') as csvFile:
writer = csv.DictWriter(csvFile, fieldnames=Fieldnames)
writer.writeheader()
for Window in WINDOW_SIZE_POOL:
for Timeout in TIMEOUT_POOL:
try:
print(f"\nTESTING WITH WINDOW:{Window}, TIMEOUT:{Timeout}...")
port = 4200 + Counter
Result = func_timeout(30, multiRunner, (WindowServer,),
{"port": port, "TIMEOUT": Timeout, "WINDOW_SIZE": Window})
print(
f"RESULTS WITH WINDOW:{Window}, TIMEOUT:{Timeout} :: {Result[0]} Mbps {Result[1]} s {Result[2]} dp")
except:
subprocess.run(['sudo', 'killall', 'client1'])
Result = (-1, -1, -1)
print(f"EXCEPTION OCCURRED WHEN TESTING WITH WINDOW:{Window}, TIMEOUT:{Timeout}...")
Results.append({
'Window': Window,
'Timeout': Timeout,
'Transmission rate': Result[0],
'time': Result[1],
'DroppedSegments': Result[2]
})
with open(LOG_FILE, 'a', newline='') as csvFile:
writer = csv.DictWriter(csvFile, fieldnames=Fieldnames)
writer.writerow(Results[-1])
Counter += 1
bar.update(Counter)
BestPerf = Results[0]
for Result in Results:
if Result['Transmission rate'] > BestPerf['Transmission rate']:
BestPerf = Result
print(f"BEST PERFORMANCE...")
print(BestPerf)
if __name__ == '__main__':
trainer()