我可以使用 curl real time 减去 sys 和 user 来获得总响应时间吗
Can I use curl real time minus sys and user to generally get total response time
在 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 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
进程的挂钟可能比实际服务响应时间长得多。