agentleFS
saizulsaizul/nodejs-backend-skills/skills/api-performance/SKILL.md

api-performance

Skill0 starsChanged 3 days agoMITView on GitHub

Performance work on Node.js APIs (Express, Fastify, NestJS, Hono) - reproducible load tests with autocannon, a script that summarises autocannon --json results (req/s, p50/p90/p99/max, error rate, status codes), compares them with a baseline, enforces latency/throughput/error budgets for CI and prints hints (short runs, tail latency, saturation, non-2xx), event loop delay and utilisation monitoring with perf_hooks, and a profiling workflow with --cpu-prof, heap profiles, clinic doctor/flame/bubbleprof and 0x, plus the usual fixes (DB indexes and N+1, blocking sync code, connection reuse, serialization, caching). Use when an endpoint is slow, p99 latency spikes, throughput is too low, the event loop is blocked, CPU or memory is high, or the user wants a load test, a benchmark comparison or a performance budget in CI.

2 other projects use a version of this.

Adopted by

Most recently taken up by

  • Other versions2 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 2

    1. nurmdrafi/pi-native★ 4same name
    2. PMDevSolutions/Nerva★ 1same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository8 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Read the hints: short run, non-2xx, tail latency, saturation.

    line 48

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

API performance

Measure first, change one thing, measure again. Numbers come from the same command and dataset each time, and the summary script turns them into a comparison you can trust.

Paths below are relative to this skill's folder (in Claude Code: ${CLAUDE_SKILL_DIR}).

When to use

  • "This endpoint is slow", "p99 spikes", "we can only do N requests/s"
  • "Load test / benchmark my API", "did this PR make it slower?"
  • High CPU, event loop lag, memory growth, GC pauses
  • Adding a performance budget to CI

When not to use

  • Front-end performance (Core Web Vitals): different tooling
  • Load testing production or third-party systems: do not, unless the owner approves in writing
  • Long-running async work that should not be in the request at all: background-jobs
  • Logging/tracing setup itself: logging-and-tracing

Workflow

  1. Define the question and the target. Which endpoint, what payload, expected concurrency, and the budget (e.g. p99 < 200 ms at 500 req/s, errors < 0.1%).
  2. Prepare a fair test. Production build, realistic data, same Node major as prod, load generator not competing for the same cores. Confirm the endpoint returns 2xx with curl -i (auth headers, body).
  3. Run a baseline (the user runs it, or you with permission; it targets their server):
    npx autocannon -c 50 -d 30 -w 5 --title "GET /products" http://localhost:3000/products --json > before.json
  4. Summarise.
    python3 scripts/autocannon_summary.py before.json
    python3 scripts/autocannon_summary.py before.json --max-p99 200 --min-rps 500 --max-error-rate 0.1
    Read the hints: short run, non-2xx, tail latency, saturation.
  5. Find the cause. Pick the tool from the symptom table in references/profiling.md: --cpu-prof or clinic flame for CPU, clinic doctor for event loop delay, bubbleprof/traces for waiting, heap snapshots for memory. Add assets/event-loop-monitor.mjs to see event loop delay in production logs.
  6. Fix one thing (common fixes, in payoff order, are at the end of the profiling reference): queries and indexes, blocking sync work, connection reuse, serialization, caching. Show the diff and get approval.
  7. Compare.
    npx autocannon -c 50 -d 30 -w 5 --title "GET /products" http://localhost:3000/products --json > after.json
    python3 scripts/autocannon_summary.py after.json --baseline before.json --max-regression 5 --markdown
    Exit 1 when a budget is broken or req/s drops / p99 rises more than --max-regression %.
  8. Lock it in (optional): a CI job that starts the app, runs autocannon and fails on budgets. Mark it as indicative on shared CI runners (noisy neighbours).

Output

GET /products  (50 conns, 30s): 4200 -> 6900 req/s (+64%), p99 24 -> 11 ms
Cause: N+1 query (1 + 50 SELECTs per page) found in the CPU profile/trace
Fix: single query with JOIN + index on products(category_id, created_at)
POST /orders: p99 310 ms > budget 200 ms, 41 x 503 -> pool exhausted (pg max 10, 50 conns); next step
| Run | req/s | p50 ms | p90 ms | p99 ms | max ms | errors % | status |
| GET /products | 6900 (+64.3%) | 6 | 8 | 11 (-54.2%) | 40 | 0.0 | ok |

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.