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>
This commit is contained in:
2026-10-02 01:21:15 +03:00
co-authored by Claude Opus 5.5
parent 5582302d68
commit e76eed789f
23 changed files with 2443 additions and 1084 deletions
+28 -9
View File
@@ -1,5 +1,6 @@
// Общие хелперы сценариев стенда: адрес, идентификация, текст, генератор
// случайных чисел, запись итога. Не Node.js: только встроенные модули k6.
import encoding from "k6/encoding";
import http from "k6/http";
import { check, fail } from "k6";
@@ -20,9 +21,18 @@ export const SUCCESS_DURATION = "http_req_duration{expected_response:true}";
// порог всегда выполняется: он нужен, чтобы подметрика попала в итог
export const SUMMARY_THRESHOLDS = { [SUCCESS_DURATION]: ["max>=0"] };
// идентификация лабы 1; с лабы 2 здесь Bearer, как Actor.headers()
export function authHeaders(userId) {
return { "X-User-Id": userId, "Content-Type": "application/json" };
// идентификация, как Actor.headers() в student-tests: Bearer-токен сессии
export function authHeaders(token) {
return {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
};
}
// синтетический пароль (72 символа, контракт — 12–128): только в памяти
// prepare.js, в фикстуру и результаты не попадает
function syntheticPassword() {
return `${crypto.randomUUID()}-${crypto.randomUUID()}`;
}
// синтетический текст ровно TEXT_LENGTH ASCII-символов
@@ -43,23 +53,32 @@ export function mulberry32(seed) {
};
}
// регистрация с паролем и вход по Basic: { id, token } пользователя
export function register(username, displayName) {
const password = syntheticPassword();
const res = http.post(
`${API}/users`,
JSON.stringify({ username, display_name: displayName }),
JSON.stringify({ username, display_name: displayName, password }),
{ headers: { "Content-Type": "application/json" } },
);
if (!check(res, { "register 201": (r) => r.status === 201 })) {
fail(`register ${username}: ${res.status} ${res.body}`);
}
return res.json("id");
const basic = encoding.b64encode(`${username}:${password}`);
const login = http.post(`${API}/auth/sessions`, null, {
headers: { Authorization: `Basic ${basic}` },
});
if (!check(login, { "login 201": (r) => r.status === 201 })) {
fail(`login ${username}: ${login.status} ${login.body}`);
}
return { id: res.json("id"), token: login.json("token") };
}
export function createChat(ownerId, title, memberIds) {
export function createChat(ownerToken, title, memberIds) {
const res = http.post(
`${API}/chats`,
JSON.stringify({ title, member_ids: memberIds }),
{ headers: authHeaders(ownerId) },
{ headers: authHeaders(ownerToken) },
);
if (!check(res, { "chat 201": (r) => r.status === 201 })) {
fail(`create chat ${title}: ${res.status} ${res.body}`);
@@ -67,12 +86,12 @@ export function createChat(ownerId, title, memberIds) {
return res.json("id");
}
export function sendMessage(chatId, senderId, text) {
export function sendMessage(chatId, senderToken, text) {
const res = http.post(
`${API}/chats/${chatId}/messages`,
JSON.stringify({ text }),
{
headers: authHeaders(senderId),
headers: authHeaders(senderToken),
responseCallback: http.expectedStatuses(201),
},
);