install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/pproenca/dot-skills/nginx-c-module-perf" ~/.claude/skills/comeonoliver-skillshub-nginx-c-module-perf && rm -rf "$T"
manifest:
skills/pproenca/dot-skills/nginx-c-module-perf/SKILL.mdsource content
nginx.org C Module Performance & Reliability Best Practices
Comprehensive performance optimization and reliability guide for nginx C modules, derived from the official nginx development documentation and production engineering experience. Contains 43 rules across 8 categories, prioritized by impact to guide automated optimization and resilience improvements.
Companion skill: This skill complements nginx-c-modules which covers correctness (memory safety, request lifecycle, configuration). This skill covers performance optimization and operational reliability.
When to Apply
Reference these guidelines when:
- Optimizing nginx C module throughput and latency
- Reducing buffer copies and enabling zero-copy I/O paths
- Tuning connection pooling and socket options
- Minimizing shared memory lock contention across workers
- Implementing graceful error recovery and fallback responses
- Configuring upstream timeouts and retry strategies
- Building in-module response caches with shared memory
- Tuning worker process behavior under load
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Buffer & Zero-Copy I/O | CRITICAL | |
| 2 | Connection Efficiency | CRITICAL | |
| 3 | Lock Contention & Atomics | HIGH | |
| 4 | Error Recovery & Resilience | HIGH | |
| 5 | Timeout & Retry Strategy | MEDIUM-HIGH | |
| 6 | Response Caching | MEDIUM | |
| 7 | Worker & Process Tuning | MEDIUM | |
| 8 | Logging & Metrics | LOW-MEDIUM | |
Quick Reference
1. Buffer & Zero-Copy I/O (CRITICAL)
- Reuse Buffer Chain Links Instead of Allocating New Onesbuf-chain-reuse
- Use File Buffers for Static Content Instead of Reading into Memorybuf-file-sendfile
- Avoid Copying Buffers When Passing Through Filter Chainbuf-avoid-copy
- Coalesce Small Buffers Before Outputbuf-coalesce-small
- Use Shadow Buffers for Derived Data Instead of Full Copiesbuf-shadow-reference
- Mark Buffers as Recycled for Upstream Response Reusebuf-recycled-flag
2. Connection Efficiency (CRITICAL)
- Mark Idle Connections as Reusable for Pool Recoveryconn-reusable-queue
- Handle Connection Drain Under Memory Pressureconn-drain-pressure
- Control TCP_NODELAY for Latency-Sensitive Responsesconn-tcp-nodelay
- Size Connection Pool to Avoid Runtime Reallocationconn-prealloc-pool
- Use Lingering Close for Graceful Connection Shutdownconn-close-linger
- Enable SSL Session Caching in Upstream Connectionsconn-ssl-session-reuse
3. Lock Contention & Atomics (HIGH)
- Minimize Critical Section Duration in Shared Memorylock-minimize-critical
- Use Atomic Operations for Simple Counters Instead of Mutexlock-atomic-counters
- Use ngx_shmtx_trylock with Fallback to Avoid Worker Stallslock-trylock-fallback
- Aggregate Per-Worker Counters to Reduce Shared Memory Accesslock-per-worker-aggregate
- Perform Slab Allocation Outside Hot Pathlock-alloc-outside
- Use Read-Copy-Update Pattern for Read-Heavy Shared Datalock-rw-pattern
4. Error Recovery & Resilience (HIGH)
- Cache ngx_errno Immediately to Prevent Overwriteerr-cache-errno
- Return Fallback Response When Upstream Failserr-fallback-response
- Handle Pool and Slab Allocation Exhaustion Gracefullyerr-resource-exhaustion
- Use Blocked Counter to Prevent Premature Request Destructionerr-blocked-counter
- Check Connection Error Flag Before I/O Operationserr-connection-error-check
- Limit Repeated Error Logging to Prevent Log Stormserr-log-once-pattern
5. Timeout & Retry Strategy (MEDIUM-HIGH)
- Set Separate Timeouts for Connect, Send, and Read Phasestimeout-upstream-phases
- Configure next_upstream Mask for Retriable Failurestimeout-retry-next-upstream
- Use Exponential Backoff for Upstream Reconnection Attemptstimeout-backoff-reconnect
- Set Client Body Timeout to Bound Slow-Client Resource Usagetimeout-client-body-limit
6. Response Caching (MEDIUM)
- Implement LRU Eviction in Shared Memory Cache Zonescache-shm-lru
- Prevent Cache Stampede with Single-Flight Patterncache-stampede-lock
- Use ngx_hash for Fixed Cache Key Lookupscache-key-hash
- Use Atomic Timestamp Comparison for TTL Expiry Checkscache-ttl-atomic
- Cache Only Successful Responses to Avoid Negative Cache Pollutioncache-conditional-store
7. Worker & Process Tuning (MEDIUM)
- Understand Accept Mutex Impact on Connection Distributionworker-accept-mutex
- Use Pre-Allocated Free List for Module Data Structuresworker-connection-prealloc
- Handle Worker Shutdown Signal Without Data Lossworker-graceful-shutdown
- Support Single-Process Mode for Debuggingworker-single-process-debug
- Access Configuration Through Cycle for Process-Level Operationsworker-cycle-conf
8. Logging & Metrics (LOW-MEDIUM)
- Guard Expensive Debug Argument Computation Behind Level Checklog-level-guard
- Attach Module Context to Connection Log for Tracinglog-connection-context
- Collect Metrics via Shared Memory Counterslog-shared-metrics
- Deduplicate Repeated Error Messages with Throttlinglog-error-dedup
- Set Log Action String for Operation Contextlog-action-string
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
Reference Files
| File | Description |
|---|---|
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |