2024-03-20 08:04:13 +00:00
|
|
|
import {SharedArray} from 'k6/data';
|
|
|
|
import exec from 'k6/execution';
|
2023-03-31 10:30:33 +00:00
|
|
|
import logging from 'k6/x/frostfs/logging';
|
|
|
|
import registry from 'k6/x/frostfs/registry';
|
|
|
|
import s3local from 'k6/x/frostfs/s3local';
|
2024-03-20 08:04:13 +00:00
|
|
|
import stats from 'k6/x/frostfs/stats';
|
|
|
|
|
|
|
|
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';
|
2024-11-15 16:07:24 +00:00
|
|
|
import {generateS3Key} from './libs/keygen.js';
|
2023-03-31 10:30:33 +00:00
|
|
|
|
|
|
|
parseEnv();
|
|
|
|
|
2024-11-15 16:07:24 +00:00
|
|
|
const obj_list = new SharedArray(
|
|
|
|
'obj_list',
|
|
|
|
function() { return JSON.parse(open(__ENV.PREGEN_JSON)).objects; });
|
2023-03-31 10:30:33 +00:00
|
|
|
|
2024-11-15 16:07:24 +00:00
|
|
|
const container_list = new SharedArray(
|
|
|
|
'container_list',
|
|
|
|
function() { return JSON.parse(open(__ENV.PREGEN_JSON)).containers; });
|
2023-03-31 10:30:33 +00:00
|
|
|
|
2024-11-15 16:07:24 +00:00
|
|
|
const bucket_list = new SharedArray(
|
|
|
|
'bucket_list',
|
|
|
|
function() { return JSON.parse(open(__ENV.PREGEN_JSON)).buckets; });
|
2023-03-31 10:30:33 +00:00
|
|
|
|
|
|
|
function bucket_mapping() {
|
2024-03-20 08:04:13 +00:00
|
|
|
if (container_list.length != bucket_list.length) {
|
|
|
|
throw 'The number of containers and buckets in the preset file must be the same.';
|
|
|
|
}
|
|
|
|
let mapping = {};
|
|
|
|
for (let i = 0; i < container_list.length; ++i) {
|
|
|
|
mapping[bucket_list[i]] = container_list[i];
|
|
|
|
}
|
|
|
|
return mapping;
|
2023-03-31 10:30:33 +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';
|
2023-03-31 10:30:33 +00:00
|
|
|
|
|
|
|
const config_file = __ENV.CONFIG_FILE;
|
2023-10-23 15:55:07 +00:00
|
|
|
const config_dir = __ENV.CONFIG_DIR;
|
2024-03-20 08:04:13 +00:00
|
|
|
const max_total_size_gb =
|
|
|
|
__ENV.MAX_TOTAL_SIZE_GB ? parseInt(__ENV.MAX_TOTAL_SIZE_GB) : 0;
|
2024-11-15 16:07:24 +00:00
|
|
|
const s3_client = s3local.connect(config_file, config_dir, {
|
|
|
|
'debug_logger' : __ENV.DEBUG_LOGGER || 'false',
|
|
|
|
},
|
|
|
|
bucket_mapping(), max_total_size_gb);
|
2024-03-20 08:04:13 +00:00
|
|
|
const log = logging.new().withFields(
|
2024-11-15 16:07:24 +00:00
|
|
|
{'config_file' : config_file, 'config_dir' : config_dir});
|
2023-03-31 10:30:33 +00:00
|
|
|
|
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-03-31 10:30:33 +00:00
|
|
|
const registry_enabled = !!__ENV.REGISTRY_FILE;
|
2024-03-20 08:04:13 +00:00
|
|
|
const obj_registry =
|
|
|
|
registry_enabled ? registry.open(__ENV.REGISTRY_FILE) : undefined;
|
2023-03-31 10:30:33 +00:00
|
|
|
|
2023-07-20 07:00:51 +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(
|
|
|
|
__ENV.REGISTRY_FILE, 'obj_to_read',
|
|
|
|
__ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0, {
|
2024-11-15 16:07:24 +00:00
|
|
|
status : 'created',
|
2024-03-20 08:04:13 +00:00
|
|
|
})
|
2023-07-20 07:00:51 +00:00
|
|
|
}
|
|
|
|
|
2023-03-31 10:30:33 +00:00
|
|
|
const duration = __ENV.DURATION;
|
|
|
|
|
|
|
|
const scenarios = {};
|
|
|
|
|
|
|
|
const write_vu_count = parseInt(__ENV.WRITERS || '0');
|
2024-01-12 10:16:34 +00:00
|
|
|
const generator = newGenerator(write_vu_count > 0);
|
2023-03-31 10:30:33 +00:00
|
|
|
if (write_vu_count > 0) {
|
2024-03-20 08:04:13 +00:00
|
|
|
scenarios.write = {
|
2024-11-15 16:07:24 +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
|
|
|
};
|
2023-03-31 10:30:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const read_vu_count = parseInt(__ENV.READERS || '0');
|
|
|
|
if (read_vu_count > 0) {
|
2024-03-20 08:04:13 +00:00
|
|
|
scenarios.read = {
|
2024-11-15 16:07:24 +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
|
|
|
};
|
2023-03-31 10:30:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const options = {
|
2024-03-20 08:04:13 +00:00
|
|
|
scenarios,
|
2024-11-15 16:07:24 +00:00
|
|
|
setupTimeout : '5s',
|
2023-03-31 10:30:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export function setup() {
|
2024-03-20 08:04:13 +00:00
|
|
|
const total_vu_count = write_vu_count + read_vu_count;
|
|
|
|
|
|
|
|
console.log(`Pregenerated buckets: ${bucket_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}`);
|
|
|
|
|
|
|
|
const start_timestamp = Date.now()
|
|
|
|
console.log(
|
|
|
|
`Load started at: ${Date(start_timestamp).toString()}`)
|
2023-03-31 10:30:33 +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(
|
|
|
|
`Load finished at: ${Date(end_timestamp).toString()}`)
|
2023-03-31 10:30:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function handleSummary(data) {
|
2024-03-20 08:04:13 +00:00
|
|
|
return {
|
2024-11-15 16:07:24 +00:00
|
|
|
'stdout' : textSummary(data, {indent : ' ', enableColors : false}),
|
|
|
|
[summary_json] : JSON.stringify(data),
|
2024-03-20 08:04:13 +00:00
|
|
|
};
|
|
|
|
}
|
2023-03-31 10:30:33 +00:00
|
|
|
|
|
|
|
export function obj_write() {
|
2024-10-23 14:14:54 +00:00
|
|
|
const key = generateS3Key();
|
2024-03-20 08:04:13 +00:00
|
|
|
const bucket = bucket_list[Math.floor(Math.random() * bucket_list.length)];
|
|
|
|
|
|
|
|
const payload = generator.genPayload();
|
|
|
|
const resp = s3_client.put(bucket, key, payload);
|
|
|
|
if (!resp.success) {
|
|
|
|
if (resp.abort) {
|
|
|
|
exec.test.abort(resp.error);
|
2023-03-31 10:30:33 +00:00
|
|
|
}
|
2024-11-15 16:07:24 +00:00
|
|
|
log.withFields({bucket : bucket, key : key}).error(resp.error);
|
2024-03-20 08:04:13 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-03-31 10:30:33 +00:00
|
|
|
|
2024-03-20 08:04:13 +00:00
|
|
|
if (obj_registry) {
|
|
|
|
obj_registry.addObject('', '', bucket, key, payload.hash());
|
|
|
|
}
|
2023-03-31 10:30:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function obj_read() {
|
2024-03-20 08:04:13 +00:00
|
|
|
if (obj_to_read_selector) {
|
|
|
|
const obj = obj_to_read_selector.nextObject();
|
|
|
|
if (!obj) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const resp = s3_client.get(obj.s3_bucket, obj.s3_key)
|
|
|
|
if (!resp.success) {
|
2024-11-15 16:07:24 +00:00
|
|
|
log.withFields({bucket : obj.s3_bucket, key : obj.s3_key})
|
2024-03-20 08:04:13 +00:00
|
|
|
.error(resp.error);
|
2023-07-20 07:00:51 +00:00
|
|
|
}
|
2024-03-20 08:04:13 +00:00
|
|
|
return
|
|
|
|
}
|
2023-07-20 07:00:51 +00:00
|
|
|
|
2024-03-20 08:04:13 +00:00
|
|
|
const obj = obj_list[Math.floor(Math.random() * obj_list.length)];
|
2023-03-31 10:30:33 +00:00
|
|
|
|
2024-03-20 08:04:13 +00:00
|
|
|
const resp = s3_client.get(obj.bucket, obj.object);
|
|
|
|
if (!resp.success) {
|
2024-11-15 16:07:24 +00:00
|
|
|
log.withFields({bucket : obj.bucket, key : obj.object}).error(resp.error);
|
2024-03-20 08:04:13 +00:00
|
|
|
}
|
2023-03-31 10:30:33 +00:00
|
|
|
}
|