Skip to main content

ngx_mzstd NGINX Module Brings Zstd Compression to Thread Pools

Explore ngx_mzstd, a Rust-based NGINX module for on-the-fly Zstandard compression using thread pools, eliminating event loop blocking and cutting p99 latency.

AI-written
Inewgen
22 Oct 2026Source: Dev.to2 min read (0 views)
Share
ngx_mzstd NGINX Module Brings Zstd Compression to Thread Pools

Stock photo for illustration only, not from the actual event

Font size
  • ngx_mzstd is a Rust-written NGINX module supporting Zstandard compression on thread pools.
  • Solves the issue of large response compression blocking the event loop and small requests.
  • WSL2 benchmarks on October 20, 2026, show p99 latency dropping to just 1.7-2.0 milliseconds.

On-the-fly compression in NGINX traditionally suffers from event loop blocking when processing large payloads. Standard modules like tokers/zstd-nginx-module handle all compression work directly inside the single-threaded event loop, forcing small concurrent requests to wait while heavy assets—such as a 1.03 MB JavaScript bundle compressed at level 19—consume roughly 200 milliseconds of processing time per file.

To overcome this bottleneck, ngx_mzstd has been developed in Rust built on top of the mzstd encoder. It serves as a drop-in replacement for tokers/zstd-nginx-module using identical directives and requiring no libzstd. Its primary advantage is leveraging NGINX thread pools for compression, ensuring that compressing large responses does not halt worker connections from serving other traffic.

1.5sPrevious p99 latency (8 concurrent requests)
2.0msp99 latency using a 4-thread pool

Benchmark numbers gathered under WSL2 on October 20, 2026, demonstrate a dramatic performance shift. When eight large requests arrived simultaneously at compression level 19, tokers/zstd-nginx-module caused small request p99 latency to spike to 1.5 seconds, whereas ngx_mzstd running on a 4-thread pool maintained latency at an impressive 1.7 to 2.0 milliseconds.

chromebook notebook computer office desk workspace

Stock photo for illustration only, not from the actual event

NGINX thread pools were originally introduced for blocking file I/O (aio threads) back in version 1.7.11 in 2015. By applying this established architecture to Zstandard compression, ngx_mzstd unlocks multi-core CPU utilization that remains idle during standard single-threaded event loop operations, resulting in massive concurrency gains.

Regarding segmentation, ngx_mzstd splits responses into default 1 MiB chunks (zstd_parallel_segment_size), processing up to 4 segments simultaneously across pool threads (zstd_parallel_tasks). Although segments are not fully independent—requiring context boundaries to maintain high compression ratios comparable to event loop execution—the trade-off delivers substantial tail latency improvements.

Source: Dev.to

Comments

Leave a Comment
0/2000

Found something wrong in this article? Report an issue with this article