Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load tests: Accept brotli compressed data #653

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/load-tests/tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
"@itwin/presentation-models-tree": "workspace:*",
"@itwin/presentation-shared": "workspace:*",
"@types/artillery": "^1.7.4",
"@types/brotli": "^1.3.4",
"@types/node": "^20.12.12",
"artillery": "2.0.15",
"brotli": "^1.3.3",
"eslint": "^8.57.0",
"rimraf": "^5.0.5",
"rxjs": "^7.8.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ config:
processor: "../lib/processors/models-tree-stateless.js"

scenarios:
- name: Full Models Tree (stateless)
- name: First branch Models Tree (stateless)
beforeScenario: "initScenario"
afterScenario: "terminateScenario"
flow:
Expand Down
87 changes: 45 additions & 42 deletions apps/load-tests/tests/src/processors/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/* eslint-disable no-console */

import { EventEmitter, ScenarioContext } from "artillery";
import { decompress as brotliDecompress } from "brotli";
import * as http from "node:http";
import * as https from "node:https";
import * as path from "path";
Expand Down Expand Up @@ -58,32 +59,16 @@ export async function openIModelConnectionIfNeeded() {
while (!connection) {
try {
await new Promise((resolve, reject) => {
const activityId = Guid.createValue();
let responseBody = "";
const req = BACKEND_PROPS.httpApi.request(
{
agent: BACKEND_PROPS.agent,
hostname: BACKEND_PROPS.hostname,
port: BACKEND_PROPS.port,
path: `${BACKEND_PROPS.createPath("IModelReadRpcInterface-3.6.0-getConnectionProps")}?parameters=W3siaVR3aW5JZCI6Ijg5MmFhMmM5LTViZTgtNDg2NS05ZjM3LTdkNGM3ZTc1ZWJiZiIsImlNb2RlbElkIjoiZWQwYzQwOGItYWRkMi00OTZlLWFjNTgtNWE3ZTg1M2NiYzBiIiwiY2hhbmdlc2V0Ijp7ImluZGV4Ijo2OSwiaWQiOiIyN2JlMTZkOTU5NjQ1OTg1ZmNhODBjZmY1MDJiZDIzN2I4MmYwZjg0In19XQ==`,
method: "get",
headers: {
["X-Session-Id"]: sessionId,
["X-Correlation-Id"]: activityId,
["Content-Type"]: "text/plain",
["Authorization"]: `Bearer ${BACKEND_PROPS.authToken}`,
},
},
(response) => {
response.setEncoding("utf8");
response.on("data", (chunk) => {
responseBody += chunk;
});
response.on("end", () => {
resolve(JSON.parse(responseBody));
});
response.once("error", reject);
headers: createRequestHeaders(),
},
(response) => handleResponse(response, resolve, reject),
);
req.once("error", reject);
req.end();
Expand All @@ -99,39 +84,26 @@ export async function doRequest(operation: string, body: string, events: EventEm
events.emit("rate", "http.request_rate");
events.emit("counter", "http.requests", 1);
events.emit("counter", `itwin.${reqName}.requests`, 1);
const activityId = Guid.createValue();
const timer = new StopWatch(undefined, true);
let responseBody = "";
const req = BACKEND_PROPS.httpApi.request(
{
agent: BACKEND_PROPS.agent,
hostname: BACKEND_PROPS.hostname,
port: BACKEND_PROPS.port,
path: BACKEND_PROPS.createPath(operation),
method: "post",
headers: {
["X-Session-Id"]: sessionId,
["X-Correlation-Id"]: activityId,
["Content-Type"]: "text/plain",
["Authorization"]: `Bearer ${BACKEND_PROPS.authToken}`,
},
},
(response) => {
response.setEncoding("utf8");
response.on("data", (chunk) => {
responseBody += chunk;
});
response.on("end", () => {
events.emit("histogram", "http.response_time", timer.current.milliseconds);
events.emit("histogram", `itwin.${reqName}.response_time`, timer.current.milliseconds);
if (response.statusCode && response.statusCode.toString().startsWith("2")) {
resolve(JSON.parse(responseBody));
} else {
reject(responseBody);
}
});
response.once("error", reject);
headers: createRequestHeaders(),
},
(response) =>
handleResponse(
response,
(value) => {
events.emit("histogram", "http.response_time", timer.current.milliseconds);
events.emit("histogram", `itwin.${reqName}.response_time`, timer.current.milliseconds);
resolve(value);
},
reject,
),
);
req.on("socket", (socket) => {
if (socket.listenerCount("connect") > 0) {
Expand All @@ -147,6 +119,37 @@ export async function doRequest(operation: string, body: string, events: EventEm
req.end();
});
}
function createRequestHeaders() {
return {
["X-Session-Id"]: sessionId,
["X-Correlation-Id"]: Guid.createValue(),
["Accept-Encoding"]: "br",
["Content-Type"]: "text/plain",
["Authorization"]: `Bearer ${BACKEND_PROPS.authToken}`,
};
}
function handleResponse(response: http.IncomingMessage, resolve: (value: any) => void, reject: (reason: any) => void) {
const chunks: Uint8Array[] = [];
response.on("data", (chunk) => {
chunks.push(chunk);
});
response.on("end", () => {
const buffer = Buffer.concat(chunks);
chunks.length = 0;
const responseBody = (function () {
if (response.headers["content-encoding"] === "br") {
return Buffer.from(brotliDecompress(buffer)).toString("utf8");
}
return buffer.toString();
})();
if (!response.statusCode || !response.statusCode.toString().startsWith("2")) {
reject(responseBody);
return;
}
resolve(JSON.parse(responseBody));
});
response.once("error", reject);
}

export function getCurrentIModelPath(context: ScenarioContext) {
return (context.vars.$loopElement as any)[0] as string;
Expand Down
Loading
Loading