2022-09-02 19:23:33 +00:00
|
|
|
import datagen from 'k6/x/neofs/datagen';
|
2022-06-23 02:20:56 +00:00
|
|
|
import native from 'k6/x/neofs/native';
|
2022-09-02 19:23:33 +00:00
|
|
|
import registry from 'k6/x/neofs/registry';
|
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 container_list = new SharedArray('container_list', function () {
|
2022-09-02 19:23:33 +00:00
|
|
|
return JSON.parse(open(__ENV.PREGEN_JSON)).containers;
|
|
|
|
});
|
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
|
|
|
./k6 run -e PROFILE=0:60 -e CLIENTS=200 -e WRITE_OBJ_SIZE=1024 \
|
|
|
|
-e GRPC_ENDPOINTS=host1:8080,host2:8080 \
|
|
|
|
-e PREGEN_JSON=test.json \
|
|
|
|
scenarios/grpc.js
|
2022-06-23 02:20:56 +00:00
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
REGISTRY - if set to "enabled", all produced objects will be stored in database for subsequent verification.
|
2022-06-23 02:20:56 +00:00
|
|
|
*/
|
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
// Parse profile from env (format is write:duration)
|
|
|
|
// * write - percent of VUs performing write operations (the rest will be read VUs)
|
|
|
|
// * duration - duration in seconds
|
2022-06-23 02:20:56 +00:00
|
|
|
const [ write, duration ] = __ENV.PROFILE.split(':');
|
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
// Allocate VUs between write and read operations
|
|
|
|
const read_vu_count = Math.ceil(__ENV.CLIENTS / 100 * (100 - parseInt(write)));
|
|
|
|
const write_vu_count = __ENV.CLIENTS - read_vu_count;
|
2022-06-23 02:20:56 +00:00
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
// Select random gRPC endpoint for current VU
|
|
|
|
const grpc_endpoints = __ENV.GRPC_ENDPOINTS.split(',');
|
|
|
|
const grpc_endpoint = grpc_endpoints[Math.floor(Math.random() * grpc_endpoints.length)];
|
|
|
|
const grpc_client = native.connect(grpc_endpoint, '');
|
2022-06-23 02:20:56 +00:00
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
const registry_enabled = (__ENV.REGISTRY || "").toLowerCase() == "enabled"
|
|
|
|
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-02 19:23:33 +00:00
|
|
|
if (write_vu_count > 0) {
|
|
|
|
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
|
|
|
if (read_vu_count > 0) {
|
|
|
|
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',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setup() {
|
2022-09-02 19:23:33 +00:00
|
|
|
console.log("Pregenerated containers: " + container_list.length);
|
|
|
|
console.log("Pregenerated read object size: " + read_size);
|
|
|
|
console.log("Pregenerated total objects: " + obj_list.length);
|
2022-06-23 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const options = {
|
2022-09-02 19:23:33 +00:00
|
|
|
scenarios,
|
2022-06-23 02:20:56 +00:00
|
|
|
setupTimeout: '5s',
|
|
|
|
};
|
|
|
|
|
|
|
|
export function obj_write() {
|
2022-09-02 19:23:33 +00:00
|
|
|
if (__ENV.SLEEP) {
|
|
|
|
sleep(__ENV.SLEEP);
|
2022-06-23 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
const headers = {
|
|
|
|
unique_header: uuidv4()
|
|
|
|
};
|
|
|
|
const container = container_list[Math.floor(Math.random() * container_list.length)];
|
|
|
|
|
|
|
|
const { payload, hash } = generator.genPayload(registry_enabled);
|
|
|
|
let resp = grpc_client.put(container, headers, payload);
|
2022-06-23 02:20:56 +00:00
|
|
|
if (!resp.success) {
|
|
|
|
console.log(resp.error);
|
2022-09-02 19:23:33 +00:00
|
|
|
return;
|
2022-06-23 02:20:56 +00:00
|
|
|
}
|
2022-09-02 19:23:33 +00:00
|
|
|
|
|
|
|
if (registry_enabled) {
|
|
|
|
registry.addObject(container, resp.object_id, "", "", hash);
|
2022-08-10 11:31:03 +00:00
|
|
|
}
|
2022-06-23 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function obj_read() {
|
2022-08-10 11:31:03 +00:00
|
|
|
if (__ENV.SLEEP) {
|
|
|
|
sleep(__ENV.SLEEP);
|
|
|
|
}
|
2022-09-02 19:23:33 +00:00
|
|
|
|
|
|
|
let obj = obj_list[Math.floor(Math.random() * obj_list.length)];
|
|
|
|
let resp = grpc_client.get(obj.container, obj.object)
|
|
|
|
if (!resp.success) {
|
|
|
|
console.log(resp.error);
|
|
|
|
}
|
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
|
|
|
}
|