-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdcfs_tuner.py
executable file
·82 lines (65 loc) · 1.98 KB
/
dcfs_tuner.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
79
80
81
#!/usr/bin/env python
from __future__ import print_function
import os
import subprocess
import csv
import Queue
import threading
thread_pool_size = 4
def worker(q, results):
while True:
params = q.get()
if params is None:
return
d, p, v, = params
env = dict(os.environ)
env[p] = str(v)
print("Testing {} with {} = {}...".format(d, p, v))
out = subprocess.check_output("./main -v".split(), stdin=open(d), stderr=open("/dev/null"), env=env)
#del os.environ[p]
price = int(out.split("\n")[0])
print("{}:{}={}\t{}".format(d, p, v, price))
results[d][p].append((v, price))
def build_app():
try:
out = subprocess.check_output("go build".split())
out += subprocess.check_output("go build fspcmd/main.go".split())
except:
print("Couldn't build app!")
print(out)
os.exit(1)
data_sets = [
'/tmp/data_20.txt',
'/tmp/data_50.txt',
'/tmp/data_100.txt',
]
params = {
'DCFS_MAX_BRANCHES' : range(1, 10, 2),
'DCFS_DISC_W' : [x * 0.01 for x in range(0, 200, 25)],
'DCFS_MIN_DISC' : [x * 0.01 for x in range(-50, 50, 10)],
'DCFS_NEXT_AVG_W' : [x * 0.01 for x in range(0, 100, 10)],
'DCFS_DISC_THRESH' : range(0, 1000, 200),
}
def main():
results = {}
for d in data_sets:
results[d] = {}
for p in params.keys():
results[d][p] = []
q = Queue.Queue()
threads = [threading.Thread(target=worker, args=(q, results, )) for i in range(thread_pool_size)]
os.environ["FSP_ENGINE"] = "DCFS"
for p, vals in params.items():
for d in data_sets:
for v in vals:
q.put((d, p, v, ))
for t in threads:
t.start()
q.put(None)
for t in threads:
t.join()
del os.environ["FSP_ENGINE"]
print(results)
if __name__ == "__main__":
build_app()
main()