Backpressure and resource tuning
Track memory and temporary storage separately
Buffers, TLS state, open files, upstream sockets and module state consume resources at different lifetimes. With buffering enabled, proxy responses may spill to temporary files. Request bodies may also use disk. A per-response buffer limit is not a process memory cap. In a deliberately simplified model, 100 concurrent responses using 32 KiB of body buffers plus 4 KiB of header buffer each account for about 3.52 MiB. This excludes TLS, request pools, allocator overhead, kernel memory and other buffers. Measure real usage and keep storage headroom.
active = 100buffer_bytes = active * (32 + 4) * 1024print(buffer_bytes / 1024**2) # 3.515625 MiBBound a proxy workload
The fragment below assumes ordinary small responses, a local upstream and an application contract allowing a 64 KiB request body. Larger valid uploads would require a different policy. A proxy buffer pool may be allocated as needed. proxy_max_temp_file_size limits ordinary buffered response temporary files per request; cached or stored responses are excluded. It is not a disk quota. Timeouts are inactivity thresholds for the relevant operations, not total deadlines. Check headers and response correctness when changing buffers.
client_max_body_size 64k;client_body_buffer_size 8k;proxy_buffering on;proxy_buffer_size 4k;proxy_buffers 8 4k;proxy_busy_buffers_size 8k;proxy_max_temp_file_size 256k;proxy_read_timeout 3s;Recognize backpressure
When clients read slowly or the backend cannot keep up, queues and outstanding work grow. Buffering can free upstream connections earlier when data fits within the buffering policy, but disk use and memory increase; disabling buffering can hold upstream connections longer. A rate limit is not a total concurrency or memory cap. In this hypothetical steady observation, 40 requests per second with a mean residence time of 0.25 seconds gives about 10 concurrent requests by Little’s law. A backlog that is growing is not steady state; do not blindly extrapolate.
40 requests/s × 0.25 s = 10 average in-flight requestsIf residence time grows to 1 s at the same stable throughput: 40Measure before and after
Make one change at a time. Record worker CPU, open descriptors, cgroup memory and pressure, temp-space use, response status, latency distribution and backend saturation. Use a known response marker and a small bounded concurrency test on a private listener. The included script sends only eight requests with at most two concurrent clients; it is a smoke test, not a benchmark. Stop on errors, preserve the known-good config and avoid interpreting a small sample as a capacity guarantee.
nginx -t -p "$PWD/" -c nginx.conf# after starting only the dedicated lab instance:python3 verify_http.pyPractice and recap
A small proxy shows growing temporary files and slower responses. Propose a single controlled change and specify evidence, a stop condition and rollback. Check your reasoning against the manual exercise. Next: Benchmark design.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Backpressure and resource tuning
Choose bounded settings for a workload
Does a proxy buffer limit cap total worker memory?
What does proxy_max_temp_file_size limit?
At steady throughput of 40 requests/s and mean residence 0.25 s, what is average concurrency?
What can happen when response buffering is disabled?
What does an eight-request smoke test establish?