-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlauncher.py
More file actions
executable file
·345 lines (291 loc) · 11.9 KB
/
launcher.py
File metadata and controls
executable file
·345 lines (291 loc) · 11.9 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# /home/hargathor/dev/clarus-proxy/benchmarking/launcher.py
# Copyright (c) 2017 hargathor <3949704+hargathor@users.noreply.github.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -*- coding: utf-8 -*-
# File : /home/hargathor/dev/clarus-proxy/benchmarking/launcher.py
# Author : hargathor <3949704+hargathor@users.noreply.github.com>
# Date : 13.12.2017
# Last Modified Date: 13.12.2017
# Last Modified By : hargathor <3949704+hargathor@users.noreply.github.com>
import argparse
import os
import random
import subprocess
import sys
import time
from concurrent.futures import (ProcessPoolExecutor, ThreadPoolExecutor,
as_completed)
class Logger(object):
def __init__(self, filename="./logs/default.log"):
self.terminal = sys.stdout
self.log = open(filename, "a")
def write(self, message):
log = "[{0}] {1}".format(time.strftime('%Y-%m-%d %H:%M:%S'), message)
self.terminal.write(message)
self.log.write(log)
def flush(self):
pass
LOG_FILE = "./logs/ehealth.log"
root_dir = "./network/"
# datasets = ["std", "large", "xlarge"]
datasets = ["large"]
sys.stdout = Logger(LOG_FILE)
parser = argparse.ArgumentParser(
description='Launch the benchmarks tests for CLARUS')
parser.add_argument('target', type=str,
help='Define the postgres target host')
parser.add_argument('clarus', type=str,
help='Define the proxy host')
parser.add_argument('directory',
help='Define the directory containing the datasets')
parser.add_argument('requirement',
help='Define the requirement id that will be tested')
parser.add_argument('-u', '--users', type=int, default=1,
help='Define the number of virtual users within the pool')
parser.add_argument('-l', '--list', action="store_true",
help='List the requirements supported')
parser.add_argument('-v', '--verbose', action="store_true",
help='Increase the verbosity')
args = parser.parse_args()
def init_db(encrypt=False, dataset_size="std", target=args.target):
db_name = "ehealth_{}".format(random.randint(1, 100))
script_path = os.path.join(root_dir, 'pgsqlBenchmarks.sh')
script_args = " {} {} {} {} {}".format(
target, args.directory, dataset_size, db_name, encrypt)
cmd = script_path + script_args
if args.verbose:
print("Command: {}".format(cmd))
try:
output = subprocess.run(
cmd + " | gawk '{print strftime(\"[%Y-%m-%d %H:%M:%S]\"), $0; fflush();}' >> ./logs/ehealth.log", shell=True, check=True)
except CalledProcessError:
print("An exception occured")
return False
return db_name
def cleaning_db(db_name, target=args.target):
script_path = os.path.join(root_dir, 'cleaning_pgsqlBenchmarks.sh')
script_args = " {} {} {} {}".format(
target, args.directory, "", db_name)
cmd = script_path + script_args
if args.verbose:
print("Command: {}".format(cmd))
try:
output = subprocess.run(
cmd + " | gawk '{print strftime(\"[%Y-%m-%d %H:%M:%S]\"), $0; fflush();}' >> ./logs/ehealth.log", shell=True, check=True)
except CalledProcessError:
print("An exception occured")
return False
return True
def not_implemented():
return nill
def worker_delivery_1():
if subprocess.run("curl --head http://clarussecure.eu/packages/latest/clarus_amd64.deb 2>/dev/null | head -n 1 | cut -d ' ' -f2") == "200":
return True
return False
def worker_delivery_4():
if subprocess.run("curl --head http://clarussecure.eu/doc/latest/CLARUS_INSTALLATION_GUIDE.pdf 2>/dev/null | head -n 1 | cut -d ' ' -f2") == "200":
return True
return False
def worker_delivery_5():
if subprocess.run("curl --head http://clarussecure.eu/doc/latest/CLARUS_CONFIGURATION_GUIDE.pdf 2>/dev/null | head -n 1 | cut -d ' ' -f2") == "200":
return True
return False
def worker_perf(encrypt=False, dataset_size="std", target=args.target):
db_name = "ehealth_{}".format(random.randint(1, 100))
script_path = os.path.join(root_dir, 'pgsqlBenchmarks.sh')
script_args = " {} {} {} {} {}".format(
target, args.directory, dataset_size, db_name, encrypt)
cmd = script_path + script_args
if args.verbose:
print("Command: {}".format(cmd))
try:
output = subprocess.run(
cmd + " | gawk '{print strftime(\"[%Y-%m-%d %H:%M:%S]\"), $0; fflush();}' >> ./logs/ehealth.log", shell=True, check=True)
except CalledProcessError:
print("An exception occured")
return False
time.sleep(5)
script_path = os.path.join(root_dir, 'cleaning_pgsqlBenchmarks.sh')
script_args = " {} {} {} {}".format(
args.target, args.directory, dataset_size, db_name)
cmd = script_path + script_args
if args.verbose:
print("Command: {}".format(cmd))
try:
output = subprocess.run(
cmd + " | gawk '{print strftime(\"[%Y-%m-%d %H:%M:%S]\"), $0; fflush();}' >> ./logs/ehealth.log", shell=True, check=True)
except CalledProcessError:
print("An exception occured")
return False
time.sleep(5)
return True
def worker_review():
"""TODO: Docstring for worker_review.
:returns: TODO
"""
start_time = time.time()
worker_perf(False, dataset_size="std", target=args.clarus)
time2compute = time.time() - start_time
print("{}: Time to compute with CLARUS: {}".format(
"std", time2compute))
return True
def worker_perf_1():
for dataset in datasets:
start_time = time.time()
worker_perf(False, dataset)
time2compute = time.time() - start_time
print("{}: Time to compute directly on postgres: {}".format(
dataset, time2compute))
for dataset in datasets:
start_time = time.time()
worker_perf(False, dataset_size=dataset, target=args.clarus)
time2compute = time.time() - start_time
print("{}: Time to compute with CLARUS: {}".format(
dataset, time2compute))
return True
def worker_perf_2():
for dataset in datasets:
start_time = time.time()
worker_perf(True, dataset)
time2compute = time.time() - start_time
print("{}: Time to compute with naive encryption: {}".format(
dataset, time2compute))
for dataset in datasets:
start_time = time.time()
worker_perf(dataset_size=dataset, target=args.clarus)
time2compute = time.time() - start_time
print("{}: Time to compute with CLARUS: {}".format(dataset, time2compute))
return True
def worker_perf_3():
for dataset in datasets:
my_db = init_db()
script_path = os.path.join(root_dir, 'pgsqlBenchmarks_queries.sh')
script_args = " {} {} {} {} {}".format(
args.target, args.directory, dataset, my_db, False)
cmd = script_path + script_args
start_time = time.time()
if args.verbose is True:
print(cmd)
try:
output = subprocess.run(
cmd + " | gawk '{print strftime(\"[%Y-%m-%d %H:%M:%S]\"), $0; fflush();}' >> ./logs/ehealth.log", shell=True, check=True)
except subprocess.CalledProcessError as e:
print("An exception occured: {}".format(e.output))
return False
time2compute = time.time() - start_time
print("NO_SECURITY: {}s\tdataset size: {}".format(time2compute, dataset))
cleaning_db(my_db)
time.sleep(5)
my_db = init_db(target=args.clarus)
script_path = os.path.join(root_dir, 'pgsqlBenchmarks_queries.sh')
script_args = " {} {} {} {} {}".format(
args.clarus, args.directory, dataset, my_db, False)
cmd = script_path + script_args
start_time = time.time()
if args.verbose is True:
print(cmd)
try:
output = subprocess.run(
cmd + " | gawk '{print strftime(\"[%Y-%m-%d %H:%M:%S]\"), $0; fflush();}' >> ./logs/ehealth.log", shell=True, check=True)
except subprocess.CalledProcessError as e:
print("An exception occured: {}".format(e.output))
return False
time2compute = time.time() - start_time
print("CLARUS: {}s\tdataset size: {}".format(time2compute, dataset))
cleaning_db(my_db, target=args.clarus)
time.sleep(5)
my_db = init_db(encrypt=True)
script_path = os.path.join(root_dir, 'pgsqlBenchmarks_queries.sh')
script_args = " {} {} {} {} {}".format(
args.target, args.directory, dataset, my_db, True)
cmd = script_path + script_args
start_time = time.time()
if args.verbose == True:
print(cmd)
try:
output = subprocess.run(
cmd + " | gawk '{print strftime(\"[%Y-%m-%d %H:%M:%S]\"), $0; fflush();}' >> ./logs/ehealth.log", shell=True, check=True)
except CalledProcessError:
print("An exception occured")
return False
time2compute = time.time() - start_time
print("NAIVE SECURITY: {}s\tdataset size: {}".format(time2compute, dataset))
cleaning_db(my_db)
time.sleep(5)
return True
def worker_perf_4():
dataset_size = "std"
start_time = time.time()
worker_perf(dataset_size=dataset_size)
time2compute = time.time() - start_time
print("{}\t: {}".format(dataset_size, time2compute))
# Sleeping to allow postgres to cool down
time.sleep(5)
dataset_size = "large"
start_time = time.time()
worker_perf(dataset_size=dataset_size)
time2compute = time.time() - start_time
print("{}\t: {}".format(dataset_size, time2compute))
# Sleeping to allow postgres to cool down
time.sleep(5)
dataset_size = "xlarge"
start_time = time.time()
worker_perf(dataset_size=dataset_size)
time2compute = time.time() - start_time
print("{}\t: {}".format(dataset_size, time2compute))
return True
def worker_perf_5():
# TODO
pass
def worker_transport_3():
# TODO
# Calling JMETER here
test_plan = "test_plans/REQ-NF_TRSP-1.3.jmx"
result_file = "results/REQ-NF_TRSP-1.3.jtl"
subprocess.run("jmeter -n -t {} -l {}".format(test_plan, result_file))
print("Latency: {}".format(subprocess.run(
"cat {} | awk -F ',' '{print (2}')".format(result_file))))
def worker():
print("Using worker {}".format(args.requirement))
return requirement_func[args.requirement]()
requirement_func = {
'REQ-NF_DLV-1.1': worker_delivery_1,
'REQ-NF_DLV-1.4': worker_delivery_4,
'REQ-NF_DLV-1.5': worker_delivery_5,
'REQ-NF_PERF-1.1': worker_perf_1,
'REQ-NF_PERF-1.2': worker_perf_2,
'REQ-NF_PERF-1.3': worker_perf_3,
'REQ-NF_PERF-1.4': worker_perf_4,
'REQ-NF_PERF-1.5': worker_perf_5,
'REQ-NF_TRSP-1.3': worker_transport_3,
'review': worker_review
}
def main():
if args.list == True:
for key, value in requirement_func.items():
print(key)
return 0
futures = []
start_time = time.time()
with ThreadPoolExecutor(max_workers=args.users) as executor:
for x in range(args.users):
futures.append(executor.submit(worker))
for x in as_completed(futures):
print(x.result())
time2compute = time.time() - start_time
print("Time to compute: {}".format(time2compute))
if __name__ == '__main__':
main()