End to end interactions from when the user clicks or presses a button should to when the result of that change is displayed to the user in their monitor should be less than:
16ms
16ms is a good goal because that is the duration of a single frame of a 60hz monitor, so in theory you can have the result given to them on the very next frame. Humans can perceive this level of latency so its worth doing.
Keep network requests under the size of an TCP packet to avoid backpressure machanics: under 14k
Use curl to diagnos network speed bottlenecks:
# Units are in seconds so 0.032 would be 32ms
curl -w '
dns: %{time_namelookup}
connect: %{time_connect}
tls: %{time_appconnect}
ttfb: %{time_starttransfer}
total: %{time_total}
' -o /dev/null -s https://frii.day
Meaning: DNS lookup: 4.3ms TCP connect: 22ms TLS handshake: 89ms Time to first byte: 144ms Total request: 202ms Also use timing API (insrument based profiling). Can pretty much keep this enabled even in production because its cheap and always helpful Instrument Timing API
Can use (sample based profiling) with golangs built in profiler Sampling Profiler
Make dns cache as long as possible (cloudflare lets you set it to 24hrs)
Ensure your server is keeping TCP connections alive with client and between proxies and upstream servers so you don't keep recreating connections on every request:
keepalive_timeout 30s: keeps browser sockets warm without holding them forever. keepalive_requests 1000: avoids frequent reconnects. (max HTTP requests allowed on one persistent connection before nginx closes it.)
http {
# Client <-> Nginx keepalive
keepalive_timeout 30s;
keepalive_requests 1000;
# Optional (backward compatability with old browsers): avoid sending "Keep-Alive: timeout=..."
# Most clients do not need it.
keepalive_disable none;
upstream app {
server 127.0.0.1:8080;
# Nginx <-> backend keepalive pool (64 is the max number of idle connections in pool per worker process)
keepalive 64;
}
server {
listen 443 ssl http2;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
location / {
proxy_http_version 1.1;
# Required for upstream keepalive.
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://app;
}
}
}