2023-03-13 09:29:45 +00:00
|
|
|
import logging from 'k6/x/frostfs/logging';
|
2022-12-29 14:52:55 +00:00
|
|
|
import registry from 'k6/x/frostfs/registry';
|
2022-06-23 02:20:56 +00:00
|
|
|
import http from 'k6/http';
|
|
|
|
import { SharedArray } from 'k6/data';
|
|
|
|
import { sleep } from 'k6';
|
2023-03-01 08:32:13 +00:00
|
|
|
import { textSummary } from './libs/k6-summary-0.0.2.js';
|
2023-03-14 15:04:37 +00:00
|
|
|
import { parseEnv } from './libs/env-parser.js';
|
2023-04-13 13:31:54 +00:00
|
|
|
import { uuidv4 } from './libs/k6-utils-1.4.0.js';
|
2024-01-12 10:16:34 +00:00
|
|
|
import { newGenerator } from './libs/datagen.js';
|
2023-03-14 15:04:37 +00:00
|
|
|
|
|
|
|
parseEnv();
|
2022-06-23 02:20:56 +00:00
|
|
|
|
|
|
|
const obj_list = new SharedArray('obj_list', function () {
|
2022-09-27 16:01:43 +00:00
|
|
|
return JSON.parse(open(__ENV.PREGEN_JSON)).objects;
|
|
|
|
});
|
2022-06-23 02:20:56 +00:00
|
|
|
|
|
|
|
const container_list = new SharedArray('container_list', function () {
|
2022-09-27 16:01:43 +00:00
|
|
|
return JSON.parse(open(__ENV.PREGEN_JSON)).containers;
|
|
|
|
});
|
2022-06-23 02:20:56 +00:00
|
|
|
|
|
|
|
const read_size = JSON.parse(open(__ENV.PREGEN_JSON)).obj_size;
|
2023-03-01 08:32:13 +00:00
|
|
|
const summary_json = __ENV.SUMMARY_JSON || "/tmp/summary.json";
|
2022-06-23 02:20:56 +00:00
|
|
|
|
2022-09-27 16:01:43 +00:00
|
|
|
// Select random HTTP endpoint for current VU
|
|
|
|
const http_endpoints = __ENV.HTTP_ENDPOINTS.split(',');
|
|
|
|
const http_endpoint = http_endpoints[Math.floor(Math.random() * http_endpoints.length)];
|
2023-02-16 15:42:45 +00:00
|
|
|
const log = logging.new().withField("endpoint", http_endpoint);
|
2022-06-23 02:20:56 +00:00
|
|
|
|
2022-09-27 16:01:43 +00:00
|
|
|
const registry_enabled = !!__ENV.REGISTRY_FILE;
|
|
|
|
const obj_registry = registry_enabled ? registry.open(__ENV.REGISTRY_FILE) : undefined;
|
2022-06-23 02:20:56 +00:00
|
|
|
|
2022-09-27 16:01:43 +00:00
|
|
|
const duration = __ENV.DURATION;
|
2022-06-23 02:20:56 +00:00
|
|
|
|
2022-09-27 16:01:43 +00:00
|
|
|
const scenarios = {};
|
2022-06-23 02:20:56 +00:00
|
|
|
|
2022-09-27 16:01:43 +00:00
|
|
|
const write_vu_count = parseInt(__ENV.WRITERS || '0');
|
2024-01-12 10:16:34 +00:00
|
|
|
const generator = newGenerator(write_vu_count > 0);
|
2022-09-27 16:01:43 +00:00
|
|
|
if (write_vu_count > 0) {
|
|
|
|
scenarios.write = {
|
2022-06-23 02:20:56 +00:00
|
|
|
executor: 'constant-vus',
|
2022-09-27 16:01:43 +00:00
|
|
|
vus: write_vu_count,
|
2022-06-23 02:20:56 +00:00
|
|
|
duration: `${duration}s`,
|
|
|
|
exec: 'obj_write',
|
|
|
|
gracefulStop: '5s',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-27 16:01:43 +00:00
|
|
|
const read_vu_count = parseInt(__ENV.READERS || '0');
|
|
|
|
if (read_vu_count > 0) {
|
|
|
|
scenarios.read = {
|
2022-06-23 02:20:56 +00:00
|
|
|
executor: 'constant-vus',
|
2022-09-27 16:01:43 +00:00
|
|
|
vus: read_vu_count,
|
2022-06-23 02:20:56 +00:00
|
|
|
duration: `${duration}s`,
|
|
|
|
exec: 'obj_read',
|
|
|
|
gracefulStop: '5s',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const options = {
|
2022-09-27 16:01:43 +00:00
|
|
|
scenarios,
|
2022-06-23 02:20:56 +00:00
|
|
|
setupTimeout: '5s',
|
|
|
|
};
|
|
|
|
|
2022-09-27 16:01:43 +00:00
|
|
|
export function setup() {
|
2022-10-13 12:36:13 +00:00
|
|
|
const total_vu_count = write_vu_count + read_vu_count;
|
2022-09-27 16:01:43 +00:00
|
|
|
|
|
|
|
console.log(`Pregenerated containers: ${container_list.length}`);
|
|
|
|
console.log(`Pregenerated read object size: ${read_size}`);
|
|
|
|
console.log(`Pregenerated total objects: ${obj_list.length}`);
|
|
|
|
console.log(`Reading VUs: ${read_vu_count}`);
|
|
|
|
console.log(`Writing VUs: ${write_vu_count}`);
|
|
|
|
console.log(`Total VUs: ${total_vu_count}`);
|
2023-07-20 11:47:21 +00:00
|
|
|
|
|
|
|
const start_timestamp = Date.now()
|
|
|
|
console.log(`Load started at: ${Date(start_timestamp).toString()}`)
|
2022-09-27 16:01:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function teardown(data) {
|
|
|
|
if (obj_registry) {
|
|
|
|
obj_registry.close();
|
|
|
|
}
|
2023-07-20 11:47:21 +00:00
|
|
|
const end_timestamp = Date.now()
|
|
|
|
console.log(`Load finished at: ${Date(end_timestamp).toString()}`)
|
2022-09-27 16:01:43 +00:00
|
|
|
}
|
|
|
|
|
2023-03-01 08:32:13 +00:00
|
|
|
export function handleSummary(data) {
|
|
|
|
return {
|
|
|
|
'stdout': textSummary(data, { indent: ' ', enableColors: false }),
|
|
|
|
[summary_json]: JSON.stringify(data),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-06-23 02:20:56 +00:00
|
|
|
export function obj_write() {
|
2022-08-11 13:56:39 +00:00
|
|
|
if (__ENV.SLEEP_WRITE) {
|
|
|
|
sleep(__ENV.SLEEP_WRITE);
|
2022-09-27 16:01:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const container = container_list[Math.floor(Math.random() * container_list.length)];
|
|
|
|
|
2024-01-12 14:37:29 +00:00
|
|
|
const payload = generator.genPayload();
|
2022-09-27 16:01:43 +00:00
|
|
|
const data = {
|
2022-06-23 02:20:56 +00:00
|
|
|
field: uuidv4(),
|
2024-01-11 18:46:57 +00:00
|
|
|
// Because we use `file` wrapping and it is not straightforward to use streams here,
|
|
|
|
// `-e STREAMING=1` has no effect for this scenario.
|
|
|
|
file: http.file(payload.bytes(), "random.data"),
|
2022-06-23 02:20:56 +00:00
|
|
|
};
|
|
|
|
|
2022-09-27 16:01:43 +00:00
|
|
|
const resp = http.post(`http://${http_endpoint}/upload/${container}`, data);
|
2022-06-23 02:20:56 +00:00
|
|
|
if (resp.status != 200) {
|
2023-02-16 15:58:45 +00:00
|
|
|
log.withFields({status: resp.status, cid: container}).error(resp.error);
|
2022-09-27 16:01:43 +00:00
|
|
|
return;
|
2022-06-23 02:20:56 +00:00
|
|
|
}
|
2022-09-27 16:01:43 +00:00
|
|
|
const object_id = JSON.parse(resp.body).object_id;
|
|
|
|
if (obj_registry) {
|
2024-01-11 18:46:57 +00:00
|
|
|
obj_registry.addObject(container, object_id, "", "", payload.hash());
|
2022-08-10 11:31:03 +00:00
|
|
|
}
|
2022-06-23 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function obj_read() {
|
2022-08-11 13:56:39 +00:00
|
|
|
if (__ENV.SLEEP_READ) {
|
|
|
|
sleep(__ENV.SLEEP_READ);
|
2022-08-10 11:31:03 +00:00
|
|
|
}
|
2022-09-27 16:01:43 +00:00
|
|
|
|
|
|
|
const obj = obj_list[Math.floor(Math.random() * obj_list.length)];
|
|
|
|
const resp = http.get(`http://${http_endpoint}/get/${obj.container}/${obj.object}`);
|
|
|
|
if (resp.status != 200) {
|
2023-02-16 15:58:45 +00:00
|
|
|
log.withFields({status: resp.status, cid: obj.container, oid: obj.object}).error(resp.error);
|
2022-09-27 16:01:43 +00:00
|
|
|
}
|
2022-06-23 02:20:56 +00:00
|
|
|
}
|