2023-03-14 12:45:25 +00:00
|
|
|
import datagen from 'k6/x/frostfs/datagen';
|
|
|
|
import local from 'k6/x/frostfs/local';
|
|
|
|
import logging from 'k6/x/frostfs/logging';
|
|
|
|
import registry from 'k6/x/frostfs/registry';
|
|
|
|
import { SharedArray } from 'k6/data';
|
|
|
|
import { textSummary } from './libs/k6-summary-0.0.2.js';
|
2023-03-24 08:29:44 +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';
|
2023-12-14 13:22:07 +00:00
|
|
|
import exec from 'k6/execution';
|
2023-03-24 08:29:44 +00:00
|
|
|
|
|
|
|
parseEnv();
|
2023-03-14 12:45:25 +00:00
|
|
|
|
|
|
|
const obj_list = new SharedArray('obj_list', function () {
|
|
|
|
return JSON.parse(open(__ENV.PREGEN_JSON)).objects;
|
|
|
|
});
|
|
|
|
|
|
|
|
const container_list = new SharedArray('container_list', function () {
|
|
|
|
return JSON.parse(open(__ENV.PREGEN_JSON)).containers;
|
|
|
|
});
|
|
|
|
|
|
|
|
const read_size = JSON.parse(open(__ENV.PREGEN_JSON)).obj_size;
|
|
|
|
const summary_json = __ENV.SUMMARY_JSON || "/tmp/summary.json";
|
|
|
|
|
|
|
|
const config_file = __ENV.CONFIG_FILE;
|
2023-10-23 15:55:07 +00:00
|
|
|
const config_dir = __ENV.CONFIG_DIR;
|
2023-04-19 07:44:45 +00:00
|
|
|
const debug_logger = (__ENV.DEBUG_LOGGER || 'false') == 'true';
|
2023-12-14 13:22:07 +00:00
|
|
|
const max_total_size_gb = __ENV.MAX_TOTAL_SIZE_GB ? parseInt(__ENV.MAX_TOTAL_SIZE_GB) : 0;
|
|
|
|
const local_client = local.connect(config_file, config_dir, '', debug_logger, max_total_size_gb);
|
2023-10-23 15:55:07 +00:00
|
|
|
const log = logging.new().withFields({"config_file": config_file,"config_dir": config_dir});
|
2023-03-14 12:45:25 +00:00
|
|
|
|
|
|
|
const registry_enabled = !!__ENV.REGISTRY_FILE;
|
|
|
|
const obj_registry = registry_enabled ? registry.open(__ENV.REGISTRY_FILE) : undefined;
|
|
|
|
|
|
|
|
const duration = __ENV.DURATION;
|
|
|
|
|
|
|
|
const delete_age = __ENV.DELETE_AGE ? parseInt(__ENV.DELETE_AGE) : undefined;
|
|
|
|
let obj_to_delete_selector = undefined;
|
|
|
|
if (registry_enabled && delete_age) {
|
|
|
|
obj_to_delete_selector = registry.getSelector(
|
|
|
|
__ENV.REGISTRY_FILE,
|
|
|
|
"obj_to_delete",
|
|
|
|
__ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0,
|
|
|
|
{
|
|
|
|
status: "created",
|
|
|
|
age: delete_age,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const generator = datagen.generator(1024 * parseInt(__ENV.WRITE_OBJ_SIZE));
|
|
|
|
|
|
|
|
const scenarios = {};
|
|
|
|
|
|
|
|
const write_vu_count = parseInt(__ENV.WRITERS || '0');
|
|
|
|
if (write_vu_count > 0) {
|
|
|
|
scenarios.write = {
|
|
|
|
executor: 'constant-vus',
|
|
|
|
vus: write_vu_count,
|
|
|
|
duration: `${duration}s`,
|
|
|
|
exec: 'obj_write',
|
|
|
|
gracefulStop: '5s',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const read_vu_count = parseInt(__ENV.READERS || '0');
|
|
|
|
if (read_vu_count > 0) {
|
|
|
|
scenarios.read = {
|
|
|
|
executor: 'constant-vus',
|
|
|
|
vus: read_vu_count,
|
|
|
|
duration: `${duration}s`,
|
|
|
|
exec: 'obj_read',
|
|
|
|
gracefulStop: '5s',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const delete_vu_count = parseInt(__ENV.DELETERS || '0');
|
|
|
|
if (delete_vu_count > 0) {
|
|
|
|
if (!obj_to_delete_selector) {
|
|
|
|
throw new Error('Positive DELETE worker number without a proper object selector');
|
|
|
|
}
|
|
|
|
|
|
|
|
scenarios.delete = {
|
|
|
|
executor: 'constant-vus',
|
|
|
|
vus: delete_vu_count,
|
|
|
|
duration: `${duration}s`,
|
|
|
|
exec: 'obj_delete',
|
|
|
|
gracefulStop: '5s',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export const options = {
|
|
|
|
scenarios,
|
|
|
|
setupTimeout: '5s',
|
|
|
|
};
|
|
|
|
|
|
|
|
export function setup() {
|
|
|
|
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}`);
|
2023-07-20 11:47:21 +00:00
|
|
|
|
|
|
|
const start_timestamp = Date.now()
|
|
|
|
console.log(`Load started at: ${Date(start_timestamp).toString()}`)
|
2023-03-14 12:45:25 +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()}`)
|
2023-03-14 12:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function handleSummary(data) {
|
|
|
|
return {
|
|
|
|
'stdout': textSummary(data, { indent: ' ', enableColors: false }),
|
|
|
|
[summary_json]: JSON.stringify(data),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function obj_write() {
|
|
|
|
const headers = {
|
|
|
|
unique_header: uuidv4()
|
|
|
|
};
|
|
|
|
const container = container_list[Math.floor(Math.random() * container_list.length)];
|
|
|
|
|
|
|
|
const { payload, hash } = generator.genPayload(registry_enabled);
|
|
|
|
const resp = local_client.put(container, headers, payload);
|
|
|
|
if (!resp.success) {
|
2023-12-14 13:22:07 +00:00
|
|
|
if (resp.abort) {
|
|
|
|
exec.test.abort(resp.error);
|
|
|
|
}
|
2023-03-14 12:45:25 +00:00
|
|
|
log.withField("cid", container).error(resp.error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj_registry) {
|
|
|
|
obj_registry.addObject(container, resp.object_id, "", "", hash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function obj_read() {
|
|
|
|
const obj = obj_list[Math.floor(Math.random() * obj_list.length)];
|
|
|
|
const resp = local_client.get(obj.container, obj.object)
|
|
|
|
if (!resp.success) {
|
|
|
|
log.withFields({cid: obj.container, oid: obj.object}).error(resp.error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function obj_delete() {
|
2023-07-20 12:01:57 +00:00
|
|
|
const obj = obj_to_delete_selector.nextObject();
|
2023-03-14 12:45:25 +00:00
|
|
|
if (!obj) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const resp = local_client.delete(obj.c_id, obj.o_id);
|
|
|
|
if (!resp.success) {
|
|
|
|
// Log errors except (2052 - object already deleted)
|
|
|
|
log.withFields({cid: obj.c_id, oid: obj.o_id}).error(resp.error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
obj_registry.deleteObject(obj.id);
|
|
|
|
}
|