forked from mtusi2026/mtusi2026lab5
Перенесено дерево lab4 целиком: NestJS-приложение с вложениями и S3,
Dockerfile, compose.yaml, infra/{haproxy,minio}, стендовые скрипты,
scripts/lab4, evidence/lab4 и contracts/extensions.openapi.json.
Задание lab5 оставлено своим: README, REPORT, COURSE, lab.json,
contracts/{openapi,infrastructure,jobs.schema,attachment-states,examples},
tests, compose.example.yaml, .github/pull_request_template.md.
Адаптации при переносе:
- docker-проект mtusi-lab4 -> mtusi-lab5 и тег образа mtusi-messenger:lab5,
чтобы тома и контейнеры не пересекались с lab4 (scripts/stop-one.sh:
LAB_PROJECT вместо LAB4_PROJECT);
- Makefile: цели lab5 сохранены, добавлены стендовые (stand-up/down,
wait-ready, init-env, test-e2e, test-dependencies, s3-security,
consistency, bench);
- .env.example: реальные переменные приложения и стенда lab4 (без них
compose.yaml не поднимается) + блок lab5 (BROKER_URL_FILE, WORKER_*).
34 lines
1.5 KiB
JavaScript
34 lines
1.5 KiB
JavaScript
// Peak RSS of one full decode check with the same sharp pipeline as
|
|
// app/src/attachments/image/image-decoder.ts, on worst-case inputs near
|
|
// MAX_IMAGE_PIXELS. Runs where the API runs (same libvips, VIPS_DISC_THRESHOLD):
|
|
// docker compose exec -T api node - < scripts/lab4/decode_memory.mjs # reads files from IMAGES (paths in the container)
|
|
// or on the host from app/: IMAGES="a.png b.jpg" node ../scripts/lab4/decode_memory.mjs
|
|
import { readFileSync } from 'node:fs';
|
|
import { createRequire } from 'node:module';
|
|
|
|
const sharp = createRequire(`${process.cwd()}/`)('sharp');
|
|
sharp.cache(false);
|
|
sharp.concurrency(1);
|
|
for (const file of (process.env.IMAGES ?? '').split(/\s+/u).filter(Boolean)) {
|
|
const data = readFileSync(file);
|
|
const meta = await sharp(data).metadata();
|
|
const base = process.memoryUsage().rss;
|
|
let peak = base;
|
|
const timer = setInterval(() => {
|
|
peak = Math.max(peak, process.memoryUsage().rss);
|
|
}, 5);
|
|
const started = Date.now();
|
|
let verdict = 'ok';
|
|
try {
|
|
await sharp(data, { failOn: 'warning', sequentialRead: true, limitInputPixels: 40_000_000 })
|
|
.resize(64, 64, { fit: 'inside' })
|
|
.toBuffer();
|
|
} catch (error) {
|
|
verdict = `rejected: ${String(error.message).split('\n')[0]}`;
|
|
}
|
|
clearInterval(timer);
|
|
console.log(
|
|
`${meta.format} ${meta.width}x${meta.height} ${meta.channels}ch ${meta.depth}${meta.isProgressive ? ' progressive' : ''}${meta.isPalette ? ' palette' : ''} bytes=${data.length} decode_ms=${Date.now() - started} peak_delta_rss_mib=${((peak - base) / 1048576).toFixed(1)} ${verdict}`,
|
|
);
|
|
}
|