-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.py
116 lines (104 loc) · 2.86 KB
/
benchmark.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import argparse
import json
import subprocess
import os
import shutil
import random
import time
START_PORT = 6500
def hex128(i):
return format(i, '#018x')
parser = argparse.ArgumentParser(description='Run benchmarks on the trusted DCR system.')
parser.add_argument('graph_file',
metavar='file',
type=argparse.FileType('r'),
help='a TDCR config file describing the DCR graph to use')
parser.add_argument('--peers',
dest='num_peers',
type=int,
required=True,
help='total amount of peers')
parser.add_argument('--exec-delay',
dest='exec_delay',
type=int,
required=True,
help='delay between executions (ms)')
parser.add_argument('--duration',
dest='duration',
type=int,
required=True,
help='total duration of benchmark (ms)')
args = parser.parse_args()
conf = json.load(args.graph_file)
conf['peers'] = []
num_events = len(conf['workflow']['events'])
num_relations = reduce((lambda a, b: a + b),
map((lambda event:
len(event['conditionRelations']) +
len(event['excludeRelations']) +
len(event['includeRelations']) +
len(event['milestoneRelations']) +
len(event['responseRelations'])),
conf['workflow']['events']))
num_peers = args.num_peers
exec_delay = args.exec_delay
duration = args.duration
print 'EVENTS..........%i' % num_events
print 'RELAITONS.......%i' % num_relations
print 'PEERS...........%i' % num_peers
print 'EXEC DELAY......%ims' % exec_delay
print 'TOTAL DURATION..%ims' % duration
# setup peers in config
for pi in range(num_peers):
ei = pi/(num_peers/num_events)
event = conf['workflow']['events'][ei]
peer = {
'addr': '127.0.0.1:{0}'.format(START_PORT + pi),
'event': conf['workflow']['events'][ei]['uid'],
'uid': { 'hex': hex128(pi + 1) },
}
conf['peers'].append(peer)
print 'Writing temp config files...'
if not os.path.exists('temp'):
os.mkdir('temp')
os.chdir('temp')
for pi in range(num_peers):
peer = conf['peers'][pi]
conf['self'] = peer['uid']
with open('{0}.json'.format(peer['uid']['hex']), 'w') as pconf_file:
json.dump(conf, pconf_file)
os.chdir('..')
print 'Starting enclaves...'
os.chdir('../tdcr')
FNULL = open(os.devnull, 'w')
for pi in range(num_peers):
peer = conf['peers'][pi]
subprocess.Popen(
[
'tdcr.bat',
'start',
'-c',
'..\\benchmarks\\temp\\{0}.json'.format(peer['uid']['hex']),
'-p',
str(START_PORT + pi)
],
stdout=FNULL,
stderr=subprocess.STDOUT)
def exec_work():
pi = random.randint(0, num_peers - 1)
ei = random.randint(0, num_events - 1)
subprocess.Popen(
[
'tdcr.bat',
'exec',
'-p',
str(START_PORT + pi),
conf['workflow']['events'][ei]['uid']['hex']
],
stdout=FNULL,
stderr=subprocess.STDOUT)
raw_input('Press any key to start benchmarking...')
start = time.time()
while ((time.time() - start) * 1000 < duration):
exec_work()
time.sleep(exec_delay/1000.)