This repository has been archived by the owner on Oct 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
77 lines (61 loc) · 2.62 KB
/
main.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
"""
Orchestrate the simulations and generate the figures presenting the results
"""
import argparse
import time
from pathlib import Path
import matplotlib.pyplot as plt
from numpy.random import SeedSequence, SFC64, Generator
import graphs
from parameters import Parameters
from simulations import mm1_simulation, map_ph_simulation
from stats import compute_print_stats
SEED_SEQUENCE = SeedSequence()
def main():
# Defining CLI Arguments
description = 'Simulate a proof-of-work blockchain system with a M/M/1 or MAP/PH/1 queue, with fees or not.'
parser = argparse.ArgumentParser(description=description)
parser.add_argument('parameters_dir', nargs='?', type=str, default='parameters',
help='path to directory containing the parameters (README for details)')
parser.add_argument('--seed', type=int, help='seed to initialize the pseudo random generator')
parser.add_argument('--mm1', action='store_true', help='run the simulation with M/M/1 queue')
parser.add_argument('--mapph1', action='store_true', help='run the simulation with MAP/PH/1 queue')
parser.add_argument('--fees', action='store_true',
help='Prioritize transactions according to offered fees (otherwise, random order)')
args = parser.parse_args()
# Parsing parameters from file system
p = Parameters.get_from(Path(args.parameters_dir))
# Initiating pseudo random generator
global SEED_SEQUENCE
if args.seed:
SEED_SEQUENCE = SeedSequence(args.seed)
print('Seed :', SEED_SEQUENCE.entropy)
generators = [Generator(SFC64(stream)) for stream in SEED_SEQUENCE.spawn(10)]
# Simulations
if args.mm1:
if args.fees:
print('M/M/1 with fees :')
else:
print('M/M/1 :')
start = time.perf_counter()
measures = mm1_simulation(generators, fees=args.fees, **p)
stats = compute_print_stats(**measures)
graphs.draw(**measures, **stats, queue_name='M/M/1')
print(f"Done after {time.perf_counter() - start:.0f}s")
if args.mapph1:
if args.fees:
print('MAP/PH/1 with fees :')
else:
print('MAP/PH/1 :')
start = time.perf_counter()
measures = map_ph_simulation(generators, fees=args.fees, **p)
stats = compute_print_stats(**measures)
graphs.draw(**measures, **stats, queue_name='MAP/PH/1')
print(f"Done after {time.perf_counter() - start:.0f}s")
if not (args.mm1 or args.mapph1):
parser.print_help()
exit("You didn't select any simulation to run.")
else:
plt.show()
if __name__ == '__main__':
main()