CodePark/ questions / Debugging a server in production
START PRACTICINGPRACTICE
Backend question · OS, networking & Linux › Debugging a server in production

An endpoint feels slow when called from one server. How can curl show where the time goes, and what does this output tell you?

$ curl -s -o /dev/null -w "dns:%{time_namelookup} connect:%{time_connect} tls:%{time_appconnect} ttfb:%{time_starttransfer} total:%{time_total}\n" https://api.example.com/orders
dns:0.004 connect:0.015 tls:0.042 ttfb:1.873 total:1.880

Use curl -w to print timing variables after the request. Each time is measured from the start of the request, so the times add up (they are cumulative). To get the length of one phase, subtract the previous value from it.

What each variable means:

  • time_namelookup: when DNS finished.
  • time_connect: when the TCP handshake finished. Connect minus namelookup is about one network round trip.
  • time_appconnect: when the TLS handshake finished.
  • time_starttransfer: when the first byte of the response arrived. Starttransfer minus appconnect is the server's processing time plus one round trip.
  • time_total: when everything finished. Total minus starttransfer is the time to download the body.

In this output, DNS, TCP and TLS together take about 40 ms. But the first byte arrives at 1.87 s. So the server's handler is slow, not the network.

Other patterns: a large namelookup points to DNS. A large connect points to distance or packet loss. curl -v adds headers and handshake details.

  • curl -w times are cumulative, measured from the start of the request.
  • namelookup is DNS, connect is TCP, and appconnect is TLS.
  • starttransfer is the time to first byte; starttransfer minus appconnect is mostly server time.
  • Subtract each value from the next one to find the slow phase.