# Compression on xeon: mode off, static and all against nginx gzip (2026-11-15)

URL: https://scalws.com/docs/benchmarks/2026-11-15-compression/
Source: `docs/benchmarks/2026-11-15-compression.md` in the ScalWS repository

The measurement of the ScalPanel plan's Task 6 (design "Cost when off, measured"): what
response compression costs when it is off, and how ScalWS's `static` and `all` modes compare
with nginx's gzip module.

## Method

`bench/compression.sh <scalwsd> <base-scalwsd> <out-dir>` (the script's header has every
detail).

- Host: 2x Xeon E5-2650 v2 (no AVX2), Ubuntu 26.04, kernel 7.0.0-38, no VM running.
- Server on CPU 0 (1 CPU layout) or CPUs 0-5 (6 CPU layout), socket 0; PHP-FPM 8.5.4 (one
  external pool for both servers, static, 8 children) on 6, 7, 22, 23; oha 1.16.0 on 8-15 and
  24-31 (socket 1), 64 connections, 5 s warm-up and 15 s measured per row, 3 rounds with the
  server order rotated; medians, ratios are the median of the per-round ratios.
- ScalWS: `tools/pgo-build.sh` with `PGO_FEATURES=scalwsd/http3`, commit 99e4900 (this
  task). Base: the same build of f19987c, the v1.1 branch before compression (Task 4).
  Both with `open_file_cache: {max_entries: 0}` and the access log off, as nginx.
- nginx 1.31.6 (built from source with `gzip_static`; no 1.30 build is installed on xeon,
  1.31.6 is the release every 1.0 ratio was taken against) with
  `bench/configs/nginx-gzip.conf`: `gzip on; gzip_comp_level 1; gzip_min_length 1024;
  gzip_types <ScalWS's static types>; gzip_vary on; gzip_static on;`, no `.gz` files present.
  nginx has no brotli module: for `Accept-Encoding: br, gzip` it sends gzip.
- Files: a 100 KiB CSS and a 20 KiB HTML page generated from a fixed seed, a 300 KiB JS
  (jQuery 3 unminified, repeated to 300 KiB), text files of 1 KiB and 100 KiB for part (a), a
  PHP hello page and a PHP page that sends a 50 KiB HTML file.

What the modes do in these rows: with `static`, ScalWS compresses a file once at the cached
levels (gzip 6, brotli 5) and serves the variant from memory afterwards; nginx compresses
every response at level 1 (`gzip_static` only helps with precompressed files on disk). With
`all`, both compress the PHP page while it streams, at level 1.

## Results (run 1, 21:58 to 22:39 local time)

#### (a) mode off against the build before compression (gate: >= 0.98)

| CPUs | scenario | scalws-off rps | base-off rps | ratio (median, min-max) | scalws-off p99 ms | base-off p99 ms | scalws-off bytes/resp | base-off bytes/resp | encoding | gate |
|---:|---|---:|---:|---|---:|---:|---:|---:|---|---|
| 1 | php-hello | 13417 | 13213 | 1.013 (1.009-1.030) | 5.14 | 5.22 | 13 | 13 | identity | PASS |
| 1 | static-100k | 5113 | 5232 | 0.977 (0.975-0.995) | 31.05 | 30.68 | 102400 | 102400 | identity | FAIL |
| 1 | static-1k | 13259 | 13402 | 0.989 (0.977-1.017) | 11.30 | 10.96 | 1024 | 1024 | identity | PASS |
| 6 | php-hello | 29918 | 29874 | 1.001 (1.001-1.002) | 3.12 | 3.11 | 13 | 13 | identity | PASS |
| 6 | static-100k | 33703 | 33886 | 0.995 (0.993-1.005) | 3.75 | 4.00 | 102400 | 102400 | identity | PASS |
| 6 | static-1k | 81012 | 81884 | 0.991 (0.979-1.000) | 1.74 | 1.52 | 1024 | 1024 | identity | PASS |

#### (b) mode static against nginx gzip_comp_level 1 + gzip_static (gate at 1 CPU: >= 1.05)

| CPUs | scenario | scalws-static rps | nginx rps | ratio (median, min-max) | scalws-static p99 ms | nginx p99 ms | scalws-static bytes/resp | nginx bytes/resp | encoding | gate |
|---:|---|---:|---:|---|---:|---:|---:|---:|---|---|
| 1 | css-100k-br | 9638 | 984 | 9.858 (9.720-10.122) | 14.80 | 65.75 | 17031 | 21744 | br/gzip | PASS |
| 1 | css-100k-gzip | 10010 | 983 | 10.189 (10.169-10.461) | 14.84 | 65.81 | 16694 | 21744 | gzip | PASS |
| 1 | html-20k-br | 10220 | 2755 | 3.725 (3.648-3.835) | 14.05 | 23.60 | 6236 | 7193 | br/gzip | PASS |
| 1 | html-20k-gzip | 10592 | 2755 | 3.857 (3.792-3.958) | 13.42 | 23.62 | 6470 | 7193 | gzip | PASS |
| 1 | js-300k-br | 7186 | 188 | 38.206 (37.566-38.601) | 20.49 | 3574.15 | 79667 | 111126 | br/gzip | PASS |
| 1 | js-300k-gzip | 7092 | 189 | 37.746 (36.996-38.071) | 20.95 | 3572.47 | 91849 | 111126 | gzip | PASS |
| 6 | css-100k-br | 59904 | 5916 | 10.144 (10.093-10.165) | 1.96 | 15.57 | 17031 | 21744 | br/gzip | report (>= 1.0) |
| 6 | css-100k-gzip | 62707 | 5915 | 10.602 (10.588-10.686) | 1.85 | 14.44 | 16694 | 21744 | gzip | report (>= 1.0) |
| 6 | html-20k-br | 63260 | 16429 | 3.851 (3.832-3.875) | 1.80 | 4.78 | 6236 | 7193 | br/gzip | report (>= 1.0) |
| 6 | html-20k-gzip | 66231 | 16441 | 4.016 (3.984-4.061) | 1.98 | 5.55 | 6470 | 7193 | gzip | report (>= 1.0) |
| 6 | js-300k-br | 44255 | 1121 | 39.481 (39.276-39.745) | 2.69 | 59.86 | 79667 | 111126 | br/gzip | report (>= 1.0) |
| 6 | js-300k-gzip | 43717 | 1120 | 39.080 (38.788-39.233) | 2.74 | 59.99 | 91849 | 111126 | gzip | report (>= 1.0) |

#### (c) mode all, 50 KiB PHP page, against nginx gzip on over FastCGI (gate at 1 CPU: >= 1.05)

| CPUs | scenario | scalws-all rps | nginx rps | ratio (median, min-max) | scalws-all p99 ms | nginx p99 ms | scalws-all bytes/resp | nginx bytes/resp | encoding | gate |
|---:|---|---:|---:|---|---:|---:|---:|---:|---|---|
| 1 | php-50k-gzip | 1818 | 1172 | 1.550 (1.548-1.571) | 36.24 | 55.70 | 23105 | 17259 | gzip | PASS |
| 6 | php-50k-gzip | 7129 | 4730 | 1.761 (1.507-1.821) | 12.00 | 15.69 | 23105 | 17259 | gzip | report (>= 1.0) |

Non-2xx answers over all rows: 0.

Every row of run 1 is at or above its gate except (a) 1 CPU `static-100k`, 0.977 (per-round
0.975 to 0.995), below the 0.98 line by 0.3 %.

## Re-measurement of the row below the gate

Part (a) at 1 CPU again (23:39 to 23:52 local time), 5 rounds of 20 s, the same binaries,
under the xeon bench lock (`/var/tmp/XEON_BENCH`, no cargo or rustc running). A first
attempt of this re-run (around 23:12) is discarded: another agent's tests held
127.0.0.1:9901, the metrics port the bench configuration uses by default, so the server did
not start.

#### (a) mode off against the build before compression (gate: >= 0.98)

| CPUs | scenario | scalws-off rps | base-off rps | ratio (median, min-max) | scalws-off p99 ms | base-off p99 ms | scalws-off bytes/resp | base-off bytes/resp | encoding | gate |
|---:|---|---:|---:|---|---:|---:|---:|---:|---|---|
| 1 | php-hello | 13448 | 13380 | 1.001 (0.998-1.015) | 5.12 | 5.14 | 13 | 13 | identity | PASS |
| 1 | static-100k | 5525 | 5596 | 0.996 (0.960-1.010) | 29.95 | 29.56 | 102400 | 102400 | identity | PASS |
| 1 | static-1k | 13036 | 13336 | 0.985 (0.921-0.988) | 5.43 | 10.54 | 1024 | 1024 | identity | PASS |

Non-2xx answers over all rows: 0.

All three rows pass. The 100 KiB row moved from 0.977 to 0.996 with nothing changed: its
spread (0.960 to 1.010 per round here) is wider than the 2 % gate, so run 1's value is noise.
Nothing in the off path of this task touches the static handler: with `compression` absent
the pipeline pays one `Option` test when the application is routed and one in `finish`, and
`pipeline_cost` counts the same allocations per request as before (below). The `static`
and `php` rows of `pipeline_cost` allocate about 1.3 KiB more bytes per request (same count)
since Task 5 (a larger future of the static handler); that is Task 5's and did not show here.

`pipeline_cost` (`cargo test --release -p scalws-server pipeline_cost -- --ignored`,
allocations per request / bytes per request):

| row | f19987c (before Task 4) | ea0c445 (Task 5) | 99e4900 (this task) |
|---|---:|---:|---:|
| proxy | 22.0 / 7593 | 22.0 / 7593 | 22.0 / 7593 |
| respond | 15.0 / 5232 | 15.0 / 5232 | 15.0 / 5232 |
| static (1 KiB file, new row) | 17.0 / 6632 | 17.0 / 7928 | 17.0 / 7960 |
| php (PHP-FPM page, new row) | 29.0 / 8611 | 29.0 / 9907 | 29.0 / 9939 |
| respond+cache | 15.0 / 5232 | 15.0 / 5232 | 15.0 / 5232 |
| respond+cloudflare | 15.0 / 5232 | 15.0 / 5232 | 15.0 / 5232 |
| respond+trusted | 18.0 / 5292 | 18.0 / 5292 | 18.0 / 5292 |

## Findings

- Mode off: within the 2 % gate at 1 and 6 CPUs (run 1 at 6 CPUs, the re-run at 1 CPU).
- Mode static: 3.7x to 38x nginx at 1 CPU and 3.9x to 39x at 6 CPUs. The difference is the
  method, not the encoder: ScalWS compresses each file once (gzip 6, brotli 5) and serves
  the variant from memory, so it also sends fewer bytes (CSS 16.7 KB gzip / 17.0 KB br against
  nginx's 21.7 KB; JS 91.8 / 79.7 KB against 111.1 KB); nginx compresses every response at
  level 1. nginx at 1 CPU with the 300 KiB JS reaches 189 requests per second and a p99 of
  3.6 s; ScalWS 7 092 and 21 ms.
- Inline fills (Task 5 review): rows (b) do not measure them. The `curl` that checks the
  encoding before each row and the warm-up fill the cache, so the measured window has cache
  hits only. Fills are measured separately in part (f) below (fix round 1).
- Mode all: 1.55x nginx at 1 CPU and 1.76x at 6 CPUs for the 50 KiB PHP page. ScalWS's
  responses are larger, 23.1 KB against nginx's 17.3 KB, at the same nominal level 1. The
  likely cause is zlib-rs's level 1, the fast "quick" strategy of zlib-ng, which compresses
  less than zlib's level 1 (ScalWS also sync-flushes when PHP's output pauses). Streaming gzip
  at level 2 would likely close most of the byte gap for some speed; not changed here, since
  every row is above its gate. Fix round 1 tried level 2: see below.
- No non-2xx answer in any row.

## Fix round 1 (2026-11-16): inline fills, streaming gzip level 2

Same host and method; PGO builds of the fix-round tree. Taken under the xeon bench lock
(`/var/tmp/XEON_BENCH`, no cargo or rustc running), `FORCE=1` (the load average of idle
sessions stays near 2.7 on xeon).

### (c) at streaming gzip level 2 (01:39 UTC)

| CPUs | scalws-all rps | nginx rps | ratio (median, min-max) | scalws p99 ms | nginx p99 ms | scalws bytes/resp | nginx bytes/resp |
|---:|---:|---:|---|---:|---:|---:|---:|
| 1 | 1341 | 1175 | 1.138 (1.138-1.141) | 48.93 | 55.19 | 16614 | 17259 |
| 6 | 6044 | 4597 | 1.308 (1.210-1.452) | 13.07 | 17.17 | 16614 | 17259 |

Level 2 sends 28 % fewer bytes than level 1 (16.6 KB against 23.1 KB, now below nginx's 17.3
KB), but throughput at 1 CPU drops from 1.55x to 1.14x nginx. That is under the 1.2x the
controller set as the condition for keeping it, so streaming gzip stays at level 1 (rows (c)
of run 1 stand). The ETag suffix is now derived from the encoder's level (`Level::level`),
so a later level change cannot keep an old suffix.

### (f) inline fills (new part)

4 connections fetch random ones of 1000 distinct 60 KiB CSS files with a variant cache of 1
byte, so every one of their requests compresses the file (gzip 6 or brotli 5) and nothing is
kept; 60 connections fetch the 1 KiB file as identity at the same time. Against the same
load with compression off. Server on CPU 0, 3 rounds of 15 s.

Inline limit 64 KiB for both codings (01:44 UTC):

| scenario | fill rps | off rps | fill p50 ms | off p50 ms | fill p99 ms | off p99 ms | p99 ratio (median, min-max) |
|---|---:|---:|---:|---:|---:|---:|---|
| background, br fills | 6278 | 12074 | 7.64 | 4.97 | 24.80 | 10.68 | 2.341 (2.247-2.553) |
| br fill load | 242 | 801 | 17.32 | 4.97 | 34.46 | 10.72 | 3.237 (3.102-3.286) |
| background, gzip fills | 7665 | 12062 | 6.18 | 4.97 | 19.85 | 10.66 | 1.817 (1.816-1.895) |
| gzip fill load | 296 | 803 | 13.87 | 4.96 | 28.72 | 10.81 | 2.657 (2.583-2.780) |

Brotli inline limit lowered one step, to 32 KiB, so these 60 KiB brotli fills run on the
blocking pool (02:40 UTC):

| scenario | fill rps | off rps | fill p50 ms | off p50 ms | fill p99 ms | off p99 ms | p99 ratio (median, min-max) |
|---|---:|---:|---:|---:|---:|---:|---|
| background, br fills | 6362 | 12032 | 7.59 | 5.00 | 24.51 | 10.83 | 2.264 (2.253-2.282) |
| br fill load | 242 | 798 | 17.08 | 4.99 | 33.93 | 10.74 | 3.124 (3.121-3.176) |
| background, gzip fills | 7866 | 11885 | 6.00 | 5.01 | 19.46 | 10.85 | 1.809 (1.779-1.809) |
| gzip fill load | 299 | 790 | 13.83 | 5.00 | 28.27 | 10.76 | 2.637 (2.615-2.660) |

No non-2xx answer. (A first part (f) run at 23:09 UTC is discarded: its file URLs were not
generated as intended (404) and oha's default `Accept-Encoding` made the background
compressed too.)

What this shows:

- A steady stream of fills at 1 CPU raises the p99 of other requests on that CPU by 1.8x
  (gzip) to 2.3x (brotli), well over the 1.10x line set for this row. Each 60 KiB fill costs
  roughly 3 ms (gzip 6) to 4 ms (brotli 5) of CPU, and 240 to 300 of them a second take most
  of the core.
- Where the fill runs makes no measurable difference at 1 CPU: with brotli fills moved from
  the event loop to the blocking pool, the background p99 went from 2.34x to 2.26x, inside
  the round spread. Both threads share the one CPU, so the cost is the CPU time, not the
  place. With more CPUs the blocking pool runs beside the event loop, which is what the lower
  limit is for; 6 CPUs were not measured here.
- The row is the worst case by construction: in normal operation a file is compressed once
  per coding while it stays in the cache (rows (b): cache hits only). A site whose working set
  of compressible files does not fit `cache_bytes` (8 MiB in ScalPanel mode) pays these fills
  repeatedly.
- The brotli inline limit stays at 32 KiB (gzip at 64 KiB): no measurable cost and no
  measurable gain at 1 CPU; it bounds the stall of one event loop worker per fill on hosts
  with more CPUs.
