Skip to content

Commit a03ec70

Browse files
committed
perf(benchmark): optimize nginx and caddy configs for raw throughput
nginx: add aio threads, open_file_cache, directio, sendfile_max_chunk, output_buffers, bumped keepalive_requests to 10k, listen backlog 4096, server_tokens off, reset_timedout_connection. caddy: disable admin API, explicit auto_https off, suppress Server and X-Content-Type-Options headers, disable_canonical_uris in file_server.
1 parent 6e6e8a4 commit a03ec70

File tree

2 files changed

+54
-16
lines changed

2 files changed

+54
-16
lines changed

benchmark/Caddyfile

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
1+
{
2+
# Global options
3+
# Disable the admin API — not needed for benchmarking
4+
admin off
5+
6+
# Prevent Caddy from trying HTTPS / ACME
7+
auto_https off
8+
}
9+
110
:80 {
211
root * /www
3-
file_server
12+
file_server {
13+
# Pre-compress is off — fair raw-throughput comparison
14+
disable_canonical_uris
15+
}
16+
17+
# Compression off — fair comparison with raw file serving
18+
# (encode gzip / encode zstd deliberately omitted)
19+
20+
# Suppress verbose response headers
21+
header -Server
22+
header -X-Content-Type-Options
423

5-
# Disable access log for fair benchmark comparison
24+
# Disable access log
625
log {
726
output discard
827
}

benchmark/nginx.conf

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,48 @@
1-
worker_processes auto;
2-
worker_rlimit_nofile 65535;
1+
worker_processes auto;
2+
worker_rlimit_nofile 65535;
33

44
events {
5-
worker_connections 4096;
6-
use epoll;
7-
multi_accept on;
5+
worker_connections 4096;
6+
use epoll;
7+
multi_accept on;
88
}
99

1010
http {
1111
include /etc/nginx/mime.types;
1212
default_type application/octet-stream;
1313

14-
sendfile on;
15-
tcp_nopush on;
16-
tcp_nodelay on;
17-
keepalive_timeout 65;
18-
keepalive_requests 1000;
14+
# ── I/O ──────────────────────────────────────────────────────────────────
15+
sendfile on;
16+
sendfile_max_chunk 512k; # cap per-call to avoid worker starvation
17+
aio threads; # async file I/O via thread pool (built-in)
18+
directio 4m; # bypass page cache for files > 4 MB
19+
tcp_nopush on; # batch headers + first data chunk (needs sendfile)
20+
tcp_nodelay on; # flush remaining small frames immediately
1921

20-
access_log off;
21-
error_log /dev/null crit;
22+
# ── Keepalive ────────────────────────────────────────────────────────────
23+
keepalive_timeout 75;
24+
keepalive_requests 10000;
25+
reset_timedout_connection on;
2226

23-
gzip off; # disabled — fair comparison with raw file serving
27+
# ── Buffers ──────────────────────────────────────────────────────────────
28+
output_buffers 2 128k;
29+
30+
# ── Open-file cache (avoid stat/open syscalls on every request) ──────────
31+
open_file_cache max=10000 inactive=30s;
32+
open_file_cache_valid 60s;
33+
open_file_cache_min_uses 1;
34+
open_file_cache_errors on;
35+
36+
# ── Logging / noise ──────────────────────────────────────────────────────
37+
access_log off;
38+
error_log /dev/null crit;
39+
server_tokens off;
40+
41+
# ── Compression — disabled for fair raw-throughput comparison ────────────
42+
gzip off;
2443

2544
server {
26-
listen 80;
45+
listen 80 backlog=4096;
2746
root /www;
2847
index index.html;
2948

0 commit comments

Comments
 (0)