bedkillerspacex-boop/codex-skill-library/uvicorn-gunicorn-workers

Claude Code and agent skill by bedkillerspacex-boop/codex-skill-library

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Size and run Uvicorn/Gunicorn workers for owned Python ASGI apps: worker classes, counts vs CPU, timeouts, keepalive, graceful reload, memory limits, and health checks. Use when tuning FastAPI/Starlette deployments — not for attacking third-party services.

Install

npx vskill@latest install bedkillerspacex-boop/codex-skill-library/uvicorn-gunicorn-workers

SKILL.md

The same SKILL.md was published earlier as bedkillerspacex-boop/codex-skill-library/uvicorn-gunicorn-workers.

Uvicorn / Gunicorn Worker Sizing

Scope And Authorization

  • In scope: Process model tuning for ASGI apps you operate (Uvicorn, Gunicorn+UvicornWorker, Hypercorn).
  • Out of scope: Load testing third-party sites without authorization.
  • Change worker counts in staging first; watch memory before production scale-out.
  • Pair with observability skills and code-quality-standards.

When To Use

  • Choosing between pure Uvicorn multi-process vs Gunicorn managing UvicornWorkers.
  • High latency/timeouts, OOM kills, or uneven CPU under load.
  • Setting timeout, graceful_timeout, keep-alive, limit_concurrency.
  • Container CPU/memory requests aligned to worker math.

Do Not Use As Primary

NeedSkill instead
App-level auth/security reviewweb security skills
Reverse proxy cachingvarnish-vcl-basics / CDN skills
vLLM GPU servingvllm-serving-hardening
Generic observabilityobservability-metrics-tracing
Implementation quality baselinecode-quality-standards

Domain Focus

SettingGuidance
Worker classuvicorn.workers.UvicornWorker under Gunicorn for ASGI
Worker countStart ~ (2 x CPU) + 1 for sync-ish; for async often fewer (1–2 per core) + concurrency limits
ThreadsPrefer async concurrency over many threads for pure ASGI
Timeout≥ longest expected request; smaller than LB idle timeout carefully
Max requestsRecycle workers to mitigate leaks (max_requests + jitter)
PitfallsToo many workers × large models = OOM; blocking CPU work in async handlers

Process Topology

ModeCommand sketchNotes
Uvicorn onlyuvicorn app:app --host 0.0.0.0 --port 8000 --workers NSimple
Gunicorn+Uvicorngunicorn app:app -k uvicorn.workers.UvicornWorker -w NBetter process mgmt
Single worker + concurrency--workers 1 --limit-concurrency CHigh async I/O

Workflow

1. Confirm scope and success criteria
  1. Record app type (I/O bound vs CPU), container CPU/memory, SLOs (p95 latency, error rate).
  2. Success: stable p95 under target RPS; no OOM; clean rolling deploys; health checks pass.
  3. Rollback: previous worker env vars / deployment revision.
2. Inventory current runtime
bash
ps aux | rg -i 'uvicorn|gunicorn'
# In container
cat /proc/cpuinfo | rg processor | wc -l
free -h
# App entry
rg -n "uvicorn|gunicorn|UvicornWorker" Dockerfile docker-compose.yml Procfile
  1. Note blocking libraries (PDF, numpy heavy) inside request path.
  2. Check proxy timeouts (nginx/ALB) vs app timeout.
3. Baseline metrics
  1. Under representative load: CPU, RSS per worker, event loop lag, queue time.
  2. Capture 5xx rate and timeout count.
  3. Measure startup time × worker count (deploy readiness).
4. Apply sizing changes

Gunicorn config example:

python
# gunicorn.conf.py
import multiprocessing
bind = "0.0.0.0:8000"
worker_class = "uvicorn.workers.UvicornWorker"
workers = int(os.getenv("WEB_CONCURRENCY", min(4, multiprocessing.cpu_count())))
timeout = 60
graceful_timeout = 30
keepalive = 5
max_requests = 1000
max_requests_jitter = 100
accesslog = "-"
errorlog = "-"

Uvicorn CLI:

bash
uvicorn app:app --host 0.0.0.0 --port 8000 \
--workers "${WEB_CONCURRENCY:-2}" \
--timeout-keep-alive 5 \
--limit-concurrency 100 \
--limit-max-requests 1000
  1. Align K8s resources.limits.memory ≥ workers × peak_rss × headroom.
  2. Move CPU-heavy work to task queue; keep request path async I/O.
  3. Use separate deployment for WebSockets if sticky sessions / long lived connections differ.
  4. Prefer graceful shutdown: handle SIGTERM, stop accepting, drain.
5. Verify with evidence
bash
# Load against owned staging only
hey -z 60s -c 50 https://staging.example/health
# Watch
# - worker RSS stable
# - p95 within SLO
# - no restart loop
curl -sf http://127.0.0.1:8000/health
  1. Rolling update: readiness fails until workers listen.
  2. Kill -TERM master: connections drain within graceful_timeout.
  3. Memory: scale workers until OOM then back off one.
6. Observe and harden
  1. Metrics: request duration, in-flight, worker restarts, RSS.
  2. Alert on restart loops and timeout ratio.
  3. Revisit after traffic shape changes (batch uploads vs chatty API).
7. Hand off
  1. Document WEB_CONCURRENCY formula for the service.
  2. Runbook: OOM → reduce workers / raise memory / find leak.
  3. Apply code-quality-standards to app code causing blocks.

Good / Bad

TopicGoodBad
WorkersMatch CPU + memory budgetworkers=32 in 512Mi pod
AsyncNon-blocking I/Otime.sleep / heavy CPU in handler
TimeoutsApp < proxy idle with marginDefault 30s with 5min uploads
Recyclemax_requests + jitterNever recycle leaking workers
HealthCheap /healthHealth hits DB every time without need

Output Checklist

  • [ ] Workload shape and CPU/mem recorded
  • [ ] Topology chosen (uvicorn vs gunicorn)
  • [ ] Worker count and concurrency justified
  • [ ] Timeouts aligned with proxy
  • [ ] Memory headroom verified under load
  • [ ] Graceful shutdown tested
  • [ ] Metrics/alerts in place
  • [ ] Staging evidence attached
  • [ ] code-quality-standards applied
  • [ ] Residual risk noted

Rules

  • Load test only owned environments.
  • Prefer evidence from metrics over cargo-cult formulas alone.
  • Do not hide app blocking bugs by endless worker scale-out.
  • Keep secrets out of process listings and logs.
  • Focus on worker sizing and process model for Uvicorn/Gunicorn.

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/bedkillerspacex-boop/codex-skill-library/uvicorn-gunicorn-workers/badge)](https://verified-skill.com/skills/bedkillerspacex-boop/codex-skill-library/uvicorn-gunicorn-workers)

Something wrong with this skill or its page? Tell us.