首页/系统/Linux 运维命令速查/场景:接口耗时分解巡检
本包目录(613 条)
文件与目录76 条文本处理77 条
网络命令82 条
进程与作业69 条磁盘与文件系统51 条用户与权限44 条日志与排查40 条systemd 与服务42 条包管理34 条性能与监控48 条定时任务与计划50 条

场景:接口耗时分解巡检

把「接口慢」拆成 DNS、连接、TLS、TTFB、下载五段:用 curl -w 输出的指标定位瓶颈环节,可批量对比。

Linux 运维命令速查系统更新于 2026-10-12
场景接口/页面性能瓶颈定位
组合curl -w 分段计时 + 结果汇总

单次分解

单次分解
curl -sS -o /dev/null -w 'dns=%{time_namelookup} conn=%{time_connect} tls=%{time_appconnect} ttfb=%{time_starttransfer} total=%{time_total} size=%{size_download}\n' https://example.com/

批量对比

批量对比
while read -r url; do
  curl -sS -o /dev/null --max-time 10 -w '%{time_total} %{time_starttransfer} %{time_connect} %{http_code} ' "$url"
  echo "$url"
done < urls.txt | sort -rn | head
各段含义:namelookup=DNS;connect=TCP 握手(含 DNS);appconnect=TLS;starttransfer=首字节;total=整体。

易错点

  • time_connect 包含 time_namelookup,排查时算「差值」才是 TCP 握手本身
  • 重复请求受 DNS 缓存与连接复用影响:冷启动/热启动结果差异要区分记录

数据来源与参考

  • curl 官方文档(curl.se/docs/manpage.html)

相关工具

​‌‌​​‌​​​‌‌​‌‌‌‌​‌‌​​​‌‌​‌‌‌​​‌‌​​‌​‌‌‌​​‌‌‌​​​‌​‌‌​‌​​‌​‌‌‌​​​‌​‌‌​‌​​‌​‌‌​​​‌‌​‌‌‌​‌​​​‌‌​‌‌‌‌​​‌​‌‌‌​​‌‌​​​‌‌​‌‌​‌‌‌‌​‌‌​‌‌​‌