curl -w로 요청 어느 구간이 느린지 보기
조회 2 · 댓글 0
API 응답이 느린데 서버 처리가 느린 건지 연결이 느린 건지 가를 때, curl의 -w(--write-out)로 단계별 소요 시간을 찍어볼 수 있습니다. 본문은 버리고 타이밍만 보면 되니 -o /dev/null -s와 같이 씁니다.
curl -s -o /dev/null -w "dns: %{time_namelookup}\ntcp: %{time_connect}\ntls: %{time_appconnect}\nttfb: %{time_starttransfer}\ntotal: %{time_total}\n" https://api.example.com/health주의할 점은 이 값들이 전부 "요청 시작부터 그 시점까지의 누적 시간"이라는 겁니다. 공식 문서 기준 time_namelookup은 이름 해석 완료까지, time_connect은 TCP 연결 완료까지, time_appconnect은 TLS 핸드셰이크 완료까지, time_starttransfer은 첫 바이트를 받기 직전까지 걸린 시간입니다. 그래서 순수 서버 처리 시간을 보려면 time_starttransfer - time_appconnect처럼 인접 값을 빼야 합니다. ttfb는 큰데 앞 단계가 작으면 서버가 느린 것이고, time_connect나 time_appconnect가 크면 네트워크나 TLS 쪽을 의심하면 됩니다.
🔗 https://everything.curl.dev/usingcurl/verbose/all-variables.html
로그인 후 답글을 남길 수 있습니다.