gpt4 book ai didi

linux - 我可以使用 curl real time 减去 sys 和 user 来获得总响应时间吗

转载 作者:太空宇宙 更新时间:2023-11-04 09:17:19 27 4
gpt4 key购买 nike

在 linux shell 脚本中,我正在针对对 REST 服务的 curl 请求运行时间。

假设一个线程,如果我获取结果的实时时间并减去用户和系统时间,剩余时间是否会被视为网络延迟和服务完成请求所需时间的总和?

如果没有,是否有一种简单的方法来获取网络延迟和服务完成 linux shell 请求所需的时间?

引用:What do 'real', 'user' and 'sys' mean in the output of time(1)?

最佳答案

如果您使用的是 curl,获取请求计时详细信息的最简单方法是使用 -w/--write-out选项。

您可以格式化输出以包含如下变量:

time_appconnect The time, in seconds, it took from the start until the SSL/SSH/etc connect/handshake to the remote host was completed. (Added in 7.19.0)

time_connect The time, in seconds, it took from the start until the TCP connect to the remote host (or proxy) was completed.

time_namelookup The time, in seconds, it took from the start until the name resolving was completed.

time_pretransfer The time, in seconds, it took from the start until the file transfer was just about to begin. This includes all pre-transfer commands and negotiations that are specific to the particular protocol(s) involved.

time_redirect The time, in seconds, it took for all redirection steps include name lookup, connect, pretransfer and transfer before the final transaction was started. time_redirect shows the complete execution time for multiple redirections. (Added in 7.12.3)

time_starttransfer The time, in seconds, it took from the start until the first byte was just about to be transferred. This includes time_pretransfer and also the time the server needed to calculate the result.

time_total The total time, in seconds, that the full operation lasted. The time will be displayed with millisecond resolution.

例如:

$ curl httpbin.org/ip -s -o output -w 'dns: %{time_namelookup} sec\nconnect: %{time_connect} sec\nuntil first byte: %{time_starttransfer} sec\ntotal: %{time_total} sec\n'
dns: 0.061 sec
connect: 0.297 sec
until first byte: 0.502 sec
total: 0.502 sec

回答您的直接问题 - 不,从挂钟时间减去进程和进程内核时间通常不会给您网络延迟或响应时间。考虑具有许多进程竞争 CPU 的系统:在这种情况下,您的 curl 进程的挂钟可能比实际服务响应时间长得多。

关于linux - 我可以使用 curl real time 减去 sys 和 user 来获得总响应时间吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45763622/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com