Files
mtusi2026lab2/bench/k6/explain.js
T
ricoromaandClaude Opus 5.5 e76eed789f feat: run load bench on PostgreSQL with query plans
- bench stand is a separate compose project mtusi-bench (API, Postgres,
  Valkey) with fixed limits, fresh volume per size and migrations
- k6 registers with a password, logs in with Basic and sends Bearer
- VACUUM (ANALYZE) and CHECKPOINT after prefill
- EXPLAIN (ANALYZE, BUFFERS) of the app's history query via auto_explain,
  plus the same query without the index in a rolled back transaction
- Postgres CPU, table and index size in results; storages in passport
- bench_compare checks storage limits, images and settings
- remove inproc.py and make bench_inproc

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-02 01:21:15 +03:00

50 lines
1.8 KiB
JavaScript

// Этап плана: три страницы истории читаемого чата подряд, пока в Postgres
// стенда включён auto_explain. Первая — без курсора, средняя и последняя
// полная — курсоры из пула (середина и конец). Порядок запросов = порядок
// планов в журнале: оркестратор сопоставляет их по нему.
import http from "k6/http";
import { check, fail } from "k6";
import { API, PAGE_LIMIT, WORK_DIR, authHeaders } from "./lib.js";
const fixture = JSON.parse(open(`${WORK_DIR}/fixture.json`));
const pool = JSON.parse(open(`${WORK_DIR}/cursors.json`));
export const options = {
vus: 1,
iterations: 1,
};
export default function () {
const cursors = pool.cursors;
if (cursors.length === 0) {
fail("cursor pool is empty: history is shorter than a walk page");
}
const pages = [
["first", null],
["middle", cursors[Math.floor(cursors.length / 2)]],
["last", cursors[cursors.length - 1]],
];
const url = `${API}/chats/${fixture.readChatId}/messages`;
const params = { headers: authHeaders(fixture.tokens[fixture.readerId]) };
for (const [name, cursor] of pages) {
const query = cursor === null
? `?limit=${PAGE_LIMIT}`
: `?limit=${PAGE_LIMIT}&cursor=${encodeURIComponent(cursor)}`;
const res = http.get(url + query, params);
const ok = check(res, {
[`${name} 200`]: (r) => r.status === 200,
[`${name} full page`]: (r) =>
r.status === 200 && r.json("items.#") === PAGE_LIMIT,
});
if (!ok) {
fail(`explain page ${name}: ${res.status}`);
}
}
}
// итог не нужен: планы оркестратор берёт из журнала Postgres
export function handleSummary() {
return {};
}