2024-03-20 08:04:13 +00:00
|
|
|
import {sleep} from 'k6';
|
|
|
|
import {SharedArray} from 'k6/data';
|
2023-04-14 08:03: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';
|
|
|
|
|
|
|
|
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-04-14 08:03:49 +00:00
|
|
|
|
|
|
|
parseEnv();
|
|
|
|
|
2024-03-20 08:04:13 +00:00
|
|
|
const obj_list = new SharedArray('obj_list', function() {
|
|
|
|
return JSON.parse(open(__ENV.PREGEN_JSON)).objects;
|
2023-04-14 08:03:49 +00:00
|
|
|
});
|
|
|
|
|
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-04-14 08:03:49 +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-04-14 08:03: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-07-13 12:50:03 +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-04-14 08:03: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-04-14 08:03: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-04-14 08:03:49 +00:00
|
|
|
const delete_age = __ENV.DELETE_AGE ? parseInt(__ENV.DELETE_AGE) : undefined;
|
|
|
|
let obj_to_delete_selector = undefined;
|
|
|
|
if (registry_enabled && delete_age) {
|
2024-03-20 08:04:13 +00:00
|
|
|
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,
|
|
|
|
});
|
2023-04-14 08:03:49 +00:00
|
|
|
}
|
|
|
|
|
2023-10-02 17:08:43 +00:00
|
|
|
const read_age = __ENV.READ_AGE ? parseInt(__ENV.READ_AGE) : 10;
|
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, {
|
|
|
|
status: 'created',
|
|
|
|
age: read_age,
|
|
|
|
})
|
2023-07-20 07:00:51 +00:00
|
|
|
}
|
|
|
|
|
2023-04-14 08:03:49 +00:00
|
|
|
const scenarios = {};
|
|
|
|
|
|
|
|
const time_unit = __ENV.TIME_UNIT || '1s';
|
|
|
|
const pre_alloc_write_vus = parseInt(__ENV.PRE_ALLOC_WRITERS || '0');
|
|
|
|
const max_write_vus = parseInt(__ENV.MAX_WRITERS || pre_alloc_write_vus);
|
|
|
|
const write_rate = parseInt(__ENV.WRITE_RATE || '0');
|
2024-01-12 10:16:34 +00:00
|
|
|
const generator = newGenerator(write_rate > 0);
|
2023-04-14 08:03:49 +00:00
|
|
|
if (write_rate > 0) {
|
2024-03-20 08:04:13 +00:00
|
|
|
scenarios.write = {
|
|
|
|
executor: 'constant-arrival-rate',
|
|
|
|
duration: `${duration}s`,
|
|
|
|
preAllocatedVUs: pre_alloc_write_vus,
|
|
|
|
maxVUs: max_write_vus,
|
|
|
|
rate: write_rate,
|
|
|
|
timeUnit: time_unit,
|
|
|
|
exec: 'obj_write',
|
|
|
|
gracefulStop: '5s',
|
|
|
|
};
|
2023-04-14 08:03:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const pre_alloc_read_vus = parseInt(__ENV.PRE_ALLOC_READERS || '0');
|
|
|
|
const max_read_vus = parseInt(__ENV.MAX_READERS || pre_alloc_read_vus);
|
|
|
|
const read_rate = parseInt(__ENV.READ_RATE || '0');
|
|
|
|
if (read_rate > 0) {
|
2024-03-20 08:04:13 +00:00
|
|
|
scenarios.read = {
|
|
|
|
executor: 'constant-arrival-rate',
|
|
|
|
duration: `${duration}s`,
|
|
|
|
preAllocatedVUs: pre_alloc_write_vus,
|
|
|
|
maxVUs: max_read_vus,
|
|
|
|
rate: read_rate,
|
|
|
|
timeUnit: time_unit,
|
|
|
|
exec: 'obj_read',
|
|
|
|
gracefulStop: '5s',
|
|
|
|
};
|
2023-04-14 08:03:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const pre_alloc_delete_vus = parseInt(__ENV.PRE_ALLOC_DELETERS || '0');
|
|
|
|
const max_delete_vus = parseInt(__ENV.MAX_DELETERS || pre_alloc_write_vus);
|
|
|
|
const delete_rate = parseInt(__ENV.DELETE_RATE || '0');
|
|
|
|
if (delete_rate > 0) {
|
2024-07-25 15:18:08 +00:00
|
|
|
if (!obj_to_delete_selector && !obj_list.length) {
|
2024-03-20 08:04:13 +00:00
|
|
|
throw new Error(
|
2024-07-25 15:18:08 +00:00
|
|
|
'Positive DELETE worker number without a proper object selector or any preloaded objects');
|
2024-03-20 08:04:13 +00:00
|
|
|
}
|
2023-04-14 08:03:49 +00:00
|
|
|
|
2024-03-20 08:04:13 +00:00
|
|
|
scenarios.delete = {
|
|
|
|
executor: 'constant-arrival-rate',
|
|
|
|
duration: `${duration}s`,
|
|
|
|
preAllocatedVUs: pre_alloc_delete_vus,
|
|
|
|
maxVUs: max_delete_vus,
|
|
|
|
rate: delete_rate,
|
|
|
|
timeUnit: time_unit,
|
|
|
|
exec: 'obj_delete',
|
|
|
|
gracefulStop: '5s',
|
|
|
|
};
|
2023-04-14 08:03:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const options = {
|
2024-03-20 08:04:13 +00:00
|
|
|
scenarios,
|
|
|
|
setupTimeout: '5s',
|
2023-04-14 08:03:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export function setup() {
|
2024-03-20 08:04:13 +00:00
|
|
|
const total_pre_allocated_vu_count =
|
|
|
|
pre_alloc_write_vus + pre_alloc_read_vus + pre_alloc_delete_vus;
|
|
|
|
const total_max_vu_count = max_read_vus + max_write_vus + max_delete_vus
|
|
|
|
|
|
|
|
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(`Pre allocated reading VUs: ${pre_alloc_read_vus}`);
|
|
|
|
console.log(`Pre allocated writing VUs: ${pre_alloc_write_vus}`);
|
|
|
|
console.log(`Pre allocated deleting VUs: ${pre_alloc_delete_vus}`);
|
|
|
|
console.log(`Total pre allocated VUs: ${total_pre_allocated_vu_count}`);
|
|
|
|
console.log(`Max reading VUs: ${max_read_vus}`);
|
|
|
|
console.log(`Max writing VUs: ${max_write_vus}`);
|
|
|
|
console.log(`Max deleting VUs: ${max_delete_vus}`);
|
|
|
|
console.log(`Total max VUs: ${total_max_vu_count}`);
|
|
|
|
console.log(`Time unit: ${time_unit}`);
|
|
|
|
console.log(`Read rate: ${read_rate}`);
|
|
|
|
console.log(`Writing rate: ${write_rate}`);
|
|
|
|
console.log(`Delete rate: ${delete_rate}`);
|
|
|
|
|
|
|
|
const start_timestamp = Date.now()
|
|
|
|
console.log(
|
|
|
|
`Load started at: ${Date(start_timestamp).toString()}`)
|
2023-04-14 08:03:49 +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-04-14 08:03: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-04-14 08:03:49 +00:00
|
|
|
|
|
|
|
export function obj_write() {
|
2024-03-20 08:04:13 +00:00
|
|
|
if (__ENV.SLEEP_WRITE) {
|
|
|
|
sleep(__ENV.SLEEP_WRITE);
|
|
|
|
}
|
2023-04-14 08:03:49 +00:00
|
|
|
|
2024-03-20 08:04:13 +00:00
|
|
|
const key = __ENV.OBJ_NAME || uuidv4();
|
|
|
|
const bucket = bucket_list[Math.floor(Math.random() * bucket_list.length)];
|
2023-04-14 08:03:49 +00:00
|
|
|
|
2024-03-20 08:04:13 +00:00
|
|
|
const payload = generator.genPayload();
|
|
|
|
const resp = s3_client.put(bucket, key, payload);
|
|
|
|
if (!resp.success) {
|
|
|
|
log.withFields({bucket: bucket, key: key}).error(resp.error);
|
|
|
|
return;
|
|
|
|
}
|
2023-04-14 08:03:49 +00:00
|
|
|
|
2024-03-20 08:04:13 +00:00
|
|
|
if (obj_registry) {
|
|
|
|
obj_registry.addObject('', '', bucket, key, payload.hash());
|
|
|
|
}
|
2023-04-14 08:03:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function obj_read() {
|
2024-03-20 08:04:13 +00:00
|
|
|
if (__ENV.SLEEP_READ) {
|
|
|
|
sleep(__ENV.SLEEP_READ);
|
|
|
|
}
|
2023-04-14 08:03:49 +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;
|
|
|
|
}
|
|
|
|
const resp = s3_client.get(obj.s3_bucket, obj.s3_key)
|
|
|
|
if (!resp.success) {
|
|
|
|
log.withFields({bucket: obj.s3_bucket, key: obj.s3_key})
|
|
|
|
.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-04-14 08:03:49 +00:00
|
|
|
|
2024-03-20 08:04:13 +00:00
|
|
|
const resp = s3_client.get(obj.bucket, obj.object);
|
|
|
|
if (!resp.success) {
|
|
|
|
log.withFields({bucket: obj.bucket, key: obj.object}).error(resp.error);
|
|
|
|
}
|
2023-04-14 08:03:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function obj_delete() {
|
2024-03-20 08:04:13 +00:00
|
|
|
if (__ENV.SLEEP_DELETE) {
|
|
|
|
sleep(__ENV.SLEEP_DELETE);
|
|
|
|
}
|
2023-04-14 08:03:49 +00:00
|
|
|
|
2024-07-25 15:18:08 +00:00
|
|
|
if (obj_to_delete_selector) {
|
|
|
|
const obj = obj_to_delete_selector.nextObject();
|
|
|
|
if (!obj) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const resp = s3_client.delete(obj.s3_bucket, obj.s3_key);
|
|
|
|
if (!resp.success) {
|
|
|
|
log.withFields({bucket: obj.s3_bucket, key: obj.s3_key, op: 'DELETE'})
|
|
|
|
.error(resp.error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
obj_registry.deleteObject(obj.id);
|
|
|
|
return
|
2024-03-20 08:04:13 +00:00
|
|
|
}
|
2023-04-14 08:03:49 +00:00
|
|
|
|
2024-07-25 15:18:08 +00:00
|
|
|
const obj = obj_list[Math.floor(Math.random() * obj_list.length)];
|
|
|
|
|
|
|
|
const resp = s3_client.delete(obj.bucket, obj.object);
|
2024-03-20 08:04:13 +00:00
|
|
|
if (!resp.success) {
|
2024-07-25 15:18:08 +00:00
|
|
|
log.withFields({bucket: obj.bucket, key: obj.object, op : 'DELETE'}).error(resp.error);
|
2024-03-20 08:04:13 +00:00
|
|
|
}
|
2023-04-14 08:03:49 +00:00
|
|
|
}
|