forked from NYU-NEWS/janus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
executable file
·1194 lines (1019 loc) · 45.6 KB
/
run.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
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# python system modules
import os
import sys
import time
import shutil
import logging
import subprocess
import multiprocessing
import argparse
import traceback
import itertools
import random
import math
import signal
from threading import Thread
from argparse import ArgumentParser
from multiprocessing import Value
from multiprocessing import Lock
import yaml
import tempfile
from collections import OrderedDict
# third-party python modules
from tabulate import tabulate
# deptran python modules
sys.path += os.path.abspath(os.path.join(os.path.split(__file__)[0], "./rrr/pylib")),
sys.path += os.path.abspath(os.path.join(os.path.split(__file__)[0], "./deptran")),
from simplerpc import Client
from simplerpc.marshal import Marshal
from deptran.rcc_rpc import ServerControlProxy
from deptran.rcc_rpc import ClientControlProxy
from pylib import ps
LOG_LEVEL = logging.INFO
LOG_FILE_LEVEL = logging.DEBUG
logger = logging.getLogger('janus')
cwd = os.getcwd()
deptran_home, ff = os.path.split(os.path.realpath(__file__))
g_log_dir = deptran_home + "/log"
ONE_BILLION = float(10 ** 9)
g_latencies_percentage = [0.5, 0.9, 0.99, 0.999]
g_latencies_header = [str(x * 100) + "% LATENCY" for x in g_latencies_percentage]
g_att_latencies_percentage = [0.5, 0.9, 0.99, 0.999]
g_att_latencies_header = [str(x * 100) + "% ATT_LT" for x in g_att_latencies_percentage]
g_n_try_percentage = [0.5, 0.9, 0.99, 0.999]
g_n_try_header = [str(x * 100) + "% N_TRY" for x in g_n_try_percentage]
g_interest_txn = "NEW ORDER"
g_max_latency = 99999.9
g_max_try = 99999.9
hosts_path_g = ""
hosts_map_g = dict()
class TxnInfo(object):
def __init__(self, txn_type, txn_name, interest):
self.txn_type = txn_type
self.start_txn = 0
self.pre_start_txn = 0
self.total_txn = 0
self.pre_total_txn = 0
self.total_try = 0
self.pre_total_try = 0
self.commit_txn = 0
self.pre_commit_txn = 0
self.txn_name = txn_name
self.max_data = list()
self.max_interval = 0.0
self.interest = interest
self.last_interval_start = 0
self.this_latencies = []
self.last_latencies = []
self.attempt_latencies = []
self.all_latencies = []
self.n_try = []
self.min_interval = 0.0
self.update_latency = False
self.mid_retry_exhausted = 0
self.mid_status = 0 # 0: not started, 1: ongoing, 3: end
self.mid_pre_start_txn = 0
self.mid_start_txn = 0
self.mid_pre_total_txn = 0
self.mid_total_txn = 0
self.mid_pre_total_try = 0
self.mid_total_try = 0
self.mid_pre_commit_txn = 0
self.mid_commit_txn = 0
self.mid_time = 0.0
self.mid_latencies = []
self.mid_all_latencies = []
self.mid_attempt_latencies = []
self.mid_n_try = []
def set_mid_status(self):
self.mid_status += 1
def clear(self):
self.start_txn = 0
self.total_txn = 0
self.total_try = 0
self.commit_txn = 0
self.mid_retry_exhausted = 0
self.this_latencies = []
self.min_interval = g_max_latency
self.attempt_latencies = []
self.n_try = []
if self.mid_status == 0:
self.mid_pre_start_txn = 0
self.mid_pre_total_txn = 0
self.mid_pre_total_try = 0
self.mid_pre_commit_txn = 0
elif self.mid_status == 1:
self.mid_start_txn = 0
self.mid_total_txn = 0
self.mid_total_try = 0
self.mid_commit_txn = 0
def push_res(self, start_txn, total_txn, total_try, commit_txn,
this_latencies, last_latencies, latencies,
attempt_latencies, interval_time, n_tried, n_retry_exhausted):
self.start_txn += start_txn
self.total_txn += total_txn
self.total_try += total_try
self.commit_txn += commit_txn
if self.min_interval > interval_time:
self.min_interval = interval_time
if self.mid_status == 0:
logger.debug("before recording period: {}".format(self.txn_type))
self.mid_pre_start_txn += start_txn
self.mid_pre_total_txn += total_txn
self.mid_pre_total_try += total_try
self.mid_pre_commit_txn += commit_txn
logger.debug("mid_pre_commit_txn (+{}): {}".format(commit_txn, self.mid_pre_commit_txn))
elif self.mid_status == 1:
logger.debug("during recording period!!! {}".format(self.txn_type))
self.mid_latencies.extend(latencies)
self.mid_all_latencies.extend(self.mid_latencies)
self.mid_attempt_latencies.extend(attempt_latencies)
self.mid_time += interval_time
self.mid_n_try.extend(n_tried)
self.mid_start_txn += start_txn
self.mid_total_txn += total_txn
self.mid_total_try += total_try
self.mid_commit_txn += commit_txn
self.mid_retry_exhausted += n_retry_exhausted
#logger.debug("mid_commit_txn (+{}): {}".format(commit_txn, self.mid_commit_txn))
#logger.debug("self.mid_latencies: {}".format(self.mid_latencies))
def get_res(self, interval_time, total_time, set_max,
all_total_commits, all_interval_commits, do_sample, do_sample_lock):
min_latency = g_max_latency
max_latency = g_max_latency
latencies_size = len(self.last_latencies)
interval_latencies = [g_max_latency for x in g_att_latencies_percentage]
interval_attempt_latencies = [g_max_latency for x in g_att_latencies_percentage]
int_n_try = [g_max_try for x in g_n_try_percentage]
interval_tps = int(round((self.commit_txn - self.pre_commit_txn) / interval_time))
interval_commits = self.commit_txn - self.pre_commit_txn
if all_total_commits > 0:
total_ret = [str(round(self.commit_txn * 100.0 / all_total_commits, 2)) + "%", self.txn_name, self.start_txn, self.total_txn, self.total_try, self.commit_txn, int(round(self.commit_txn / total_time))]
else:
total_ret = ["----", self.txn_name, self.start_txn, self.total_txn, self.total_try, self.commit_txn, int(round(self.commit_txn / total_time))]
if all_interval_commits > 0:
interval_ret = [str(round(interval_commits * 100.0 / all_interval_commits, 2)) + "%", self.txn_name, self.start_txn - self.pre_start_txn, self.total_txn - self.pre_total_txn, self.total_try - self.pre_total_try, interval_commits, interval_tps, min_latency, max_latency]
else:
interval_ret = ["----", self.txn_name, self.start_txn - self.pre_start_txn, self.total_txn - self.pre_total_txn, self.total_try - self.pre_total_try, interval_commits, interval_tps, min_latency, max_latency]
interval_ret.extend(interval_latencies)
interval_ret.extend(interval_attempt_latencies)
interval_ret.extend(int_n_try)
ret = [total_ret, interval_ret]
if (self.update_latency):
self.update_latency = False
ul_index = 9
while ul_index < len(ret[1]):
self.max_data[ul_index] = ret[1][ul_index]
ul_index += 1
if (set_max):
if (len(self.max_data) == 0 or self.max_data[6] < interval_tps):
self.max_data = ret[1]
self.max_interval = interval_time
self.update_latency = True
self.last_interval_start = self.start_txn - self.pre_start_txn
self.pre_start_txn = self.start_txn
self.pre_total_txn = self.total_txn
self.pre_total_try = self.total_try
self.pre_commit_txn = self.commit_txn
self.this_latencies = []
return ret
def print_mid(self, config, num_clients):
start_txn = self.mid_start_txn - self.mid_pre_start_txn
total_txn = self.mid_total_txn - self.mid_pre_total_txn
tries = self.mid_total_try - self.mid_pre_total_try
commit_txn = self.mid_commit_txn - self.mid_pre_commit_txn
self.mid_time /= num_clients
tps = commit_txn / self.mid_time
logger.info("mid_commit_txn: {}".format(self.mid_commit_txn))
logger.info("mid_pre_commit_txn: {}".format(self.mid_pre_commit_txn))
logger.info("mid_time = {}".format(self.mid_time))
if self.mid_retry_exhausted > 0:
m = [max(self.mid_latencies)]
self.mid_all_latencies.extend(m * self.mid_retry_exhausted)
self.mid_latencies.sort()
self.mid_all_latencies.sort()
self.mid_attempt_latencies.sort()
self.mid_n_try.sort()
NO_VALUE = 999999.99
latencies = {}
all_latencies = {}
att_latencies = {}
for percent in g_latencies_percentage:
logger.info("percent: {}".format(percent))
percent = percent*100
key = str(percent)
if len(self.mid_latencies)>0:
index = int(math.ceil(percent/100*len(self.mid_latencies)))-1
latencies[key] = self.mid_latencies[index]
else:
latencies[key] = NO_VALUE
if len(self.mid_all_latencies)>0:
index = int(math.ceil(percent/100*len(self.mid_all_latencies)))-1
all_latencies[key] = self.mid_all_latencies[index]
else:
all_latencies[key] = NO_VALUE
if len(self.mid_attempt_latencies)>0:
att_index = int(math.ceil(percent/100*len(self.mid_attempt_latencies)))-1
att_latencies[key] = self.mid_attempt_latencies[att_index]
else:
att_latencies[key] = NO_VALUE
num_clients = sum([len(x)
for x in config['site']['client']]) * \
config["n_concurrent"]
zipf = -1
if 'coefficient' in config['bench']:
zipf = config['bench']['coefficient']
self.data = {
'benchmark': config['bench']['workload'],
'cc': config['mode']['cc'],
'ab': config['mode']['ab'],
'clients': num_clients,
'duration': self.mid_time,
'txn_name': self.txn_name,
'start_cnt': start_txn,
'total_cnt': total_txn,
'attempts': tries,
'commits': commit_txn,
'tps': tps,
'zipf': zipf,
'experiment_id': int(config['args'].experiment_id),
'retries_exhausted_cnt': self.mid_retry_exhausted
}
self.data['latency'] = {}
self.data['latency'].update(latencies)
if len(self.mid_latencies)>0:
self.data['latency']['min'] = self.mid_latencies[0]
self.data['latency']['max'] = self.mid_latencies[len(self.mid_latencies)-1]
else:
self.data['latency']['min'] = NO_VALUE
self.data['latency']['max'] = NO_VALUE
self.data['all_latency'] = {}
self.data['all_latency'].update(all_latencies)
if len(self.mid_all_latencies)>0:
self.data['all_latency']['min'] = self.mid_all_latencies[0]
self.data['all_latency']['max'] = self.mid_all_latencies[len(self.mid_all_latencies)-1]
else:
self.data['all_latency']['min'] = NO_VALUE
self.data['all_latency']['max'] = NO_VALUE
self.data['att_latency'] = {}
self.data['att_latency'].update(att_latencies)
if len(self.mid_latencies)>0:
self.data['att_latency']['min'] = self.mid_attempt_latencies[0]
self.data['att_latency']['max'] = self.mid_attempt_latencies[
len(self.mid_attempt_latencies)-1
]
else:
self.data['att_latency']['min'] = NO_VALUE
self.data['att_latency']['max'] = NO_VALUE
logger.info("\n__Data__\n{}\n__EndData__\n".format(yaml.dump(self.data)))
def print_max(self):
latency_str = ""
i = 0
for l_str in g_latencies_header:
latency_str += "; " + l_str + ": " + str(self.max_data[9 + i])
i += 1
i = 0
latency_size = len(g_latencies_header)
for l_str in g_att_latencies_header:
latency_str += "; " + l_str + ": " + str(self.max_data[9 + latency_size + i])
i += 1
n_tried_str = ""
i = 0
att_latency_size = len(g_att_latencies_header)
for l_str in g_n_try_header:
n_tried_str += "; " + l_str + ": " + str(self.max_data[9 + latency_size + att_latency_size + i])
i += 1
logger.info("RECORDING_RESULT: TXN: <" + str(self.max_data[1]) + ">; STARTED_TXNS: " + str(self.max_data[2]) + "; FINISHED_TXNS: " + str(self.max_data[3]) + "; ATTEMPTS: " + str(self.max_data[4]) + "; COMMITS: " + str(self.max_data[5]) + "; TPS: " + str(self.max_data[6]) + latency_str + "; TIME: " + str(self.max_interval) + "; LATENCY MIN: " + str(self.max_data[7]) + "; LATENCY MAX: " + str(self.max_data[8]) + n_tried_str)
class ClientController(object):
def __init__(self, config, process_infos):
self.config = config
self.process_infos = process_infos
self.benchmark = config['bench']['workload']
self.timeout = config['args'].c_timeout
self.duration = config['args'].c_duration
self.taskset = config['args'].c_taskset
self.log_dir = config['args'].log_dir
self.interest_txn = config['args'].interest_txn
self.recording_path = config['args'].recording_path
self.max_data = list()
self.finish_set = set()
self.txn_infos = dict()
self.rpc_proxy = dict()
self.txn_names = dict()
self.machine_n_cores = dict()
self.start_time = 0
self.pre_start_txn = 0
self.start_txn = 0
self.pre_total_txn = 0
self.total_txn = 0
self.pre_total_try = 0
self.total_try = 0
self.pre_commit_txn = 0
self.commit_txn = 0
self.run_sec = 0
self.pre_run_sec = 0
self.run_nsec = 0
self.pre_run_nsec = 0
self.n_asking = 0
self.max_tps = 0
self.recording_period = False
self.print_max = False
def client_run(self, do_sample, do_sample_lock):
sites = ProcessInfo.get_sites(self.process_infos,
SiteInfo.SiteType.Client)
for site in sites:
site.connect_rpc(30)
logger.info("Connected to client site %s @ %s", site.name, site.process.host_address)
barriers = []
for site in sites:
barriers.append(site.process.client_rpc_proxy.async_client_ready_block())
for barrier in barriers:
barrier.wait()
logger.info("Clients all ready")
res = sites[0].process.client_rpc_proxy.sync_client_get_txn_names()
for k, v in res.items():
logger.debug("txn: %s - %s", v, k)
self.txn_names[k] = v
self.start_client()
logger.info("Clients started")
start = time.time()
try:
self.benchmark_record(do_sample, do_sample_lock)
finally:
logger.info("Duration: {:.2f} seconds".format(time.time() - start))
logger.info("Benchmark finished")
def start_client(self):
sites = ProcessInfo.get_sites(self.process_infos,
SiteInfo.SiteType.Client)
client_rpc = set()
for site in sites:
client_rpc.add(site.process.client_rpc_proxy)
futures = []
for rpc_proxy in client_rpc:
futures.append(rpc_proxy.async_client_start())
for future in futures:
future.wait()
logger.info("client start send successfully.")
self.start_time = time.time()
def benchmark_record(self, do_sample, do_sample_lock):
logger.debug("in benchmark_record")
sites = ProcessInfo.get_sites(self.process_infos,
SiteInfo.SiteType.Client)
rpc_proxy = set()
for site in sites:
rpc_proxy.add(site.process.client_rpc_proxy)
rpc_proxy = list(rpc_proxy)
logger.info("contact {} client rpc proxies".format(len(rpc_proxy)))
self.num_proxies = len(rpc_proxy)
while (len(rpc_proxy) != len(self.finish_set)):
logger.debug("top client heartbeat; timeout {}".format(self.timeout))
for k in self.txn_infos.keys():
self.txn_infos[k].clear()
self.start_txn = 0
self.total_txn = 0
self.total_try = 0
self.commit_txn = 0
self.run_sec = 0
self.run_nsec = 0
futures = []
for proxy in rpc_proxy:
try:
future = proxy.async_client_response()
futures.append(future)
except:
logger.error(traceback.format_exc())
i=0
for future in futures:
res = future.result
period_time = res.period_sec + res.period_nsec / ONE_BILLION
for txn_type in res.txn_info.keys():
if txn_type not in self.txn_infos:
self.txn_infos[txn_type] = TxnInfo(txn_type, self.txn_names[txn_type], self.txn_names[txn_type] == self.interest_txn)
self.start_txn += res.txn_info[txn_type].start_txn
self.total_txn += res.txn_info[txn_type].total_txn
self.total_try += res.txn_info[txn_type].total_try
self.commit_txn += res.txn_info[txn_type].commit_txn
#print("num_exhausted: ", res.txn_info[txn_type].num_exhausted)
#print("num lat: ", len(res.txn_info[txn_type].attempt_latency))
self.txn_infos[txn_type].push_res(
res.txn_info[txn_type].start_txn,
res.txn_info[txn_type].total_txn,
res.txn_info[txn_type].total_try,
res.txn_info[txn_type].commit_txn,
res.txn_info[txn_type].this_latency,
res.txn_info[txn_type].last_latency,
res.txn_info[txn_type].interval_latency,
res.txn_info[txn_type].attempt_latency,
period_time,
res.txn_info[txn_type].num_try,
res.txn_info[txn_type].num_exhausted)
logger.debug("timing from server: run_sec {:.2f}; run_nsec {:.2f}".format(res.run_sec, res.run_nsec))
self.run_sec += res.run_sec
self.run_nsec += res.run_nsec
self.n_asking += res.n_asking
if (res.is_finish == 1):
self.finish_set.add(i)
i += 1
if len(futures) == 0:
logger.fatal("client control rpc futures length 0")
sys.exit(1)
self.run_sec /= len(futures)
self.run_nsec /= len(futures)
logger.debug("avg timing from {} servers: run_sec {:.2f}; run_nsec {:.2f}".format(len(futures), res.run_sec, res.run_nsec))
self.cur_time = time.time()
need_break = self.print_stage_result(do_sample, do_sample_lock)
if (need_break):
break
else:
time.sleep(self.timeout)
def print_stage_result(self, do_sample, do_sample_lock):
sites = ProcessInfo.get_sites(self.process_infos,
SiteInfo.SiteType.Client)
interval_time = (self.run_sec - self.pre_run_sec) + \
((self.run_nsec - self.pre_run_nsec) / ONE_BILLION)
total_time = (self.run_sec + self.run_nsec / ONE_BILLION)
progress = int(round(100 * total_time / self.duration))
logger.info("Progress: {}".format(progress))
#if (self.print_max):
# self.print_max = False
# for k, v in self.txn_infos.items():
# #v.print_max()
# v.print_mid(self.config, self.num_proxies)
lower_cutoff_pct = 25
upper_cutoff_pct = 75
if (not self.recording_period):
if (progress >= lower_cutoff_pct and progress <= upper_cutoff_pct):
logger.info("start recording period")
self.recording_period = True
do_sample_lock.acquire()
do_sample.value = 1
do_sample_lock.release()
for k, v in self.txn_infos.items():
v.set_mid_status()
else:
if (progress >= upper_cutoff_pct):
logger.info("done with recording period")
self.recording_period = False
for k, v in self.txn_infos.items():
v.print_mid(self.config, self.num_proxies)
do_sample_lock.acquire()
do_sample.value = 1
do_sample_lock.release()
for k, v in self.txn_infos.items():
v.set_mid_status()
output_str = "\nProgress: " + str(progress) + "%\n"
total_table = []
interval_table = []
interval_commits = self.commit_txn - self.pre_commit_txn
for txn_type in self.txn_infos.keys():
rows = self.txn_infos[txn_type].get_res(interval_time, total_time, self.recording_period, self.commit_txn, interval_commits, do_sample, do_sample_lock)
total_table.append(rows[0])
interval_table.append(rows[1])
logger.info("total_time: {}".format(total_time))
total_table.append(["----", "Total", self.start_txn, self.total_txn, self.total_try, self.commit_txn, int(round(self.commit_txn / total_time))])
interval_total_row = ["----", "Total", self.start_txn - self.pre_start_txn, self.total_txn - self.pre_total_txn, self.total_try - self.pre_total_try, interval_commits, int(round((self.commit_txn - self.pre_commit_txn) / interval_time))]
interval_total_row.extend([0.0 for x in g_latencies_header])
interval_total_row.extend([0.0 for x in g_att_latencies_header])
interval_table.append(interval_total_row)
total_header = ["RATIO", "NAME", "start", "finish", "attempts", "commits", "TPS"]
interval_header = ["RATIO", "NAME", "start", "finish", "attempts", "commits", "TPS", "min lt", "max lt"]
interval_header.extend(g_latencies_header)
interval_header.extend(g_att_latencies_header)
interval_header.extend(g_n_try_header)
output_str += "TOTAL: elapsed time: " + str(round(total_time, 2)) + "\n"
output_str += tabulate(total_table, headers=total_header) + "\n\n"
output_str += "INTERVAL: elapsed time: " + str(round(interval_time, 2)) + "\n"
output_str += tabulate(interval_table, headers=interval_header) + "\n"
output_str += "\tTotal asking finish: " + str(self.n_asking) + "\n"
output_str += "----------------------------------------------------------------------\n"
logger.info(output_str)
self.pre_start_txn = self.start_txn
self.pre_total_txn = self.total_txn
self.pre_total_try = self.total_try
self.pre_commit_txn = self.commit_txn
self.pre_run_sec = self.run_sec
self.pre_run_nsec = self.run_nsec
if (self.cur_time - self.start_time > 1.5 * self.duration):
#if (self.print_max):
# self.print_max = False
# for k, v in self.txn_infos.items():
# v.print_mid(self.config, self.num_proxies)
return True
else:
return False
def client_kill(self):
logger.info("killing clients ...")
sites = ProcessInfo.get_sites(self.process_infos, SiteInfo.SiteType.Client)
hosts = { s.process.host_address for s in sites }
ps.killall(hosts, "deptran_server", "-9")
def client_shutdown(self):
logger.debug("Shutting down clients ...")
sites = ProcessInfo.get_sites(self.process_infos, SiteInfo.SiteType.Client)
for site in self.sites:
try:
site.rpc_proxy.sync_client_shutdown()
except:
logger.error(traceback.format_exc())
class ServerResponse(object):
def __init__(self, value_times_pair):
self.value = value_times_pair.value
self.times = value_times_pair.times
def add_one(self, value_times_pair):
self.value += value_times_pair.value
self.times += value_times_pair.times
def get_value(self):
return self.value
def get_times(self):
return self.times
def get_ave(self):
if self.times == 0:
return 0.0
else:
return 1.0 * self.value / self.times
class ServerController(object):
def __init__(self, config, process_infos):
self.config = config
self.timeout = config['args'].s_timeout
self.log_dir = config['args'].log_dir
taskset = config['args'].s_taskset
self.recording_path = config['args'].recording_path
self.process_infos = process_infos
self.rpc_proxy = dict()
self.server_kill()
if (taskset == 1):
# set task on CPU 1
self.taskset_func = lambda x: "taskset -c " + str(2 * x + 16)
logger.info("Setting servers on CPU 1")
elif (taskset == 2):
# set task on CPU 0, odd number cores, no overlapping with irq cores
self.taskset_func = lambda x: "taskset -c " + str(2 * x + 1)
logger.info("Setting servers on CPU 0, odd number cores")
elif (taskset == 3):
# set task on CPU 0, even number cores, overlapping with irq cores
self.taskset_func = lambda x: "taskset -c " + str(2 * x)
logger.info("Setting servers on CPU 0, even number cores")
else:
self.taskset_func = lambda x: ""
logger.info("No taskset, auto scheduling")
self.pre_statistics = dict()
self.pre_time = time.time()
def server_kill(self):
hosts = { pi.host_address for pi in self.process_infos.itervalues() }
ps_output = ps.ps(hosts, "deptran_server")
logger.debug("Existing Server or Client Processes:\n{}".format(ps_output))
ps.killall(hosts, "deptran_server", "-9")
ps_output = ps.ps(hosts, "deptran_server")
logger.debug("Existing Server or Client After Kill:\n{}".format(ps_output))
def setup_heartbeat(self, client_controller):
logger.debug("in setup_heartbeat")
cond = multiprocessing.Condition()
s_init_finish = Value('i', 0)
do_sample = Value('i', 0)
do_sample_lock = Lock()
server_process = multiprocessing.Process(
target=self.server_heart_beat,
args=(cond, s_init_finish, do_sample, do_sample_lock))
server_process.daemon = False
server_process.start()
logger.info("Waiting for server init ...")
cond.acquire()
while (s_init_finish.value == 0):
cond.wait()
if s_init_finish.value == 5:
logger.error("Waiting for server init ... FAIL")
raise RuntimeError("server init failed.")
cond.release()
logger.info("Waiting for server init ... Done")
# let all clients start running the benchmark
client_controller.client_run(do_sample, do_sample_lock)
cond.acquire()
s_init_finish.value = 0
cond.release()
return server_process
def shutdown_sites(self, sites):
for site in sites:
try:
site.rpc_proxy.sync_server_shutdown()
except:
logger.error(traceback.format_exc())
def server_heart_beat(self, cond, s_init_finish, do_sample, do_sample_lock):
logger.debug("in server_heart_beat")
sites = []
try:
sites = ProcessInfo.get_sites(self.process_infos,
SiteInfo.SiteType.Server)
for site in sites:
site.connect_rpc(300)
logger.info("Connected to site %s @ %s", site.name, site.process.host_address)
for site in sites:
logger.info("call sync_server_ready on site {}".format(site.id))
while (site.rpc_proxy.sync_server_ready() != 1):
time.sleep(1) # waiting for server to initialize
logger.info("site %s ready", site.name)
cond.acquire()
s_init_finish.value = 1
cond.notify()
cond.release()
avg_r_cnt = 0.0
avg_r_sz = 0.0
avg_cpu_util = 0.0
sample_result = []
while (True):
logger.debug("top server heartbeat loop")
do_statistics = False
do_sample_lock.acquire()
if do_sample.value == 1:
do_statistics = True
do_sample.value = 0
do_sample_lock.release()
i = 0
r_cnt_sum = 0
r_cnt_num = 0
r_sz_sum = 0
r_sz_num = 0
statistics = dict()
cpu_util = [0.0] * len(sites)
futures = []
try:
for site in sites:
logger.debug("ping %s", site.name)
if do_statistics:
futures.append(site.rpc_proxy.async_server_heart_beat_with_data())
else:
futures.append(site.rpc_proxy.async_server_heart_beat())
except:
logger.fatal("server heart beat failure")
break
i = 0
while (i < len(futures)):
if do_statistics:
ret = futures[i].result
r_cnt_sum += ret.r_cnt_sum
r_cnt_num += ret.r_cnt_num
r_sz_sum += ret.r_sz_sum
r_sz_num += ret.r_sz_num
cpu_util[i] = ret.cpu_util
logger.info("CPU {}: {}".format(i, ret.cpu_util))
for k, v in ret.statistics.items():
if k not in statistics:
statistics[k] = ServerResponse(v)
else:
statistics[k].add_one(v)
else:
futures[i].wait()
i += 1
if do_statistics:
total_result = []
interval_result = []
cur_time = time.time()
interval_time = cur_time - self.pre_time
self.pre_time = cur_time
for k, v in statistics.items():
total_result.append([k, v.get_value(), v.get_times(), v.get_ave()])
interval_result.append([k, v.get_value(), v.get_times(), v.get_ave(), interval_time])
self.pre_statistics = statistics
sample_result = interval_result
avg_cpu_util = sum(cpu_util) / len(cpu_util)
if r_cnt_num != 0:
avg_r_cnt = (1.0 * r_cnt_sum) / r_cnt_num
else:
avg_r_cnt = -1.0
if r_sz_num != 0:
avg_r_sz = (1.0 * r_sz_sum) / r_sz_num
else:
avg_r_sz = -1.0
cond.acquire()
if (s_init_finish.value == 0):
cond.release()
break
cond.release()
time.sleep(self.timeout / 4)
for single_record in sample_result:
logger.info("SERVREC: %s; " + str(single_record[0]) + ": VALUE: " +
\
str(single_record[1]) + "; TIMES: " + \
str(single_record[2]) + "; MEAN: " + \
str(single_record[3]) + "; TIME: " + \
str(single_record[4]))
logger.info("CPUINFO: " + str(avg_cpu_util))
logger.info("AVG_LOG_FLUSH_CNT: " + str(avg_r_cnt))
logger.info("AVG_LOG_FLUSH_SZ: " + str(avg_r_sz))
logger.info("BENCHMARK SUCCESS!")
except:
logger.error(traceback.format_exc())
cond.acquire()
s_init_finish.value = 5
cond.notify()
cond.release()
def gen_process_cmd(self, process, host_process_counts):
cmd = []
cmd.append("cd " + deptran_home + "; ")
cmd.append("mkdir -p " + self.log_dir + "; ")
if (len(self.recording_path) != 0):
recording = " -r '" + self.recording_path + "/deptran_server_" + process.name + "' "
cmd.append("mkdir -p " + self.recording_path + "; ")
else:
recording = ""
s = "nohup " + self.taskset_func(host_process_counts[process.host_address]) + \
" ./build/deptran_server " + \
"-b " + \
"-d " + str(self.config['args'].c_duration) + " "
for fn in self.config['args'].config_files:
s += "-f '" + fn + "' "
s += "-P '" + process.name + "' " + \
"-p " + str(self.config['args'].rpc_port + process.id) + " " \
"-t " + str(self.config['args'].s_timeout) + " " \
"-r '" + self.config['args'].log_dir + "' " + \
recording + \
"1>'" + self.log_dir + "/proc-" + process.name + ".log' " + \
"2>'" + self.log_dir + "/proc-" + process.name + ".err' " + \
"&"
host_process_counts[process.host_address] += 1
cmd.append(s)
return ' '.join(cmd)
def start(self):
# this current starts all the processes
# todo: separate this into a class that starts and stops deptran
host_process_counts = { host_address: 0 for host_address in self.config['host'].itervalues() }
def run_one_server(process, process_name, host_process_counts):
logger.info("starting %s @ %s", process_name, process.host_address)
cmd = self.gen_process_cmd(process, host_process_counts)
logger.debug("running: %s", cmd)
subprocess.call(['ssh', '-f',process.host_address, cmd])
logger.debug(self.process_infos)
t_list = []
for process_name, process in self.process_infos.iteritems():
t = Thread(target=run_one_server,
args=(process, process_name, host_process_counts,))
t.start()
t_list.append(t)
for t in t_list:
t.join()
def create_parser():
parser = ArgumentParser()
parser.add_argument('-n', "--name", dest="experiment_name",
help="name of experiment",
default=None)
parser.add_argument('-id', dest="experiment_id", default="-1")
parser.add_argument("-f", "--file", dest="config_files",
help="read config from FILE, default is sample.yml",
action='append',
default=[], metavar="FILE")
parser.add_argument("-P", "--port", dest="rpc_port", help="port to use",
default=5555, metavar="PORT")
parser.add_argument("-t", "--server-timeout", dest="s_timeout",
help="server heart beat timeout in seconds", default=10,
action="store", metavar="TIMEOUT", type=int)
parser.add_argument("-i", "--status-time-interval", dest="c_timeout",
help="time interval to report benchmark status in seconds",
default=5, action="store", metavar="TIME", type=int)
parser.add_argument("-w", "--wait", dest="wait",
help="wait after starting processes",
default=False, action="store_true")
parser.add_argument("-d", "--duration", dest="c_duration",
help="benchmark running duration in seconds", default=60,
action="store", metavar="TIME", type=int)
parser.add_argument("-S", "--single-server", dest="c_single_server",
help="control each client always touch the same server "
"0, disabled; 1, each thread will touch a single server; "
"2, each process will touch a single server",
default=0, action="store", metavar="[0|1|2]")
parser.add_argument("-T", "--taskset-schema", dest="s_taskset",
help="Choose which core to run each server on. "
"0: auto; "
"1: CPU 1; "
"2: CPU 0, odd cores; "
"3: CPU 0, even cores;",
default=0, action="store", metavar="[0|1|2|3]")
parser.add_argument("-c", "--client-taskset", dest="c_taskset",
help="taskset client processes round robin", default=False,
action="store_true")
parser.add_argument("-l", "--log-dir", dest="log_dir",
help="Log file directory", default=g_log_dir,
metavar="LOG_DIR")
parser.add_argument("-r", "--recording-path", dest="recording_path",
help="Recording path", default="", metavar="RECORDING_PATH")
parser.add_argument("-x", "--interest-txn", dest="interest_txn",
help="interest txn", default=g_interest_txn,
metavar="INTEREST_TXN")
parser.add_argument("-H", "--hosts", dest="hosts_path",
help="hosts path", default="./config/hosts-local",
metavar="HOSTS_PATH")
logger.debug(parser)
return parser
class TrialConfig:
def __init__(self, options):
self.s_timeout = int(options.s_timeout)
self.c_timeout = int(options.c_timeout)
self.c_duration = int(options.c_duration)
self.c_single_server = int(options.c_single_server)
self.s_taskset = int(options.s_taskset)
self.c_taskset = options.c_taskset
self.config_path = os.path.realpath(options.config_path)
self.hosts_path = os.path.realpath(options.hosts_path)
self.recording_path = os.path.realpath(options.recording_path)
self.log_path = os.path.realpath(options.log_dir)
self.c_interest_txn = str(options.interest_txn)
self.rpc_port = int(options.rpc_port)
pass
def check_correctness(self):
if self.c_single_server not in [0, 1, 2]:
logger.error("Invalid single server argument.")
return False
if not os.path.exists(self.config_path):
logger.error("Config path incorrect.")
return False
if not os.path.exists(self.hosts_path):
logger.error("Hosts path incorrect.")
return False
return True
class SiteInfo:
class SiteType:
Client = 1
Server = 2
CTRL_PORT_DELTA = 10000
id = -1
@staticmethod
def next_id():
SiteInfo.id += 1
return SiteInfo.id
def __init__(self, process, site_name, site_type, port):
self.id = SiteInfo.next_id()
self.process = process
self.name = site_name
if type(site_type) == str:
if site_type == 'client':
self.site_type = SiteInfo.SiteType.Client
else:
self.site_type = SiteInfo.SiteType.Server
else:
self.site_type = site_type
if site_type == 'client':
self.port = int(port)
self.rpc_port = int(port)
elif port is not None:
self.port = int(port)
self.rpc_port = self.port + self.CTRL_PORT_DELTA
else: