DEV Community

niuniu
niuniu

Posted on

Quick Tip: `curl -w` Measures DNS, TLS, and TTFB Without Any Tools

Quick Tip

You just deployed to a free tier. Is it slow, or is it your internet? One curl command tells you exactly where the time goes:

curl -w "\nDNS: %{time_namelookup}s\nTCP: %{time_connect}s\nTLS: %{time_appconnect}s\nTTFB: %{time_starttransfer}s\nTotal: %{time_total}s\n" \
  -o /dev/null -s https://your-app.fly.io/health
Enter fullscreen mode Exit fullscreen mode

Output:

DNS: 0.001s
TCP: 0.012s
TLS: 0.089s
TTFB: 0.412s
Total: 0.445s
Enter fullscreen mode Exit fullscreen mode

What each phase tells you

Phase If it's slow Fix
DNS Your DNS provider or no CDN Move to Cloudflare (free)
TCP Server is far away or overloaded Pick a closer region
TLS Certificate chain or old TLS Let's Encrypt + TLS 1.3
TTFB Your app is slow (cold start, DB query) Optimize code or upgrade tier

The free-tier cold start detector

Run this twice, 5 minutes apart:

# First hit (cold)
curl -w "TTFB: %{time_starttransfer}s\n" -o /dev/null -s https://your-app.onrender.com/

# Second hit (warm)
curl -w "TTFB: %{time_starttransfer}s\n" -o /dev/null -s https://your-app.onrender.com/
Enter fullscreen mode Exit fullscreen mode

If TTFB drops from 14s to 0.2s, your free tier spins down. That's not a bug — it's the business model.

The one-liner I keep in my dotfiles

alias curltime='curl -w "\nDNS: %{time_namelookup}s | TCP: %{time_connect}s | TLS: %{time_appconnect}s | TTFB: %{time_starttransfer}s | Total: %{time_total}s\n" -o /dev/null -s'
Enter fullscreen mode Exit fullscreen mode

No install. No dependencies. Works on every server, every CI runner, every Docker container you'll ever debug.

Powered by MonkeyCode: https://ly.cyberserval.tech/iIETXiF

What's your go-to one-liner for diagnosing slow endpoints? I keep finding new uses for curl -w and it keeps replacing tools I used to install.

Top comments (0)