Files
TarkovMaps/server/Caddyfile
T
Claude 6c2bd6d27b Serve tiles with Caddy; fix serve.py falling back to HTTP/1.0
serve.py inherited SimpleHTTPRequestHandler's HTTP/1.0 default, which
closes the socket after every response. A map view pulls ~30 tiles, so
that was ~30 TCP handshakes per pan. Setting HTTP/1.1 more than doubled
loopback throughput on its own.

That still leaves thread-per-connection behind the GIL. Measured over 480
tile requests on reused connections:

  conc  8   serve.py 2,622 req/s p95 4.0ms  |  caddy 6,987 req/s p95 1.9ms
  conc 32   serve.py   462 req/s max 1013ms |  caddy 5,877 req/s max  21ms

serve.py does not merely slow down under load, its throughput falls and
tail latency crosses a second. Caddy stays flat, so it is now the default.

run.ps1 picks Caddy when server/caddy.exe is present and falls back to
serve.py, so a fresh clone still works with nothing installed.
get-caddy.ps1 fetches the binary; it is gitignored.

HTTP/2 is not active: browsers only negotiate h2 over TLS, and trusting a
local CA on every phone is not worth it on a LAN. The gain is Go's I/O.

Co-Authored-By: Claude Opus 5 <[email protected]>
2026-08-08 02:20:39 -07:00

44 lines
1.4 KiB
Caddyfile

# Production-ish static server for the built site.
#
# server/caddy.exe run --config server/Caddyfile
#
# Get caddy.exe with server/get-caddy.ps1 (it is gitignored -- 47 MB binary).
#
# Compared with serve.py this adds ETags, compression, and concurrency that
# scales instead of collapsing. Everything here is static files; there is no
# application server.
#
# Note: this is plain HTTP, so HTTP/2 is NOT active -- browsers only negotiate
# h2 over TLS. The speedup over serve.py is Go's I/O, not h2. Turning on
# `tls internal` would enable h2/h3 but every phone would need Caddy's local
# CA installed, which is not worth it on a LAN.
{
admin off
auto_https off
}
:{$TARKOVMAP_PORT:8080} {
root * ../web
encode zstd gzip
# Tiles are rewritten wholesale by tools/build.py and never edited in
# place, so a long lifetime is safe. `immutable` stops the browser
# revalidating them on every pan.
@tiles path /tiles/*
header @tiles Cache-Control "public, max-age=604800, immutable"
# The shell and the manifest must never be stale, or the app can end up
# pointing at tiles that no longer exist.
@shell path / /index.html /app.js /style.css /data/*
header @shell Cache-Control "no-cache"
# Leaflet skips a tile that 404s; without this an out-of-bounds request
# logs an error page instead of failing quietly.
handle_errors {
respond "" {http.error.status_code}
}
file_server
}