This repository has been archived by the owner on May 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
pipeline.py
71 lines (53 loc) · 2.01 KB
/
pipeline.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
from controller import read_metric, read_knob, set_knob, knob_set, init_knobs, load_workload, run_workload, calc_metric, restart_db
from gpmodel import configuration_recommendation
from datamodel import GPDataSet
from settings import tikv_ip, tikv_port, target_knob_set, target_metric_name, wl_metrics, wltype, loadtype
import numpy as np
import time
if __name__ == '__main__':
ds = GPDataSet()
Round=200
init_knobs()
metric_list=wl_metrics[wltype]
ds.initdataset(metric_list)
num_knobs = len(target_knob_set)
num_metrics = len(metric_list)
KEY = str(time.time())
while(Round>0):
print("################## start a new Round ##################")
rec = configuration_recommendation(ds)
knob_cache = {}
for x in rec.keys():
set_knob(x, rec[x])
knob_cache[x] = rec[x]
print("Round: ", Round, rec)
restart_db()
lres = load_workload(loadtype)
print(lres)
if("_ERROR" in lres):
print("load workload error")
exit()
new_knob_set = np.zeros([1, num_knobs])
new_metric_before = np.zeros([1, num_metrics])
new_metric_after = np.zeros([1, num_metrics])
for i,x in enumerate(metric_list):
new_metric_before[0][i] = read_metric(x)
for i,x in enumerate(target_knob_set):
new_knob_set[0][i] = read_knob(x, knob_cache)
rres = run_workload(wltype)
print(rres)
if("_ERROR" in rres):
print("run workload error")
exit()
for i,x in enumerate(metric_list):
new_metric_after[0][i] = read_metric(x, rres)
new_metric = calc_metric(new_metric_after, new_metric_before, metric_list)
#print(new_metric,metric_list)
ds.add_new_data(new_knob_set, new_metric)
import pickle
fp = "ds_"+KEY+"_"+str(Round)+"_.pkl"
with open(fp, "wb") as f:
pickle.dump(ds, f)
ds.printdata()
ds.merge_new_data()
Round-=1