I got a page which is generated in a few milliseconds.
Completed 200 OK in 83ms (Views: 75.9ms)
When I try to load this page with "time wget http://localhost:3000/search", I fould that it takes 1.5 seconds.
real 0m1.562s user 0m0.001s sys 0m0.003s
There's no js execution time in it as开发者_运维知识库 it's not loaded in browser. So what's the extra time for? Is there any tools that can figure out time cost details in rails? Thanks.
If Rails is loaded up in development, the controllers are not cached (by default) which can add to latency and might not be captured by Rails' measurement (can't say I've looked).
Another thing to look at is the Rack server in use. WEBrick works like a champ but is painfully slow; Thin and Unicorn are significantly faster at servicing requests. I would consider looking into using Rack middleware or Rails Metal if you need an action to be optimized for speed.
At the TCP level, the localhost->127.0.0.1 DNS lookup will take some small amount of time. Also, wget has to establish a new socket to the app. Neither of these will be measurable by the app itself.
For what it's worth, that same experiment against a Rails 2.3.12 app running on Unicorn 4.0.1 hitting the login page:
Completed in 16ms (DB: 4) | 302 Found [http://localhost/]
real 0m0.407s
user 0m0.000s
sys 0m0.010s
Update 9/28/2011:
Digging in at the HTTP layer, curl supports tracing a URL request with timestamp outputs:
curl --trace-ascii trace.log --trace-time http://localhost:3000
To dig a bit further and see the actual calls, try using strace with timing mode on:
strace -T curl http://localhost:3000
Example output from both of these is available as a gist.
精彩评论