-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgen_workload.py
174 lines (144 loc) · 5.1 KB
/
gen_workload.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
import sys
import os
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
#####################################################################################
def reverseHostName ( email ) :
name, sep, host = email.partition('@')
hostparts = host[:-1].split('.')
r_host = ''
for part in hostparts :
r_host = part + '.' + r_host
return r_host + sep + name
#####################################################################################
if (len(sys.argv) != 2) :
print bcolors.WARNING + 'Usage:'
print 'workload file' + bcolors.ENDC
config_file = sys.argv[1]
args = []
f_config = open (config_file, 'r')
for line in f_config :
args.append(line[:-1])
ycsb_dir = 'YCSB/'
workload_dir = 'workload_spec/'
output_dir='workloads/'
workload = args[0]
key_type = args[1]
print bcolors.OKGREEN + 'workload = ' + workload
print 'key type = ' + key_type + bcolors.ENDC
email_list = 'list.txt'
email_list_size = 27245616
out_ycsb_load = output_dir + 'ycsb_load_' + key_type + '_' + workload
out_ycsb_txn = output_dir + 'ycsb_txn_' + key_type + '_' + workload
out_load_ycsbkey = output_dir + 'load_' + 'ycsbkey' + '_' + workload
out_txn_ycsbkey = output_dir + 'txn_' + 'ycsbkey' + '_' + workload
out_load = output_dir + 'load_' + key_type + '_' + workload
out_txn = output_dir + 'txn_' + key_type + '_' + workload
cmd_ycsb_load = ycsb_dir + 'bin/ycsb load basic -P ' + workload_dir + workload + ' -s > ' + out_ycsb_load
cmd_ycsb_txn = ycsb_dir + 'bin/ycsb run basic -P ' + workload_dir + workload + ' -s > ' + out_ycsb_txn
os.system(cmd_ycsb_load)
os.system(cmd_ycsb_txn)
#####################################################################################
f_load = open (out_ycsb_load, 'r')
f_load_out = open (out_load_ycsbkey, 'w')
for line in f_load :
cols = line.split()
if len(cols) > 0 and cols[0] == "INSERT":
f_load_out.write (cols[0] + " " + cols[2][4:] + "\n")
f_load.close()
f_load_out.close()
f_txn = open (out_ycsb_txn, 'r')
f_txn_out = open (out_txn_ycsbkey, 'w')
for line in f_txn :
cols = line.split()
if (cols[0] == 'SCAN') or (cols[0] == 'INSERT') or (cols[0] == 'READ') or (cols[0] == 'UPDATE'):
startkey = cols[2][4:]
if cols[0] == 'SCAN' :
numkeys = cols[3]
f_txn_out.write (cols[0] + ' ' + startkey + ' ' + numkeys + '\n')
else :
f_txn_out.write (cols[0] + ' ' + startkey + '\n')
f_txn.close()
f_txn_out.close()
cmd = 'rm -f ' + out_ycsb_load
os.system(cmd)
cmd = 'rm -f ' + out_ycsb_txn
os.system(cmd)
#####################################################################################
if key_type == 'randint' :
f_load = open (out_load_ycsbkey, 'r')
f_load_out = open (out_load, 'w')
for line in f_load :
f_load_out.write (line)
f_txn = open (out_txn_ycsbkey, 'r')
f_txn_out = open (out_txn, 'w')
for line in f_txn :
f_txn_out.write (line)
elif key_type == 'monoint' :
keymap = {}
f_load = open (out_load_ycsbkey, 'r')
f_load_out = open (out_load, 'w')
count = 0
for line in f_load :
cols = line.split()
keymap[int(cols[1])] = count
f_load_out.write (cols[0] + ' ' + str(count) + '\n')
count += 1
f_txn = open (out_txn_ycsbkey, 'r')
f_txn_out = open (out_txn, 'w')
for line in f_txn :
cols = line.split()
if cols[0] == 'SCAN' :
f_txn_out.write (cols[0] + ' ' + str(keymap[int(cols[1])]) + ' ' + cols[2] + '\n')
elif cols[0] == 'INSERT' :
keymap[int(cols[1])] = count
f_txn_out.write (cols[0] + ' ' + str(count) + '\n')
count += 1
else :
f_txn_out.write (cols[0] + ' ' + str(keymap[int(cols[1])]) + '\n')
elif key_type == 'email' :
keymap = {}
f_email = open (email_list, 'r')
emails = f_email.readlines()
f_load = open (out_load_ycsbkey, 'r')
f_load_out = open (out_load, 'w')
sample_size = len(f_load.readlines())
gap = email_list_size / sample_size
f_load.close()
f_load = open (out_load_ycsbkey, 'r')
count = 0
for line in f_load :
cols = line.split()
email = reverseHostName(emails[count * gap])
keymap[int(cols[1])] = email
f_load_out.write (cols[0] + ' ' + email + '\n')
count += 1
count = 0
f_txn = open (out_txn_ycsbkey, 'r')
f_txn_out = open (out_txn, 'w')
for line in f_txn :
cols = line.split()
if cols[0] == 'SCAN' :
f_txn_out.write (cols[0] + ' ' + keymap[int(cols[1])] + ' ' + cols[2] + '\n')
elif cols[0] == 'INSERT' :
email = reverseHostName(emails[count * gap + 1])
keymap[int(cols[1])] = email
f_txn_out.write (cols[0] + ' ' + email + '\n')
count += 1
else :
f_txn_out.write (cols[0] + ' ' + keymap[int(cols[1])] + '\n')
f_load.close()
f_load_out.close()
f_txn.close()
f_txn_out.close()
cmd = 'rm -f ' + out_load_ycsbkey
os.system(cmd)
cmd = 'rm -f ' + out_txn_ycsbkey
os.system(cmd)