-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcost_analysis_sum_test.go
More file actions
229 lines (208 loc) · 7.55 KB
/
cost_analysis_sum_test.go
File metadata and controls
229 lines (208 loc) · 7.55 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
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
package promsketch
import (
"fmt"
"testing"
"time"
)
const R_value float64 = 1
func sum(values []float64) float64 {
var sum float64 = 0
for _, v := range values {
sum += v
}
return sum
}
func prometheus_sum(total_length int64, time_window_size int64, t1, t2 []int64, ground_truth *([][]float64)) (float64, float64, float64) {
input_values := make([]float64, 0)
insert_compute := 0.0
query_compute := 0.0
for t := int64(0); t < total_length; t++ {
start := time.Now()
input_values = append(input_values, cases[0].vec[t].F)
elapsed := time.Since(start)
insert_compute += float64(elapsed.Microseconds())
// evaluate scenarios
if t == total_length-1 {
for i := range len(t1) {
start_t := t1[i] + t - time_window_size + 1
end_t := t2[i] + t - time_window_size + 1
start = time.Now()
values := make([]float64, 0)
for t := start_t; t <= end_t; t++ {
values = append(values, cases[0].vec[t].F)
}
ans := sum(values)
elapsed = time.Since(start)
query_compute += float64(elapsed.Microseconds())
(*ground_truth)[t][i] = ans
}
} else {
if t >= time_window_size-1 && (t+1)%cost_query_interval == 0 {
for i := range len(t1) {
start_t := t1[i] + t - time_window_size + 1
end_t := t2[i] + t - time_window_size + 1
start = time.Now()
values := make([]float64, 0)
for t := start_t; t <= end_t; t++ {
values = append(values, cases[0].vec[t].F)
}
ans := sum(values)
elapsed = time.Since(start)
query_compute += float64(elapsed.Microseconds())
(*ground_truth)[t][i] = ans
}
}
}
}
return insert_compute, query_compute, float64(time_window_size) * 8 / 1024
}
func TestCostAnalysisSum(t *testing.T) {
readGoogleClusterData2009()
// readPowerDataset()
fmt.Println("Finished reading input timeseries")
query_window_size := int64(1000000)
total_length := int64(2000000)
// Create a scenario
// Query these subwindows every 1000 data sample insertions
t1 := make([]int64, 0)
t2 := make([]int64, 0)
t1 = append(t1, int64(0))
t2 = append(t2, query_window_size-1)
for i := 1; i <= 10; i++ {
t1 = append(t1, query_window_size/10*int64(i-1))
t2 = append(t2, query_window_size/10*int64(i)-1)
}
start_t := t1[len(t1)-1]
for i := 1; i <= 10; i++ {
t1 = append(t1, start_t+query_window_size/10/10*int64(i-1))
t2 = append(t2, start_t+query_window_size/10/10*int64(i)-1)
}
/*
start_t = t1[len(t1)-1]
for i := 1; i <= 10; i++ {
t1 = append(t1, start_t+query_window_size/10/10/10*int64(i-1))
t2 = append(t2, start_t+query_window_size/10/10/10*int64(i)-1)
}
*/
fmt.Println("t1:", t1)
fmt.Println("t2:", t2)
ground_truth := make([][]float64, total_length)
for t := 0; t < int(total_length); t++ {
ground_truth[t] = make([]float64, len(t1))
}
// Prometheus baseline
insert_compute, query_compute, memory := prometheus_sum(total_length, query_window_size, t1, t2, &ground_truth)
fmt.Println("Prometheus")
fmt.Println("insert compute:", insert_compute, "us")
fmt.Println("query compute:", query_compute, "us")
fmt.Println("total compute:", query_compute+insert_compute, "us")
fmt.Println("memory:", memory, "KB")
// Sampling baselines
sampling_rel_error := make([][]float64, 0)
sampling_rate := []float64{0.001, 0.01, 0.05, 0.1}
for i, rate := range sampling_rate {
fmt.Println("sampling", rate)
query_compute := 0.0
insert_compute := 0.0
sampling_rel_error = append(sampling_rel_error, make([]float64, 0))
sampling_size := int(float64(query_window_size) * rate)
sampling_instance := NewUniformSampling(query_window_size, rate, sampling_size)
for t := int64(0); t < total_length; t++ {
start := time.Now()
sampling_instance.Insert(t, cases[0].vec[t].F)
elapsed := time.Since(start)
insert_compute += float64(elapsed.Microseconds())
if t == total_length-1 {
for j := range len(t1) {
start_t := t1[j] + t - query_window_size + 1
end_t := t2[j] + t - query_window_size + 1
start := time.Now()
ans_sum := sampling_instance.QuerySum(start_t, end_t)
elapsed := time.Since(start)
query_compute += float64(elapsed.Microseconds())
rel_err := AbsFloat64(ground_truth[t][j]-ans_sum) / (ground_truth[t][j]) * 100
// rel_err := AbsFloat64(ground_truth[t][j]-ans_sum) / (R_value * float64(end_t-start_t+1))
sampling_rel_error[i] = append(sampling_rel_error[i], rel_err)
}
} else {
if t >= query_window_size-1 && (t+1)%cost_query_interval == 0 {
for j := range len(t1) {
start_t := t1[j] + t - query_window_size + 1
end_t := t2[j] + t - query_window_size + 1
start := time.Now()
ans_sum := sampling_instance.QuerySum(start_t, end_t)
elapsed := time.Since(start)
query_compute += float64(elapsed.Microseconds())
rel_err := AbsFloat64(ground_truth[t][j]-ans_sum) / (ground_truth[t][j]) * 100
// rel_err := AbsFloat64(ground_truth[t][j]-ans_sum) / (R_value * float64(end_t-start_t+1))
sampling_rel_error[i] = append(sampling_rel_error[i], rel_err)
}
}
}
}
fmt.Println("relative error:", sampling_rel_error[i])
fmt.Println("insert compute:", insert_compute, "us")
fmt.Println("query compute:", query_compute, "us")
fmt.Println("total compute:", query_compute+insert_compute, "us")
fmt.Println("memory:", sampling_instance.GetMemory(), "KB")
}
/*
// PromSketch, EfficientSum
epsilon_input := []float64{0.001, 0.0001, 0.00001, 0.000001}
for _, epsilon := range epsilon_input {
fmt.Println("effsum", epsilon)
effsum_rel_error := make([]float64, 0)
total_compute := 0.0
insert_compute := 0.0
effsum := NewEfficientSum(query_window_size, query_window_size, epsilon, R_value)
for t := int64(0); t < total_length; t++ {
start := time.Now()
effsum.Insert(t, cases[0].vec[t].F)
elapsed := time.Since(start)
insert_compute += float64(elapsed.Microseconds())
if t == total_length-1 {
for j := range len(t1) {
start_t := t1[j] + t - query_window_size + 1
end_t := t2[j] + t - query_window_size + 1
start := time.Now()
ans_sum := float64(0)
if j == 0 {
ans_sum = effsum.Query(start_t, end_t, false)
} else {
ans_sum = effsum.Query(start_t, end_t, true)
}
elapsed := time.Since(start)
total_compute += float64(elapsed.Microseconds())
rel_err := AbsFloat64(ground_truth[t][j]-ans_sum) / ground_truth[t][j] * 100
// rel_err := AbsFloat64(ground_truth[t][j]-ans_sum) / (R_value * float64(end_t-start_t+1))
effsum_rel_error = append(effsum_rel_error, rel_err)
}
} else {
if t >= query_window_size-1 && (t+1)%cost_query_interval == 0 {
for j := range len(t1) {
start_t := t1[j] + t - query_window_size + 1
end_t := t2[j] + t - query_window_size + 1
start := time.Now()
ans_sum := float64(0)
if j == 0 {
ans_sum = effsum.Query(start_t, end_t, false)
} else {
ans_sum = effsum.Query(start_t, end_t, true)
}
elapsed := time.Since(start)
total_compute += float64(elapsed.Microseconds())
rel_err := AbsFloat64(ground_truth[t][j]-ans_sum) / ground_truth[t][j] * 100
// rel_err := AbsFloat64(ground_truth[t][j]-ans_sum) / (R_value * float64(end_t-start_t+1)) // Additive error defined in the paper
effsum_rel_error = append(effsum_rel_error, rel_err)
}
}
}
}
fmt.Println("relative error:", effsum_rel_error)
fmt.Println("insert compute:", insert_compute)
fmt.Println("query compute:", total_compute, "us")
fmt.Println("total compute:", total_compute+insert_compute, "us")
fmt.Println("memory:", effsum.GetMemory(), "KB")
}
*/
}