2024-06-14 08:26:01 +00:00
|
|
|
import { sleep } from 'k6';
|
|
|
|
import { SharedArray } from 'k6/data';
|
2024-04-05 10:25:12 +00:00
|
|
|
import exec from 'k6/execution';
|
2023-02-16 15:42:45 +00:00
|
|
|
import logging from 'k6/x/frostfs/logging';
|
2024-03-20 08:04:13 +00:00
|
|
|
import native from 'k6/x/frostfs/native';
|
2022-12-29 14:52:55 +00:00
|
|
|
import registry from 'k6/x/frostfs/registry';
|
2024-01-23 15:21:51 +00:00
|
|
|
import stats from 'k6/x/frostfs/stats';
|
2024-03-20 08:04:13 +00:00
|
|
|
|
2024-06-14 08:26:01 +00:00
|
|
|
import { newGenerator } from './libs/datagen.js';
|
|
|
|
import { parseEnv } from './libs/env-parser.js';
|
|
|
|
import { textSummary } from './libs/k6-summary-0.0.2.js';
|
|
|
|
import { uuidv4 } from './libs/k6-utils-1.4.0.js';
|
2023-03-14 15:04:37 +00:00
|
|
|
|
|
|
|
parseEnv();
|
2022-06-23 02:20:56 +00:00
|
|
|
|
2024-04-05 10:25:31 +00:00
|
|
|
const obj_list = new SharedArray(
|
2024-06-14 08:26:01 +00:00
|
|
|
'obj_list',
|
|
|
|
function () { return JSON.parse(open(__ENV.PREGEN_JSON)).objects; });
|
2022-06-23 02:20:56 +00:00
|
|
|
|
2024-04-05 10:25:31 +00:00
|
|
|
const container_list = new SharedArray(
|
2024-06-14 08:26:01 +00:00
|
|
|
'container_list',
|
|
|
|
function () { 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;
|
2024-03-20 08:04:13 +00:00
|
|
|
const summary_json = __ENV.SUMMARY_JSON || '/tmp/summary.json';
|
2022-06-23 02:20:56 +00:00
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
// Select random gRPC endpoint for current VU
|
|
|
|
const grpc_endpoints = __ENV.GRPC_ENDPOINTS.split(',');
|
2024-03-20 08:04:13 +00:00
|
|
|
const grpc_endpoint =
|
2024-06-14 08:26:01 +00:00
|
|
|
grpc_endpoints[Math.floor(Math.random() * grpc_endpoints.length)];
|
2024-03-20 08:04:13 +00:00
|
|
|
const grpc_client = native.connect(
|
2024-06-14 08:26:01 +00:00
|
|
|
grpc_endpoint, '', __ENV.DIAL_TIMEOUT ? parseInt(__ENV.DIAL_TIMEOUT) : 5,
|
|
|
|
__ENV.STREAM_TIMEOUT ? parseInt(__ENV.STREAM_TIMEOUT) : 60,
|
|
|
|
__ENV.PREPARE_LOCALLY ? __ENV.PREPARE_LOCALLY.toLowerCase() === 'true' : false,
|
|
|
|
1024 * parseInt(__ENV.MAX_OBJECT_SIZE || '0'));
|
2024-03-20 08:04:13 +00:00
|
|
|
const log = logging.new().withField('endpoint', grpc_endpoint);
|
2022-06-23 02:20:56 +00:00
|
|
|
|
2022-09-21 05:45:23 +00:00
|
|
|
const registry_enabled = !!__ENV.REGISTRY_FILE;
|
2024-03-20 08:04:13 +00:00
|
|
|
const obj_registry =
|
2024-06-14 08:26:01 +00:00
|
|
|
registry_enabled ? registry.open(__ENV.REGISTRY_FILE) : undefined;
|
2022-09-21 05:45:23 +00:00
|
|
|
|
2022-09-27 16:01:43 +00:00
|
|
|
const duration = __ENV.DURATION;
|
|
|
|
|
2024-01-23 15:21:51 +00:00
|
|
|
if (!!__ENV.METRIC_TAGS) {
|
2024-03-20 08:04:13 +00:00
|
|
|
stats.setTags(__ENV.METRIC_TAGS)
|
2024-01-23 15:21:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-02 17:08:43 +00:00
|
|
|
const read_age = __ENV.READ_AGE ? parseInt(__ENV.READ_AGE) : 10;
|
2023-07-19 14:23:38 +00:00
|
|
|
let obj_to_read_selector = undefined;
|
|
|
|
if (registry_enabled) {
|
2024-03-20 08:04:13 +00:00
|
|
|
obj_to_read_selector = registry.getLoopedSelector(
|
2024-06-14 08:26:01 +00:00
|
|
|
__ENV.REGISTRY_FILE, 'obj_to_read',
|
|
|
|
__ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0, {
|
|
|
|
status: 'created',
|
|
|
|
age: read_age,
|
|
|
|
})
|
2023-07-19 14:23:38 +00:00
|
|
|
}
|
|
|
|
|
2022-09-02 19:23:33 +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');
|
2023-07-05 12:35:00 +00:00
|
|
|
const write_grpc_chunk_size = 1024 * parseInt(__ENV.GRPC_CHUNK_SIZE || '0')
|
2024-01-12 10:16:34 +00:00
|
|
|
const generator = newGenerator(write_vu_count > 0);
|
2022-09-02 19:23:33 +00:00
|
|
|
if (write_vu_count > 0) {
|
2024-03-20 08:04:13 +00:00
|
|
|
scenarios.write = {
|
2024-06-14 08:26:01 +00:00
|
|
|
executor: 'constant-vus',
|
|
|
|
vus: write_vu_count,
|
|
|
|
duration: `${duration}s`,
|
|
|
|
exec: 'obj_write',
|
|
|
|
gracefulStop: '5s',
|
2024-03-20 08:04:13 +00:00
|
|
|
};
|
2022-06-23 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
2024-04-05 10:25:12 +00:00
|
|
|
const delete_age = __ENV.DELETE_AGE ? parseInt(__ENV.DELETE_AGE) : undefined;
|
|
|
|
let obj_to_delete_selector = undefined;
|
|
|
|
let obj_to_delete_exit_on_null = undefined;
|
|
|
|
if (registry_enabled && delete_age) {
|
|
|
|
obj_to_delete_exit_on_null = write_vu_count == 0;
|
|
|
|
|
|
|
|
let constructor = obj_to_delete_exit_on_null ? registry.getOneshotSelector
|
2024-06-14 08:26:01 +00:00
|
|
|
: registry.getSelector;
|
2024-04-05 10:25:12 +00:00
|
|
|
|
|
|
|
obj_to_delete_selector =
|
2024-06-14 08:26:01 +00:00
|
|
|
constructor(__ENV.REGISTRY_FILE, 'obj_to_delete',
|
|
|
|
__ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0, {
|
|
|
|
status: 'created',
|
|
|
|
age: delete_age,
|
|
|
|
});
|
2024-04-05 10:25:12 +00:00
|
|
|
}
|
|
|
|
|
2022-09-27 16:01:43 +00:00
|
|
|
const read_vu_count = parseInt(__ENV.READERS || '0');
|
2022-09-02 19:23:33 +00:00
|
|
|
if (read_vu_count > 0) {
|
2024-03-20 08:04:13 +00:00
|
|
|
scenarios.read = {
|
2024-06-14 08:26:01 +00:00
|
|
|
executor: 'constant-vus',
|
|
|
|
vus: read_vu_count,
|
|
|
|
duration: `${duration}s`,
|
|
|
|
exec: 'obj_read',
|
|
|
|
gracefulStop: '5s',
|
2024-03-20 08:04:13 +00:00
|
|
|
};
|
2022-06-23 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
2022-09-27 16:01:43 +00:00
|
|
|
const delete_vu_count = parseInt(__ENV.DELETERS || '0');
|
|
|
|
if (delete_vu_count > 0) {
|
2024-03-20 08:04:13 +00:00
|
|
|
if (!obj_to_delete_selector) {
|
|
|
|
throw new Error(
|
2024-06-14 08:26:01 +00:00
|
|
|
'Positive DELETE worker number without a proper object selector');
|
2024-03-20 08:04:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
scenarios.delete = {
|
2024-06-14 08:26:01 +00:00
|
|
|
executor: 'constant-vus',
|
|
|
|
vus: delete_vu_count,
|
|
|
|
duration: `${duration}s`,
|
|
|
|
exec: 'obj_delete',
|
|
|
|
gracefulStop: '5s',
|
2024-03-20 08:04:13 +00:00
|
|
|
};
|
2022-09-27 16:01:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const options = {
|
2024-03-20 08:04:13 +00:00
|
|
|
scenarios,
|
2024-06-14 08:26:01 +00:00
|
|
|
setupTimeout: '5s',
|
2022-09-27 16:01:43 +00:00
|
|
|
};
|
|
|
|
|
2022-06-23 02:20:56 +00:00
|
|
|
export function setup() {
|
2024-03-20 08:04:13 +00:00
|
|
|
const total_vu_count = write_vu_count + read_vu_count + delete_vu_count;
|
|
|
|
|
|
|
|
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(`Deleting VUs: ${delete_vu_count}`);
|
|
|
|
console.log(`Total VUs: ${total_vu_count}`);
|
|
|
|
|
|
|
|
const start_timestamp = Date.now()
|
|
|
|
console.log(
|
2024-06-14 08:26:01 +00:00
|
|
|
`Load started at: ${Date(start_timestamp).toString()}`)
|
2022-06-23 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
2022-09-21 05:45:23 +00:00
|
|
|
export function teardown(data) {
|
2024-03-20 08:04:13 +00:00
|
|
|
if (obj_registry) {
|
|
|
|
obj_registry.close();
|
|
|
|
}
|
|
|
|
const end_timestamp = Date.now()
|
|
|
|
console.log(
|
2024-06-14 08:26:01 +00:00
|
|
|
`Load finished at: ${Date(end_timestamp).toString()}`)
|
2022-09-21 05:45:23 +00:00
|
|
|
}
|
|
|
|
|
2023-03-01 08:32:13 +00:00
|
|
|
export function handleSummary(data) {
|
2024-03-20 08:04:13 +00:00
|
|
|
return {
|
2024-06-14 08:26:01 +00:00
|
|
|
'stdout': textSummary(data, { indent: ' ', enableColors: false }),
|
|
|
|
[summary_json]: JSON.stringify(data),
|
2024-03-20 08:04:13 +00:00
|
|
|
};
|
2023-03-01 08:32:13 +00:00
|
|
|
}
|
|
|
|
|
2022-06-23 02:20:56 +00:00
|
|
|
export function obj_write() {
|
2024-03-20 08:04:13 +00:00
|
|
|
if (__ENV.SLEEP_WRITE) {
|
|
|
|
sleep(__ENV.SLEEP_WRITE);
|
|
|
|
}
|
|
|
|
|
2024-06-14 08:26:01 +00:00
|
|
|
const headers = { unique_header: uuidv4() };
|
2024-03-20 08:04:13 +00:00
|
|
|
const container =
|
2024-06-14 08:26:01 +00:00
|
|
|
container_list[Math.floor(Math.random() * container_list.length)];
|
2024-03-20 08:04:13 +00:00
|
|
|
|
|
|
|
const payload = generator.genPayload();
|
|
|
|
const resp =
|
2024-06-14 08:26:01 +00:00
|
|
|
grpc_client.put(container, headers, payload, write_grpc_chunk_size);
|
2024-03-20 08:04:13 +00:00
|
|
|
if (!resp.success) {
|
|
|
|
log.withField('cid', container).error(resp.error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj_registry) {
|
|
|
|
obj_registry.addObject(container, resp.object_id, '', '', payload.hash());
|
|
|
|
}
|
2022-06-23 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function obj_read() {
|
2024-03-20 08:04:13 +00:00
|
|
|
if (__ENV.SLEEP_READ) {
|
|
|
|
sleep(__ENV.SLEEP_READ);
|
|
|
|
}
|
2022-09-02 19:23:33 +00:00
|
|
|
|
2024-03-20 08:04:13 +00:00
|
|
|
if (obj_to_read_selector) {
|
|
|
|
const obj = obj_to_read_selector.nextObject();
|
|
|
|
if (!obj) {
|
|
|
|
return;
|
2023-07-19 14:23:38 +00:00
|
|
|
}
|
2024-03-20 08:04:13 +00:00
|
|
|
const resp = grpc_client.get(obj.c_id, obj.o_id)
|
2022-09-02 19:23:33 +00:00
|
|
|
if (!resp.success) {
|
2024-06-14 08:26:01 +00:00
|
|
|
log.withFields({ cid: obj.c_id, oid: obj.o_id }).error(resp.error);
|
2022-09-02 19:23:33 +00:00
|
|
|
}
|
2024-03-20 08:04:13 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const obj = obj_list[Math.floor(Math.random() * obj_list.length)];
|
|
|
|
const resp = grpc_client.get(obj.container, obj.object)
|
|
|
|
if (!resp.success) {
|
2024-06-14 08:26:01 +00:00
|
|
|
log.withFields({ cid: obj.container, oid: obj.object }).error(resp.error);
|
2024-03-20 08:04:13 +00:00
|
|
|
}
|
2022-06-23 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
2022-09-27 16:01:43 +00:00
|
|
|
export function obj_delete() {
|
2024-03-20 08:04:13 +00:00
|
|
|
if (__ENV.SLEEP_DELETE) {
|
|
|
|
sleep(__ENV.SLEEP_DELETE);
|
|
|
|
}
|
|
|
|
|
|
|
|
const obj = obj_to_delete_selector.nextObject();
|
|
|
|
if (!obj) {
|
2024-04-05 10:25:12 +00:00
|
|
|
if (obj_to_delete_exit_on_null) {
|
|
|
|
exec.test.abort("No more objects to select");
|
|
|
|
}
|
2024-03-20 08:04:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const resp = grpc_client.delete(obj.c_id, obj.o_id);
|
|
|
|
if (!resp.success) {
|
|
|
|
// Log errors except (2052 - object already deleted)
|
2024-06-14 08:26:01 +00:00
|
|
|
log.withFields({ cid: obj.c_id, oid: obj.o_id }).error(resp.error);
|
2024-03-20 08:04:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
obj_registry.deleteObject(obj.id);
|
2022-09-27 16:01:43 +00:00
|
|
|
}
|