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]>
45 lines
1.4 KiB
PowerShell
45 lines
1.4 KiB
PowerShell
# Serve the built site.
|
|
#
|
|
# pwsh server/run.ps1 # port 8080
|
|
# pwsh server/run.ps1 -Port 9000
|
|
#
|
|
# Uses Caddy when server/caddy.exe is present (get it with get-caddy.ps1) and
|
|
# falls back to the dependency-free serve.py otherwise. Caddy is roughly 3x
|
|
# faster at low concurrency and does not fall over at high concurrency -- see
|
|
# the table in the README.
|
|
|
|
param([int]$Port = 8080)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
Set-Location $here # Caddyfile's `root * ../web` resolves against the cwd
|
|
|
|
if (-not (Test-Path (Join-Path $here '..\web\data\world.json'))) {
|
|
Write-Warning "web/data/world.json missing -- run 'python tools/build.py' first"
|
|
}
|
|
|
|
$ip = (Get-NetIPConfiguration |
|
|
Where-Object { $_.IPv4DefaultGateway -and $_.NetAdapter.Status -eq 'Up' } |
|
|
Select-Object -First 1).IPv4Address.IPAddress
|
|
if (-not $ip) { $ip = '127.0.0.1' }
|
|
|
|
$caddy = Join-Path $here 'caddy.exe'
|
|
$engine = if (Test-Path $caddy) { 'caddy' } else { 'serve.py (slower)' }
|
|
|
|
Write-Host ""
|
|
Write-Host " serving with $engine"
|
|
Write-Host " local http://localhost:$Port/"
|
|
Write-Host " LAN http://${ip}:$Port/"
|
|
Write-Host ""
|
|
Write-Host " Ctrl+C to stop"
|
|
Write-Host ""
|
|
|
|
if (Test-Path $caddy) {
|
|
$env:TARKOVMAP_PORT = "$Port"
|
|
& $caddy run --config (Join-Path $here 'Caddyfile')
|
|
}
|
|
else {
|
|
Write-Host " (run get-caddy.ps1 for the faster server)"
|
|
python (Join-Path $here 'serve.py') $Port
|
|
}
|