, 2 min read
Performance Comparison gzip vs Brotli
The NGINX web-server offers gzip, deflate, and Brotli compression. My current nginx.conf
file uses
brotli_comp_level 10;
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.
Brotli | size | real | user | gzip | size | real | user |
---|---|---|---|---|---|---|---|
no compression | 18,692,104 | ||||||
-q0 | 9,125,121 | 0.06 | 0.04 | ||||
-q1 | 8,910,146 | 0.07 | 0.05 | -1 | 8,983,674 | 0.20 | 0.18 |
-q2 | 8,657,583 | 0.11 | 0.09 | -2 | 8,912,562 | 0.21 | 0.19 |
-q3 | 8,591,398 | 0.15 | 0.12 | -3 | 8,862,408 | 0.22 | 0.20 |
-q4 | 8,205,937 | 0.21 | 0.19 | -4 | 8,643,793 | 0.25 | 0.24 |
-q5 | 8,003,215 | 0.26 | 0.24 | -5 | 8,576,144 | 0.28 | 0.27 |
-q6 | 7,998,547 | 0.27 | 0.23 | -6 | 8,555,589 | 0.30 | 0.28 |
-q7 | 7,992,840 | 0.29 | 0.26 | -7 | 8,549,382 | 0.31 | 0.30 |
-q8 | 7,990,726 | 0.30 | 0.28 | -8 | 8,544,135 | 0.34 | 0.30 |
-q9 | 7,961,062 | 0.43 | 0.37 | -9 | 8,543,902 | 0.34 | 0.32 |
-q10 | 7,510,277 | 5.59 | 5.55 | ||||
-q11 | 7,427,506 | 14.16 | 14.08 |
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.