2022-12-29 14:52:55 +00:00
|
|
|
import datagen from 'k6/x/frostfs/datagen';
|
|
|
|
import registry from 'k6/x/frostfs/registry';
|
|
|
|
import s3 from 'k6/x/frostfs/s3';
|
2022-06-23 02:20:56 +00:00
|
|
|
import { SharedArray } from 'k6/data';
|
2022-08-10 11:31:03 +00:00
|
|
|
import { sleep } from 'k6';
|
2022-06-23 02:20:56 +00:00
|
|
|
|
|
|
|
const obj_list = new SharedArray('obj_list', function () {
|
2022-09-02 19:23:33 +00:00
|
|
|
return JSON.parse(open(__ENV.PREGEN_JSON)).objects;
|
|
|
|
});
|
2022-06-23 02:20:56 +00:00
|
|
|
|
|
|
|
const bucket_list = new SharedArray('bucket_list', function () {
|
2022-09-02 19:23:33 +00:00
|
|
|
return JSON.parse(open(__ENV.PREGEN_JSON)).buckets;
|
|
|
|
});
|
2022-06-23 02:20:56 +00:00
|
|
|
|
|
|
|
const read_size = JSON.parse(open(__ENV.PREGEN_JSON)).obj_size;
|
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
// Select random S3 endpoint for current VU
|
|
|
|
const s3_endpoints = __ENV.S3_ENDPOINTS.split(',');
|
|
|
|
const s3_endpoint = s3_endpoints[Math.floor(Math.random() * s3_endpoints.length)];
|
|
|
|
const s3_client = s3.connect(`http://${s3_endpoint}`);
|
2023-02-16 15:42:45 +00:00
|
|
|
const log = logging.new().withField("endpoint", s3_endpoint);
|
2022-06-23 02:20:56 +00:00
|
|
|
|
2022-09-21 05:45:23 +00:00
|
|
|
const registry_enabled = !!__ENV.REGISTRY_FILE;
|
|
|
|
const obj_registry = registry_enabled ? registry.open(__ENV.REGISTRY_FILE) : undefined;
|
|
|
|
|
2022-09-27 16:01:43 +00:00
|
|
|
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",
|
2022-11-10 06:23:33 +00:00
|
|
|
__ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0,
|
2022-09-27 16:01:43 +00:00
|
|
|
{
|
|
|
|
status: "created",
|
|
|
|
age: delete_age,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
const generator = datagen.generator(1024 * parseInt(__ENV.WRITE_OBJ_SIZE));
|
2022-06-23 02:20:56 +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');
|
|
|
|
if (write_vu_count > 0) {
|
2022-09-02 19:23:33 +00:00
|
|
|
scenarios.write = {
|
2022-06-23 02:20:56 +00:00
|
|
|
executor: 'constant-vus',
|
2022-09-02 19:23:33 +00:00
|
|
|
vus: write_vu_count,
|
2022-06-23 02:20:56 +00:00
|
|
|
duration: `${duration}s`,
|
|
|
|
exec: 'obj_write',
|
|
|
|
gracefulStop: '5s',
|
2022-09-02 19:23:33 +00:00
|
|
|
};
|
2022-06-23 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
2022-09-27 16:01:43 +00:00
|
|
|
const read_vu_count = parseInt(__ENV.READERS || '0');
|
|
|
|
if (read_vu_count > 0) {
|
2022-09-02 19:23:33 +00:00
|
|
|
scenarios.read = {
|
2022-06-23 02:20:56 +00:00
|
|
|
executor: 'constant-vus',
|
2022-09-02 19:23:33 +00:00
|
|
|
vus: read_vu_count,
|
2022-06-23 02:20:56 +00:00
|
|
|
duration: `${duration}s`,
|
|
|
|
exec: 'obj_read',
|
|
|
|
gracefulStop: '5s',
|
2022-09-02 19:23:33 +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) {
|
2022-10-26 16:08:45 +00:00
|
|
|
if (!obj_to_delete_selector) {
|
|
|
|
throw 'Positive DELETE worker number without a proper object selector';
|
|
|
|
}
|
|
|
|
|
2022-09-27 16:01:43 +00:00
|
|
|
scenarios.delete = {
|
|
|
|
executor: 'constant-vus',
|
|
|
|
vus: delete_vu_count,
|
|
|
|
duration: `${duration}s`,
|
|
|
|
exec: 'obj_delete',
|
|
|
|
gracefulStop: '5s',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export const options = {
|
|
|
|
scenarios,
|
|
|
|
setupTimeout: '5s',
|
|
|
|
};
|
|
|
|
|
2022-06-23 02:20:56 +00:00
|
|
|
export function setup() {
|
2022-09-27 16:01:43 +00:00
|
|
|
const total_vu_count = write_vu_count + read_vu_count + delete_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(`Deleting VUs: ${delete_vu_count}`);
|
|
|
|
console.log(`Total VUs: ${total_vu_count}`);
|
2022-06-23 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
2022-09-21 05:45:23 +00:00
|
|
|
export function teardown(data) {
|
|
|
|
if (obj_registry) {
|
|
|
|
obj_registry.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-23 02:20:56 +00:00
|
|
|
export function obj_write() {
|
2022-08-11 13:56:39 +00:00
|
|
|
if (__ENV.SLEEP_WRITE) {
|
|
|
|
sleep(__ENV.SLEEP_WRITE);
|
2022-06-23 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
const key = __ENV.OBJ_NAME || uuidv4();
|
|
|
|
const bucket = bucket_list[Math.floor(Math.random() * bucket_list.length)];
|
2022-09-02 19:23:33 +00:00
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
const { payload, hash } = generator.genPayload(registry_enabled);
|
|
|
|
const resp = s3_client.put(bucket, key, payload);
|
2022-06-23 02:20:56 +00:00
|
|
|
if (!resp.success) {
|
2023-02-16 15:42:45 +00:00
|
|
|
log.info(resp.error);
|
2022-09-02 19:23:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-08-10 11:31:03 +00:00
|
|
|
|
2022-09-21 05:45:23 +00:00
|
|
|
if (obj_registry) {
|
|
|
|
obj_registry.addObject("", "", bucket, key, hash);
|
2022-08-10 11:31:03 +00:00
|
|
|
}
|
2022-06-23 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function obj_read() {
|
2022-08-11 13:56:39 +00:00
|
|
|
if (__ENV.SLEEP_READ) {
|
|
|
|
sleep(__ENV.SLEEP_READ);
|
2022-08-10 11:31:03 +00:00
|
|
|
}
|
2022-06-23 02:20:56 +00:00
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
const obj = obj_list[Math.floor(Math.random() * obj_list.length)];
|
|
|
|
|
|
|
|
const resp = s3_client.get(obj.bucket, obj.object);
|
|
|
|
if (!resp.success) {
|
2023-02-16 15:42:45 +00:00
|
|
|
log.info(resp.error);
|
2022-09-02 19:23:33 +00:00
|
|
|
}
|
2022-06-23 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
2022-09-27 16:01:43 +00:00
|
|
|
export function obj_delete() {
|
2022-08-11 13:56:39 +00:00
|
|
|
if (__ENV.SLEEP_DELETE) {
|
|
|
|
sleep(__ENV.SLEEP_DELETE);
|
2022-09-27 16:01:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const obj = obj_to_delete_selector.nextObject();
|
|
|
|
if (!obj) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const resp = s3_client.delete(obj.s3_bucket, obj.s3_key);
|
|
|
|
if (!resp.success) {
|
2023-02-16 15:42:45 +00:00
|
|
|
log.info(`Error deleting object ${obj.id}: ${resp.error}`);
|
2022-09-27 16:01:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
obj_registry.deleteObject(obj.id);
|
|
|
|
}
|
|
|
|
|
2022-06-23 02:20:56 +00:00
|
|
|
export function uuidv4() {
|
|
|
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
2022-09-02 19:23:33 +00:00
|
|
|
let r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
|
|
return v.toString(16);
|
2022-06-23 02:20:56 +00:00
|
|
|
});
|
2022-09-02 19:23:33 +00:00
|
|
|
}
|