Brotli on NGINX thread pools: ngx_mbrotli vs ngx_brotli

On-the-fly Brotli blocks the NGINX event loop. ngx_mbrotli on a thread pool against google/ngx_brotli: p99 latency, requests per second, CPU time and memory.

Published : 22 October 2026

Author : Mikhail Panfilov

Reading time : 13 min

Projects : ngx_mbrotli 0.4.5
mbrotli 0.5.16

Summary

  • With google/ngx_brotli, each response is compressed inside the NGINX worker’s event loop, so every other request on that worker waits. While large responses were compressed at Brotli levels 6 and 11, the p99 latency of small uncompressed requests rose from 1.9 ms to 17–514 ms.
  • ngx_mbrotli with brotli_thread_pool compresses on NGINX thread pools. In the same test, the p99 of small requests stayed at 1.7–3.3 ms, the same as with no compression.
  • One NGINX worker with a 4-thread pool served 3.8–15 times as many Brotli responses per second as google/ngx_brotli on 85 KB–2.2 MB files. The gain was largest at levels 9 and 11.
  • The cost is memory. At 8 connections on 1–2.2 MB responses, a worker peaked at 138–995 MiB, 11–26 times as much as google/ngx_brotli. Responses longer than one 1 MiB segment came out 0.9–5.2% larger.
  • Measured on 20 October 2026 with NGINX 1.30.6, one worker, an Intel Core i7-13700KF under WSL2. Every response was decoded and checked against the original by SHA-256.