From 67a14e341c4005eb66f1a55fc2785d6cec98923b Mon Sep 17 00:00:00 2001 From: Csaky Date: Thu, 20 Apr 2023 16:57:01 -0700 Subject: [PATCH] Removed index on object.bucketId; tidy up K6 code --- .../20230420000000_005-permission-indexes.js | 8 ------ {app/tests/k6 => k6}/createObject.js | 25 ++++++++----------- {app/tests/k6 => k6}/readObject.js | 9 ++++--- {app/tests/k6 => k6}/searchObject.js | 8 +++--- 4 files changed, 19 insertions(+), 31 deletions(-) rename {app/tests/k6 => k6}/createObject.js (59%) rename {app/tests/k6 => k6}/readObject.js (84%) rename {app/tests/k6 => k6}/searchObject.js (77%) diff --git a/app/src/db/migrations/20230420000000_005-permission-indexes.js b/app/src/db/migrations/20230420000000_005-permission-indexes.js index e95b44cd..59b16c5a 100644 --- a/app/src/db/migrations/20230420000000_005-permission-indexes.js +++ b/app/src/db/migrations/20230420000000_005-permission-indexes.js @@ -9,19 +9,11 @@ exports.up = function (knex) { .then(() => knex.schema.alterTable('object_permission', table => { table.uuid('objectId').index().notNullable().alter(); table.uuid('userId').index().notNullable().alter(); - })) - // Add index to object.bucketId - .then(() => knex.schema.alterTable('object', table => { - table.uuid('bucketId').index().alter(); })); }; exports.down = function (knex) { return Promise.resolve() - // Remove index on object.bucketId - .then(() => knex.schema.alterTable('object', table => { - table.dropIndex('bucketId'); - })) // Remove index on object_permission.userId and object_permission.objectId .then(() => knex.schema.alterTable('object_permission', table => { table.dropIndex('userId'); diff --git a/app/tests/k6/createObject.js b/k6/createObject.js similarity index 59% rename from app/tests/k6/createObject.js rename to k6/createObject.js index acc4bee9..ebfa7bbd 100644 --- a/app/tests/k6/createObject.js +++ b/k6/createObject.js @@ -1,14 +1,12 @@ import http from 'k6/http'; import { check, sleep } from 'k6'; -// multipart file uploads - https://k6.io/docs/examples/data-uploads/#multipart-request-uploading-a-file - // k6 options (https://k6.io/docs/using-k6/k6-options/) export const options = { scenarios: { createObject: { executor: 'constant-arrival-rate', - rate: 20, // this is per-second, see "timeUnit" below + rate: 5, // this is per-second, see "timeUnit" below timeUnit: '1s', preAllocatedVUs: 1, maxVUs: 1, @@ -17,36 +15,33 @@ export const options = { }, }; -// give objects random tags +const apiPath = 'http://localhost:3000/api/v1'; const randomLetter = String.fromCharCode(65 + Math.floor(Math.random() * 26)); +const bucketId = ''; +const url = `${apiPath}/object?bucketId=${bucketId}&tagset[${randomLetter}]=${randomLetter}`; -// request url -const url = 'http://localhost:3000/api/v1/object?tagset[' + randomLetter + ']=' + randomLetter; - -// open() the file as binary (with the 'b' argument). +// open() the file as binary (with the 'b' argument, must be declared in init scope) +// ref: https://k6.io/docs/examples/data-uploads/#multipart-request-uploading-a-file +// eslint-disable-next-line const binFile = open('./file-in-cur-dir.txt', 'b'); // run k6 export default function () { const data = { // attach file, specify file name and content type - file: http.file(binFile, 'name-given-to-file.txt', 'text/plain'), - field: 'another form field' + file: http.file(binFile, 'abc.txt', 'text/plain') }; - // make the http request const res = http.post(url, data, { // add headers headers: { - 'Authorization': 'Bearer ' + 'Authorization': 'Bearer ' } }); - // tests check(res, { 'is status 201': (r) => r.status === 201, - }) - + }); // optional delay (per VU) between iterations sleep(1); } diff --git a/app/tests/k6/readObject.js b/k6/readObject.js similarity index 84% rename from app/tests/k6/readObject.js rename to k6/readObject.js index 81b325ef..5093f283 100644 --- a/app/tests/k6/readObject.js +++ b/k6/readObject.js @@ -7,7 +7,7 @@ export const options = { scenarios: { readObject: { executor: 'constant-arrival-rate', - rate: 50, + rate: 20, duration: '20s', preAllocatedVUs: 50, timeUnit: '1s', @@ -19,8 +19,10 @@ export const options = { // run k6 export default function () { + const apiPath = 'http://localhost:3000/api/v1'; // request url - const url = 'http://localhost:3000/api/v1/object/'; + const url = `${apiPath}/object/`; + const params = { headers: { 'Authorization': 'Bearer ', @@ -33,8 +35,7 @@ export default function () { // tests check(res, { 'is status 200': (r) => r.status === 200, - }) - + }); // optional delay (per VU) between iterations sleep(1); } diff --git a/app/tests/k6/searchObject.js b/k6/searchObject.js similarity index 77% rename from app/tests/k6/searchObject.js rename to k6/searchObject.js index 112f8bc1..51cd93c5 100644 --- a/app/tests/k6/searchObject.js +++ b/k6/searchObject.js @@ -13,11 +13,12 @@ export const options = { export default function () { - // search by random tags + const apiPath = 'http://localhost:3000/api/v1'; const randomLetter = String.fromCharCode(65 + Math.floor(Math.random() * 26)); + const bucketId = ''; // request url - const url = 'http://localhost:3000/api/v1/object?latest=true&deleteMarker=false&tagset[' + randomLetter + ']=' + randomLetter; + const url = `${apiPath}/object?bucketId=${bucketId}&latest=true&deleteMarker=false&tagset[${randomLetter}]=${randomLetter}`; // Add Authorization header const params = { @@ -32,8 +33,7 @@ export default function () { // tests check(res, { 'is status 200': (r) => r.status === 200, - }) - + }); // optional delay (per VU) between iterations sleep(1); }