Skip to content

Commit e721c77

Browse files
authored
Define second performance test scenario (#2403)
1 parent b0a0e3a commit e721c77

5 files changed

Lines changed: 188 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
module.exports = {
2+
main: async function (event, context) {
3+
const data = event.extensions.request.headers;
4+
width = data['width'];
5+
height = data['height'];
6+
iterations = data['iterations'];
7+
zoom = data['zoom'];
8+
9+
console.log(`Received request with width=${width}, height=${height}, iterations=${iterations}, zoom=${zoom}`);
10+
11+
return generateMandelbrotJson(width, height, iterations, zoom);
12+
}
13+
}
14+
15+
function generateMandelbrotJson(width, height, iterations, zoom) {
16+
const safeWidth = Number.parseInt(width);
17+
const safeHeight = Number.parseInt(height);
18+
const maxIterations = Number.parseInt(iterations);
19+
const safeZoom = Number.parseFloat(zoom);
20+
const values = [];
21+
22+
const xOffset = -0.7;
23+
const yOffset = 0;
24+
25+
for (let y = 0; y < safeHeight; y++) {
26+
const row = [];
27+
const ci = (y / safeHeight - 0.5) / safeZoom + yOffset;
28+
29+
for (let x = 0; x < safeWidth; x++) {
30+
const cr = (x / safeWidth - 0.5) / safeZoom + xOffset;
31+
row.push(mandelbrotEscapeIterations(cr, ci, maxIterations));
32+
}
33+
34+
values.push(row);
35+
}
36+
37+
return {
38+
type: "mandelbrot",
39+
width: safeWidth,
40+
height: safeHeight,
41+
maxIterations: maxIterations,
42+
zoom: safeZoom,
43+
values: values
44+
};
45+
}
46+
47+
function mandelbrotEscapeIterations(cr, ci, maxIterations) {
48+
let zr = 0;
49+
let zi = 0;
50+
let iter = 0;
51+
52+
while (iter < maxIterations && zr * zr + zi * zi < 4) {
53+
const nextZr = zr * zr - zi * zi + cr;
54+
zi = 2 * zr * zi + ci;
55+
zr = nextZr;
56+
iter++;
57+
}
58+
59+
return iter;
60+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import json
2+
3+
def main(event, context):
4+
data = event['extensions']['request'].headers
5+
width = data.get("width")
6+
height = data.get("height")
7+
iterations = data.get("iterations")
8+
zoom = data.get("zoom")
9+
10+
print(f"Received request with width={width}, height={height}, iterations={iterations}, zoom={zoom}")
11+
12+
return generate_mandelbrot_json(width, height, iterations, zoom)
13+
14+
15+
def generate_mandelbrot_json(width, height, iterations, zoom):
16+
safe_width = int(str(width).strip())
17+
safe_height = int(str(height).strip())
18+
max_iterations = int(str(iterations).strip())
19+
safe_zoom = float(str(zoom).strip())
20+
values = []
21+
22+
x_offset = -0.7
23+
y_offset = 0.0
24+
25+
for y in range(safe_height):
26+
row = []
27+
ci = (y / safe_height - 0.5) / safe_zoom + y_offset
28+
29+
for x in range(safe_width):
30+
cr = (x / safe_width - 0.5) / safe_zoom + x_offset
31+
row.append(mandelbrot_escape_iterations(cr, ci, max_iterations))
32+
33+
values.append(row)
34+
35+
return {
36+
"type": "mandelbrot",
37+
"width": safe_width,
38+
"height": safe_height,
39+
"maxIterations": max_iterations,
40+
"zoom": safe_zoom,
41+
"values": values,
42+
}
43+
44+
45+
def mandelbrot_escape_iterations(cr, ci, max_iterations):
46+
zr = 0.0
47+
zi = 0.0
48+
it = 0
49+
50+
while it < max_iterations and (zr * zr + zi * zi) < 4:
51+
next_zr = zr * zr - zi * zi + cr
52+
zi = 2 * zr * zi + ci
53+
zr = next_zr
54+
it += 1
55+
56+
return it
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import http from "k6/http";
2+
import { sleep } from 'k6';
3+
import exec from 'k6/execution';
4+
5+
export const options = {
6+
scenarios: {
7+
warmup: {
8+
executor: 'constant-vus',
9+
vus: 5,
10+
duration: '1m',
11+
gracefulStop: '0s',
12+
exec: 'call_function_then_sleep',
13+
},
14+
constant_load: {
15+
executor: 'constant-vus',
16+
vus: 50,
17+
startTime: '1m',
18+
duration: "2m",
19+
gracefulStop: '0s',
20+
exec: 'call_function_then_sleep',
21+
},
22+
max_load: {
23+
executor: 'constant-vus',
24+
vus: 100,
25+
startTime: '3m',
26+
duration: "2m",
27+
gracefulStop: '0s',
28+
exec: 'call_function',
29+
},
30+
ramping_max_load: {
31+
executor: 'ramping-vus',
32+
startVUs: 0,
33+
stages: [
34+
{ duration: '30s', target: 175 },
35+
{ duration: '30s', target: 350 },
36+
{ duration: '30s', target: 525 },
37+
{ duration: '30s', target: 700 },
38+
{ duration: '30s', target: 875 },
39+
{ duration: '30s', target: 1050 },
40+
],
41+
gracefulRampDown: '0s',
42+
startTime: '5m',
43+
gracefulStop: '0s',
44+
exec: 'call_function',
45+
},
46+
},
47+
};
48+
49+
export function call_function() {
50+
get();
51+
};
52+
53+
export function call_function_then_sleep() {
54+
get();
55+
sleep(1);
56+
};
57+
58+
function get() {
59+
http.get(`http://${__ENV.FUNC_HOSTNAME}:80/`, {
60+
headers: {
61+
'Content-Type': 'application/json',
62+
'width': 800,
63+
'height': 640,
64+
'iterations': exec.instance.vusActive,
65+
'zoom': 1,
66+
},
67+
});
68+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"dependencies": {}
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)