2024-03-20 08:04:13 +00:00
|
|
|
import {sleep} from 'k6';
|
|
|
|
import {SharedArray} from 'k6/data';
|
2023-07-05 14:43:49 +00:00
|
|
|
import logging from 'k6/x/frostfs/logging';
|
|
|
|
import registry from 'k6/x/frostfs/registry';
|
|
|
|
import s3 from 'k6/x/frostfs/s3';
|
2024-03-20 08:04:13 +00:00
|
|
|
import stats from 'k6/x/frostfs/stats';
|
|
|
|
|
2024-10-23 14:14:54 +00:00
|
|
|
import {generateS3Key} from './libs/keygen.js';
|
2024-03-20 08:04:13 +00:00
|
|
|
import {newGenerator} from './libs/datagen.js';
|
2023-07-05 14:43:49 +00:00
|
|
|
import {parseEnv} from './libs/env-parser.js';
|
2024-03-20 08:04:13 +00:00
|
|
|
import {textSummary} from './libs/k6-summary-0.0.2.js';
|
2023-07-05 14:43:49 +00:00
|
|
|
|
|
|
|
parseEnv();
|
|
|
|
|
2024-03-20 08:04:13 +00:00
|
|
|
const bucket_list = new SharedArray('bucket_list', function() {
|
|
|
|
return JSON.parse(open(__ENV.PREGEN_JSON)).buckets;
|
2023-07-05 14:43:49 +00:00
|
|
|
});
|
|
|
|
|
2024-03-20 08:04:13 +00:00
|
|
|
const summary_json = __ENV.SUMMARY_JSON || '/tmp/summary.json';
|
2023-07-05 14:43:49 +00:00
|
|
|
|
|
|
|
// Select random S3 endpoint for current VU
|
|
|
|
const s3_endpoints = __ENV.S3_ENDPOINTS.split(',');
|
2024-03-20 08:04:13 +00:00
|
|
|
const s3_endpoint =
|
|
|
|
s3_endpoints[Math.floor(Math.random() * s3_endpoints.length)];
|
|
|
|
const no_verify_ssl = __ENV.NO_VERIFY_SSL || 'true';
|
|
|
|
const connection_args = {
|
|
|
|
no_verify_ssl: no_verify_ssl
|
|
|
|
};
|
2023-10-27 10:22:38 +00:00
|
|
|
const s3_client = s3.connect(s3_endpoint, connection_args);
|
2024-03-20 08:04:13 +00:00
|
|
|
const log = logging.new().withField('endpoint', s3_endpoint);
|
2023-07-05 14:43:49 +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-07-05 14:43:49 +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-07-05 14:43:49 +00:00
|
|
|
const scenarios = {};
|
|
|
|
|
|
|
|
const write_vu_count = parseInt(__ENV.WRITERS || '0');
|
|
|
|
if (write_vu_count < 1) {
|
2024-03-20 08:04:13 +00:00
|
|
|
throw 'number of VUs (env WRITERS) performing write operations should be greater than 0';
|
2023-07-05 14:43:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const write_multipart_vu_count = parseInt(__ENV.WRITERS_MULTIPART || '0');
|
|
|
|
if (write_multipart_vu_count < 1) {
|
2024-03-20 08:04:13 +00:00
|
|
|
throw 'number of parts (env WRITERS_MULTIPART) to upload in parallel should be greater than 0';
|
2023-07-05 14:43:49 +00:00
|
|
|
}
|
|
|
|
|
2024-03-20 08:04:13 +00:00
|
|
|
const generator =
|
|
|
|
newGenerator(write_vu_count > 0 || write_multipart_vu_count > 0);
|
2023-07-05 14:43:49 +00:00
|
|
|
if (write_vu_count > 0) {
|
2024-03-20 08:04:13 +00:00
|
|
|
scenarios.write_multipart = {
|
|
|
|
executor: 'constant-vus',
|
|
|
|
vus: write_vu_count,
|
|
|
|
duration: `${duration}s`,
|
|
|
|
exec: 'obj_write_multipart',
|
|
|
|
gracefulStop: '5s',
|
|
|
|
};
|
2023-07-05 14:43:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const options = {
|
2024-03-20 08:04:13 +00:00
|
|
|
scenarios,
|
|
|
|
setupTimeout: '5s',
|
2023-07-05 14:43:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export function setup() {
|
2024-03-20 08:04:13 +00:00
|
|
|
const total_vu_count = write_vu_count * write_multipart_vu_count;
|
2023-07-05 14:43:49 +00:00
|
|
|
|
2024-03-20 08:04:13 +00:00
|
|
|
console.log(`Pregenerated buckets: ${bucket_list.length}`);
|
|
|
|
console.log(`Writing VUs: ${write_vu_count}`);
|
|
|
|
console.log(`Writing multipart VUs: ${write_multipart_vu_count}`);
|
|
|
|
console.log(`Total VUs: ${total_vu_count}`);
|
2023-07-05 14:43:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function teardown(data) {
|
2024-03-20 08:04:13 +00:00
|
|
|
if (obj_registry) {
|
|
|
|
obj_registry.close();
|
|
|
|
}
|
2023-07-05 14:43:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function handleSummary(data) {
|
2024-03-20 08:04:13 +00:00
|
|
|
return {
|
|
|
|
'stdout': textSummary(data, {indent: ' ', enableColors: false}),
|
|
|
|
[summary_json]: JSON.stringify(data),
|
|
|
|
};
|
2023-07-05 14:43:49 +00:00
|
|
|
}
|
|
|
|
|
2024-03-20 08:04:13 +00:00
|
|
|
const write_multipart_part_size =
|
|
|
|
1024 * parseInt(__ENV.WRITE_OBJ_PART_SIZE || '0')
|
2023-07-05 14:43:49 +00:00
|
|
|
if (write_multipart_part_size < 5 * 1024 * 1024) {
|
2024-03-20 08:04:13 +00:00
|
|
|
throw 'part size (env WRITE_OBJ_PART_SIZE * 1024) must be greater than (5 MB)';
|
2023-07-05 14:43:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function obj_write_multipart() {
|
2024-03-20 08:04:13 +00:00
|
|
|
if (__ENV.SLEEP_WRITE) {
|
|
|
|
sleep(__ENV.SLEEP_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.multipart(
|
|
|
|
bucket, key, write_multipart_part_size, write_multipart_vu_count,
|
|
|
|
payload);
|
|
|
|
if (!resp.success) {
|
|
|
|
log.withFields({bucket: bucket, key: key}).error(resp.error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj_registry) {
|
|
|
|
obj_registry.addObject('', '', bucket, key, payload.hash());
|
|
|
|
}
|
2023-07-05 14:43:49 +00:00
|
|
|
}
|