Skip to Content
PDFRender concurrency

Render concurrency

FIFO semaphore limiting concurrent Puppeteer renders per Node process.

Module: @sumx/ssr-pdf/pdf-render-slot

Why it exists

Each PDF request can spawn Chromium work. Without a cap, traffic spikes create unbounded processes and OOM kills. The slot queue bounds active renders and queues the rest.

API

import { acquirePdfRenderSlot, releasePdfRenderSlot } from '@sumx/ssr-pdf/pdf-render-slot'; await acquirePdfRenderSlot(); try { // puppeteer render } finally { releasePdfRenderSlot(); }

The API route handler calls these automatically — you rarely invoke them directly unless building a custom pipeline.

Behavior

  • Default max concurrent: 2
  • Env override: HTML_TO_PDF_MAX_CONCURRENT (18, invalid → 2)
  • Extra requests wait (FIFO), not rejected
  • Per-process only — scale horizontally with multiple replicas for throughput

Tuning

DeploymentSuggested value
Local dev2 (default)
Small container (512MB–1GB)12
PDF-heavy worker with 2GB+34

Monitor memory and p95 latency when increasing.

Custom usage

If you add a second PDF entry point, always pair acquire/release in finally to avoid deadlocking the queue.