-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulator.py
More file actions
139 lines (118 loc) · 3.61 KB
/
Copy pathsimulator.py
File metadata and controls
139 lines (118 loc) · 3.61 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
#!/bin/python
import argparse
import time
import ConfigParser
import numpy as np
import pickle
import json
import pprint as pp
import timeit as tt
import sys
from generator import Generator
from volley import Volley
from greedy import Greedy
from central_greedy import CentralizedGreedy
from distributed_greedy import DistributedGreedy
verbose = True
debug = True
start_time = 0
end_time = 0
def load_imap(imap):
r_imap = []
with open(imap) as imap:
for line in imap:
r_imap.append(line.strip())
return r_imap
def load_amap(amap):
r_amap = []
r_amaps = []
with open(amap,'rt') as amap:
r_amap = json.load(amap)
#amap.read()
#r_map = json.loads(json_data)
print "Read number of reqs: ", len(r_amap)
r_amaps.append(r_amap)
return r_amaps
def ConfigSectionMap(config, section):
dict1 = {}
options = config.options(section)
for option in options:
try:
dict1[option] = config.get(section, option)
if dict1[option] == -1:
DebugPrint("skip: %s" % option)
except:
print("exception on %s!" % option)
dict1[option] = None
return dict1
def create_amaps(amap,imap):
amaps = []
access_config = ConfigParser.ConfigParser()
access_config.read(amap)
sections = access_config.sections()
print len(sections)
#FIXME: automate for different sections
workload_generator = Generator(imap)
for section in sections:
section_options = ConfigSectionMap(access_config, section)
sd = section_options['spatial_distribution']
sf = section_options['spatial_factor']
td = section_options['temporal_distribution']
tf = section_options['temporal_factor']
zd = section_options['size_distribution']
zf = section_options['size_factor']
dd = section_options['dependency_distribution']
df = section_options['dependency_factor']
rd = section_options['redundancy_distribution']
rf = section_options['redundancy_factor']
r_amap = workload_generator.generate_amap(sd,sf,td,tf,zd,zf,dd,df,rd,rf)
amaps.append(r_amap)
return amaps
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('--algo', choices=['volley', 'greedy', 'cgreedy', 'distributed', 'castnet'], help='the algorithm used for replication', required=True)
parser.add_argument('--imap', help='File containing imap', required=True)
parser.add_argument('--amap', help='File containing amap or amap conf params', required=True)
args = vars(parser.parse_args())
return args
if __name__ == '__main__':
args = parse_args()
print args
import sys
sys.setrecursionlimit(10000)
imap = load_imap(args['imap'])
start_time = time.time()
if '.ini' in args['amap']:
amaps = create_amaps(args['amap'], imap)
count = 0
else:
amaps=load_amap(args['amap'])
print "Loaded amap !"
end_time = time.time()
print "WLGEN: ", end_time - start_time
exit()
for amap in amaps:
#print "Number of requests in amap: ", len(amap)
#print amap
algo = None
if args['algo'] == 'volley':
#print "Using Volley algorithm ..."
algo = Volley(imap, amap)
elif args['algo'] == 'greedy':
#print "using greedy algorithm ..."
algo = DistributedGreedy(imap, amap)
elif args['algo'] == 'cgreedy':
#print "using centralized greedy algorithm ..."
algo = CentralizedGreedy(imap, amap)
elif args['algo'] == 'distributed':
#print "using distributed algorithm ..."
algo = Distributed(imap, amap)
elif args['algo'] == 'castnet':
#print "Using castnet algorithm ..."
algo = Castnet(imap, amap, budget)
else:
print "Don't know how we reached here"
start_time = time.time()
algo.execute()
end_time = time.time()
print "EXE: ", (end_time - start_time)*1000