Confusing output from time
This command gets some data from MySQL and then manipulates it. Why is the 'real' time so much higher than the 'user' time?
>time ./command.rb
real 45m45.457s
user 3m36.478s
sys 0m28.226s
For clarification - I understand the difference between the real, user, and sys output. However, I am c开发者_StackOverflow中文版onfused at why there is such a great difference. The machine I am running this on has virtually nothing else using the CPU, and I don't have any threading in my command. All it does is fetch data. Could a complex MySQL statement be the cause of such a gap?
user and sys report the amount of time the cpu is busy. The CPU won't be busy when blocked on anything, like network or disk I/O. Try, e.g., "time sleep 1", or "time dd if=/dev/zero of=/dev/null bs=1024 count=1000000" to see the differences. The first just blocks, the second will include a lot of CPU use.
The system is spending most of its time waiting for disks to spin and heads to seek.
The "user" time is the time actually spent by the CPU crunching numbers for you.
The "real" time is the amount of actual wall-clock time that passed, where the "user" and "sys" times are the amount of CPU time used for your job in each class of processing. For the "real" time to be so much higher, your job probably spent a lot of time waiting for resources or sleeping.
Just a guess, but if you are viewing the results over an ssh connection, it may be possible that much of your time is waiting for the processor to encrypt the data to be sent to your remote console.
精彩评论