feat: limit accepted attachment work and add queue overload bench
Reject uploads with 429 at [uploads] max_unfinished_jobs, counted by the existing partial indexes in the membership block. Add the bench_queue profile, hypotheses H1-H9 and the fifth failure-stand API. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
// Профиль очереди (design change track1-queue-overload, решение 6): открытая
|
||||
// модель загрузок через LB. Окна — сценарии constant-arrival-rate, timeUnit 10 с
|
||||
// для дробной интенсивности; VU заранее и без прибавления: тело — open на VU,
|
||||
// создание на ходу с телом 10 MiB теряет итерации. Ответ не повторяется: 429 —
|
||||
// отказ, недосланные итерации — dropped_iterations. Строка на загрузку
|
||||
// «q,<окно>,<отправка мс>,<длительность мс>,<статус>,<Retry-After>,<X-Instance-Id>,
|
||||
// <id>» — в файл консоли (--console-output); setup() пишет «q-t0,<мс>». WINDOWS —
|
||||
// «имя:интенсивность:секунды:VU», окна идут подряд; WARM=N — N загрузок подряд.
|
||||
import exec from "k6/execution";
|
||||
import http from "k6/http";
|
||||
|
||||
import {
|
||||
API,
|
||||
SUMMARY_THRESHOLDS,
|
||||
SUMMARY_TREND_STATS,
|
||||
WORK_DIR,
|
||||
summaryFiles,
|
||||
} from "./lib.js";
|
||||
|
||||
const fixture = JSON.parse(open(`${WORK_DIR}/fixture.json`));
|
||||
const BODY = open(`${WORK_DIR}/${__ENV.BODY}`, "b");
|
||||
const MEDIA = __ENV.MEDIA;
|
||||
const WARM = Number(__ENV.WARM || 0);
|
||||
const WINDOWS = (__ENV.WINDOWS || "")
|
||||
.split(",")
|
||||
.filter((item) => item !== "")
|
||||
.map((item) => {
|
||||
const [name, rate, seconds, vus] = item.split(":");
|
||||
return {
|
||||
name,
|
||||
rate: Number(rate),
|
||||
seconds: Number(seconds),
|
||||
vus: Number(vus),
|
||||
};
|
||||
});
|
||||
// больше timeout server LB пути загрузки (30 с): клиент видит ответ LB
|
||||
const TIMEOUT = "60s";
|
||||
const URL = `${API}/chats/${fixture.readChatId}/attachments?filename=bench`;
|
||||
const HEADERS = {
|
||||
Authorization: `Bearer ${fixture.tokens[fixture.readerId]}`,
|
||||
"Content-Type": MEDIA,
|
||||
};
|
||||
|
||||
function scenarios() {
|
||||
if (WARM) {
|
||||
return {
|
||||
warm: { executor: "shared-iterations", vus: 1, iterations: WARM },
|
||||
};
|
||||
}
|
||||
const out = {};
|
||||
let start = 0;
|
||||
for (const item of WINDOWS) {
|
||||
out[item.name] = {
|
||||
executor: "constant-arrival-rate",
|
||||
rate: Math.round(item.rate * 10),
|
||||
timeUnit: "10s",
|
||||
startTime: `${start}s`,
|
||||
duration: `${item.seconds}s`,
|
||||
preAllocatedVUs: item.vus,
|
||||
maxVUs: item.vus,
|
||||
gracefulStop: "45s",
|
||||
};
|
||||
start += item.seconds;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export const options = {
|
||||
scenarios: scenarios(),
|
||||
summaryTrendStats: SUMMARY_TREND_STATS,
|
||||
// порог всегда выполняется: итерации попадают в итог, run.py сверяет с ними
|
||||
// число строк
|
||||
thresholds: {
|
||||
...SUMMARY_THRESHOLDS,
|
||||
iterations: ["count>=0"],
|
||||
dropped_iterations: ["count>=0"],
|
||||
},
|
||||
};
|
||||
|
||||
export function setup() {
|
||||
const t0 = Date.now();
|
||||
console.log(`q-t0,${t0}`);
|
||||
return t0;
|
||||
}
|
||||
|
||||
export default function () {
|
||||
const start = Date.now();
|
||||
const res = http.post(URL, BODY, {
|
||||
headers: HEADERS,
|
||||
timeout: TIMEOUT,
|
||||
responseCallback: http.expectedStatuses(202, 429),
|
||||
});
|
||||
const t = res.timings;
|
||||
const measured = t.blocked + t.connecting + t.tls_handshaking + t.duration;
|
||||
const duration = Math.max(
|
||||
0,
|
||||
Math.round(res.status === 0 ? Date.now() - start : measured),
|
||||
);
|
||||
let id = "-";
|
||||
if (res.status === 202) {
|
||||
id = res.json("id");
|
||||
}
|
||||
const retry = res.headers["Retry-After"] || "-";
|
||||
const instance = res.headers["X-Instance-Id"] || "-";
|
||||
console.log(
|
||||
`q,${exec.scenario.name},${start},${duration},${res.status},${retry},` +
|
||||
`${instance},${id}`,
|
||||
);
|
||||
}
|
||||
|
||||
export function handleSummary(data) {
|
||||
return summaryFiles(data);
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
// Обход принятых вложений профиля очереди (design change track1-queue-overload,
|
||||
// решение 9): истина о готовности — метаданные GET /attachments/{id}, опрос в
|
||||
// замере не нужен: updated_at у ready не меняется после фиксации. Строка на
|
||||
// вложение «qs,<id>,<http>,<status>,<error_code>,<variants>,<updated_at>»; у
|
||||
// выборки (первые SAMPLE ids, порядок задал оркестратор от зерна) — оригинал и
|
||||
// варианты с SHA-256 из метаданных: «qv,<id>,<имя>,<1|0>».
|
||||
import { sha256 } from "k6/crypto";
|
||||
import exec from "k6/execution";
|
||||
import http from "k6/http";
|
||||
import { SharedArray } from "k6/data";
|
||||
|
||||
import { API, WORK_DIR, authHeaders, summaryFiles } from "./lib.js";
|
||||
|
||||
const fixture = JSON.parse(open(`${WORK_DIR}/fixture.json`));
|
||||
const ids = new SharedArray("ids", () =>
|
||||
JSON.parse(open(`${WORK_DIR}/${__ENV.IDS}`)),
|
||||
);
|
||||
const SAMPLE = Number(__ENV.SAMPLE || 10);
|
||||
const READER = authHeaders(fixture.tokens[fixture.readerId]);
|
||||
const VARIANTS = ["thumbnail", "crop", "optimized"];
|
||||
|
||||
export const options = {
|
||||
scenarios: {
|
||||
sweep: {
|
||||
executor: "shared-iterations",
|
||||
vus: 4,
|
||||
iterations: Math.max(1, ids.length),
|
||||
maxDuration: "10m",
|
||||
},
|
||||
},
|
||||
thresholds: { iterations: ["count>=0"] },
|
||||
};
|
||||
|
||||
function checkBytes(id, name, expected) {
|
||||
const query = name === "original" ? "" : `?variant=${name}`;
|
||||
const res = http.get(`${API}/attachments/${id}/content${query}`, {
|
||||
headers: READER,
|
||||
responseType: "binary",
|
||||
timeout: "60s",
|
||||
});
|
||||
let good = 0;
|
||||
if (res.status === 200) {
|
||||
good = sha256(res.body, "hex") === expected ? 1 : 0;
|
||||
}
|
||||
console.log(`qv,${id},${name},${good}`);
|
||||
}
|
||||
|
||||
export default function () {
|
||||
const index = exec.scenario.iterationInTest;
|
||||
if (index >= ids.length) {
|
||||
return;
|
||||
}
|
||||
const id = ids[index];
|
||||
const res = http.get(`${API}/attachments/${id}`, {
|
||||
headers: READER,
|
||||
timeout: "30s",
|
||||
responseCallback: http.expectedStatuses(200, 404),
|
||||
});
|
||||
if (res.status !== 200) {
|
||||
console.log(`qs,${id},${res.status},-,-,0,-`);
|
||||
return;
|
||||
}
|
||||
const meta = res.json();
|
||||
const variants = meta.variants || [];
|
||||
console.log(
|
||||
`qs,${id},200,${meta.status},${meta.error_code || "-"},` +
|
||||
`${variants.length},${meta.updated_at}`,
|
||||
);
|
||||
if (index < SAMPLE && meta.status === "ready") {
|
||||
checkBytes(id, "original", meta.sha256);
|
||||
for (const item of variants) {
|
||||
if (VARIANTS.includes(item.name)) {
|
||||
checkBytes(id, item.name, item.sha256);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function handleSummary(data) {
|
||||
return summaryFiles(data);
|
||||
}
|
||||
Reference in New Issue
Block a user