SkillPilotAI

Lab: the website is slow

"The website is slow" has four suspects: latency, packet loss, bandwidth and the server itself. Instead of guessing (or buying a bigger plan), measure each one: curl -w for the timing breakdown, ping and mtr for latency and loss, iperf3 for bandwidth and tcpdump for packet-level proof.

275.1 Why is it used?

  • Story: Asha says the company website is very slow; every page takes long to load.
  • Suspect 1, latency: network delay that costs time on every trip.
  • Suspect 2, bandwidth: the size of the pipe.
  • Suspect 3, packet loss on the way: TCP must resend.
  • Suspect 4, server think time: the server itself takes long to answer.

275.2 How it works: latency, bandwidth, TTFB

Latency: one round trip (RTT)
  1. 1.Browser sends a request: reaches the router in 2 ms

  2. 2.Through ISP and internet: reaches the server at 20 ms total

  3. 3.Reply takes the same 20 ms back: RTT = 40 ms

  4. 4.A page needs many round trips: the waits add up

  5. 5.A dropped packet is resent by TCP: loss makes it even longer

  • Bandwidth = how much data can flow in one second (pipe size).
  • Thin pipe 5 Mbps: a 60 MB file takes about 96 seconds; wide pipe 50 Mbps: about 10 seconds.
  • A wide pipe makes big files faster, but the RTT of a small request does not go down.
  • TTFB (time to first byte): the request reaches the server in 1 ms, but a DB query + page build takes 2 s before the first byte returns.
  • Fast network + plenty of bandwidth can still mean a slow page if the problem is inside the server.
SuspectWhat it isToolFixed by a bigger plan?
LatencyTime of each round tripping, mtrNo
Packet lossDropped packets, TCP resendsping, mtr (Loss%)No
BandwidthSize of the pipeiperf3Yes, for big files
Server think timeTime before the first bytecurl -w TTFB, tcpdumpNo

275.3 curl -w: reading the timing fields

FieldMeaning (curl manual)
time_namelookupDNS lookup complete
time_connectTCP connect complete
time_appconnectTLS handshake complete (HTTPS)
time_starttransfer (TTFB)First byte arrived: includes server time
time_totalThe whole request
  • Rule: a big gap before connect = network or DNS slow.
  • A big TTFB after a fast connect = the server is slow.
Where does the time go?
  1. 1.Run curl -w with dns, connect, tls, ttfb, total

  2. 2.dns or connect large? -> DNS / network latency: check with ping, mtr

  3. 3.Loss% in mtr? -> packet loss on the path

  4. 4.connect small but ttfb large? -> server: logs, database, app code

  5. 5.ttfb small but total large on big files? -> bandwidth: iperf3

  6. 6.Need proof? -> tcpdump the gap between request and first byte

275.4 Practical 1: curl timings, fast vs slow page

  • Isolated Docker lab: client 192.168.75.10, server 192.168.75.20 with a small web app.
  • /fast answers immediately; /slow waits two seconds before answering.
Terminal
# FMT (lab.sh): dns, connect, tls, ttfb, total#   %{time_namelookup} %{time_connect}#   %{time_appconnect} %{time_starttransfer}#   %{time_total}curl -s -o /dev/null -w "$FMT" \  http://server.lab.local:8080/fastcurl -s -o /dev/null -w "$FMT" \  http://server.lab.local:8080/slow
Output
$ curl -s -o /dev/null -w "$FMT" http://server.lab.local:8080/fastdns      0.001146connect  0.001644tls      0.000000ttfb     0.003913total    0.004483$ curl -s -o /dev/null -w "$FMT" http://server.lab.local:8080/slowdns      0.001107connect  0.001448tls      0.000000ttfb     2.002800total    2.002960
  • On /slow, DNS and connect still take under 2 ms but TTFB jumps to 2 s: the network is innocent, the server is slow.
  • tls is 0 because this is plain HTTP.

275.5 Practical 2: ping and mtr (latency + loss)

Terminal
ping -c 5 192.168.75.20mtr -r -c 5 -n 192.168.75.20
Output
$ ping -c 5 192.168.75.2064 bytes from 192.168.75.20: icmp_seq=1 ttl=64 time=0.123 ms64 bytes from 192.168.75.20: icmp_seq=5 ttl=64 time=0.110 ms--- 192.168.75.20 ping statistics ---5 packets transmitted, 5 received, 0% packet loss, time 4091msrtt min/avg/max/mdev = 0.110/0.117/0.123/0.004 ms$ mtr -r -c 5 -n 192.168.75.20Start: 2026-11-10T22:13:43+0000HOST: client                      Loss%   Snt   Last   Avg  Best  Wrst StDev  1.|-- 192.168.75.20              0.0%     5    0.1   0.2   0.1   0.3   0.1
  • mtr = traceroute + ping; -r report mode prints after the -c 5 cycles, -n skips name lookups.
  • RTT under 1 ms and 0% loss: the path has no latency or loss problem.

275.6 Practical 3: bandwidth with iperf3

Terminal
# on the server: iperf3 -siperf3 -c 192.168.75.20 -t 3iperf3 -c 192.168.75.20 -t 3 -b 5Miperf3 -c 192.168.75.20 -t 3 -b 50M
Output
$ iperf3 -c 192.168.75.20 -t 3[ ID] Interval           Transfer     Bitrate         Retr[  5]   0.00-3.03   sec  1.39 GBytes  3.94 Gbits/sec  2752             sender[  5]   0.00-3.03   sec  1.39 GBytes  3.94 Gbits/sec                  receiver$ iperf3 -c 192.168.75.20 -t 3 -b 5M[  5]   0.00-1.00   sec   640 KBytes  5.24 Mbits/sec    0    139 KBytes[  5]   0.00-3.00   sec  1.88 MBytes  5.24 Mbits/sec                  receiver$ iperf3 -c 192.168.75.20 -t 3 -b 50M[  5]   0.00-1.00   sec  6.00 MBytes  50.3 Mbits/sec    0    134 KBytes[  5]   0.00-3.00   sec  17.9 MBytes  50.0 Mbits/sec                  receiver
  • iperf3 -s runs server mode; -t 3 is a 3-second test.
  • About 4 Gbit/s unlimited because both containers are on the same machine.
  • -b 5M / -b 50M is iperf3's own pacing to model a thin and a wide pipe.

275.7 Practical 4: the gap in tcpdump

Terminal
# sidecar: shares the client's networkdocker run -d --name n275-capture \  --network container:n275-client \  --memory 128m nicolaka/netshoot:v0.13 \  tcpdump -i eth0 -nn -c 10 'tcp port 8080'# on the clientcurl -s -o /dev/null \  -w 'ttfb %{time_starttransfer}\n' \  http://server.lab.local:8080/slow
Output
22:14:13.937556 IP 192.168.75.10.56668 > 192.168.75.20.8080: Flags [S], seq 4054167842, win 64240, options [mss 1460,sackOK,TS val 2402115233 ecr 0,nop,wscale 10], length 022:14:13.937692 IP 192.168.75.20.8080 > 192.168.75.10.56668: Flags [S.], seq 447615425, ack 4054167843, win 65160, options [mss 1460,sackOK,TS val 1206047395 ecr 2402115233,nop,wscale 10], length 022:14:13.937721 IP 192.168.75.10.56668 > 192.168.75.20.8080: Flags [.], ack 1, win 63, options [nop,nop,TS val 2402115233 ecr 1206047395], length 022:14:13.937950 IP 192.168.75.10.56668 > 192.168.75.20.8080: Flags [P.], seq 1:89, ack 1, win 63, options [nop,nop,TS val 2402115234 ecr 1206047395], length 88: HTTP: GET /slow HTTP/1.122:14:13.937991 IP 192.168.75.20.8080 > 192.168.75.10.56668: Flags [.], ack 89, win 64, options [nop,nop,TS val 1206047396 ecr 2402115234], length 022:14:15.949357 IP 192.168.75.20.8080 > 192.168.75.10.56668: Flags [P.], seq 1:139, ack 89, win 64, options [nop,nop,TS val 1206049407 ecr 2402115234], length 138: HTTP: HTTP/1.0 200 OK$ curl -s -o /dev/null -w 'ttfb %{time_starttransfer}\n' http://server.lab.local:8080/slowttfb 2.012548
  • Handshake (S, S., .) finishes within 1 ms; GET /slow goes out and the server immediately sends only an ACK.
  • HTTP 200 OK arrives at second :15 after :13: the same 2 seconds of server think time.

275.8 Common mistakes

  • Myth: a slow website just needs a bigger internet plan. Bandwidth only speeds up big files; with latency or server think time, going from 100 Mbps to gigabit leaves TTFB the same.
  • connect 5 ms but TTFB 3 s and blaming the network: the connect was fast, so the server is the problem.
  • Ignoring packet loss: a few drops cause TCP resends and long waits.
  • Looking only at total time instead of the breakdown.

275.9 Interview tips

  • Start with a curl -w breakdown: DNS, connect, TLS, TTFB, total.
  • Network side: latency and loss with ping + mtr, bandwidth with iperf3.
  • Big TTFB: look at server logs, the database and app code.
  • Give packet-level proof with tcpdump: the gap between request and first byte.
  • Say clearly: bandwidth is not latency; a bigger pipe does not reduce RTT.