Reputation: 139
In a linux shell script I am running time against a curl request to a REST service.
Assuming a single thread, if I take the real time of the result and subtract the user and sys time would the remaining time be considered the aggregation of the network latency and the time the service required to complete the request?
If not, is there a simple way to get the network latency and time the service required to complete the request from the linux shell?
Reference:What do 'real', 'user' and 'sys' mean in the output of time(1)?
Upvotes: 0
Views: 2024
Reputation: 18697
If you are using curl
, the simplest way to get details on request timings would be to use the -w
/--write-out
option.
You can format the output to include variables like:
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.
For example:
$ 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
And to answer your direct question - no, subtracting process and process kernel time from wall clock time will not, in general, give you the network latency or response time. Consider the system with many processes competing for CPU: in that case the wall clock for your curl
process can be significantly longer than the actual service response time.
Upvotes: 3