Repository navigation
Expand file tree
/
Copy pathutils.js
More file actions
130 lines (105 loc) · 2.62 KB
/
Copy pathutils.js
File metadata and controls
130 lines (105 loc) · 2.62 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
import { open } from 'k6/experimental/fs';
// See: https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/fs/file/read/#readall-helper-function
export async function readAll(path) {
const file = await open(path)
const fileInfo = await file.stat();
const buffer = new Uint8Array(fileInfo.size);
const bytesRead = await file.read(buffer);
if (bytesRead !== fileInfo.size) {
throw new Error(
'unexpected number of bytes read; expected ' +
fileInfo.size +
' but got ' +
bytesRead +
' bytes'
);
}
return buffer;
}
export function stagesBuild(trace, builder) {
switch (builder) {
case "OneMinuteWindow":
return stagesOneMinuteWindow(trace);
case "TwoMinuteWindow":
return stagesTwoMinuteWindow(trace);
case "ThreeMinuteWindow":
return stagesThreeMinuteWindow(trace);
case "WithCooldown":
return stagesWithCooldown(trace);
default:
throw new Error(`Unknown stage builder '${builder}'`);
}
}
export function stagesOneMinuteWindow(trace) {
let stages = [];
for (const rate of trace) {
const target = Math.round(rate);
stages.push({
duration: '5s', // 5-second transition to new rate.
target,
});
stages.push({
duration: '55s', // Keep a constant rate for the remainder of the minute.
target,
});
}
return stages;
}
export function stagesTwoMinuteWindow(trace) {
let stages = [];
for (const rate of trace) {
const target = Math.round(rate);
// Similar to stagesOneMinuteWindow() but with duration of 2 minutes.
stages.push({
duration: '10s',
target,
});
stages.push({
duration: '110s',
target,
});
}
return stages;
}
export function stagesThreeMinuteWindow(trace) {
let stages = [];
for (const rate of trace) {
const target = Math.round(rate);
// Similar to stagesOneMinuteWindow() but with duration of 3 minutes.
stages.push({
duration: '15s',
target,
});
stages.push({
duration: '165s',
target,
});
}
return stages;
}
export function stagesWithCooldown(trace) {
let stages = [];
for (const rate of trace) {
const target = Math.round(rate);
// Similar to stagesOneMinuteWindow(): an initial transition to new rate,
// then constant rate.
stages.push({
duration: '20s',
target,
});
stages.push({
duration: '160s',
target,
});
// Create a "cooldown" period to let the VM rest.
stages.push({
duration: '5s',
target: 0,
});
stages.push({
duration: '15s',
target: 0,
});
}
return stages;
}