, 2 min read
Performance Comparison gzip vs Brotli
The NGINX web-server offers gzip, deflate, and Brotli compression. My current
nginx.conf file uses
It looks that indeed the default Brotli compression level 6 is a sweet spot for Brotli.
1. Measurement. I used below software versions:
- Arch Linux kernel 6.4.12-arch1-1
- Brotli 1.0.9-12
- gzip 1.12-3
Machine is using an AMD Ryzen 7 5700G CPU with 64GB DDR4-3600 RAM.
All files were stored in
/tmp, i.e., there were in a RAM disk. All compressed files were also written to
/tmp. In total there were 544 HTML files, with roughly 19 MB. The individual HTML files, of course, were smaller, otherwise I could not be member of the 512KB club.
Testing Brotli compression:
/tmp/build: time brotli -kf -q 6 `find . -name \*.html` real 0.27s user 0.23s sys 0 swapped 0 total space 0
Testing gzip compression:
/tmp/build: time gzip -kf -9 `find . -name \*.html` real 0.34s user 0.32s sys 0 swapped 0 total space 0
Checking total file size:
wc `find . -name \*.br` | tail -3
2. Results. Real- and user-times are given in seconds.
3. Discussion. Even very low compression levels of Brotli lead to a significant reduction in compressed file size, way better than gzip. Starting at compression level 9 Brotli becomes slower than gzip but still compresses way better than gzip. My decision to use compression level 10 was motivated by the fact that many readers of this blog are not from Germany, .e.g., there are either from the US or from India. In this case I hope I can trade CPU time for smaller transferred data across the wire.