当我这样做时 -
$ time curl 'http://localhost:3000'
我明白了:0.00s user 0.00s system 0% cpu 1.270 total
宝石'rack-mini-profiler'也显示时间与卷曲几乎相同。
但在rails日志中,我看到了 -
Completed 200 OK in 103ms (Views: 72.7ms | ActiveRecord: 5.0ms)
为什么有大约1秒的时差?
Curl和rails服务器都在我的开发机器上运行。
答案 0 :(得分:0)
“time curl”计算curl客户端获取Rails内容所需的时间,即它是客户端时间。
Rails日志显示服务器时间。
答案 1 :(得分:0)
您没有指定,但如果您正在运行开发模式,则会有类重新加载和资产编译,这会严重影响响应时间。但它不会影响生产。
这是我在rails 4.2应用程序中获得的内容(第一次卷曲,而不是日志中的相应摘录):
curl 'http://localhost:3000' 0.01s user 0.00s system 0% cpu 1.817 total
curl 'http://localhost:3000' 0.01s user 0.00s system 2% cpu 0.366 total
Completed 200 OK in 1254ms (Views: 1206.2ms | ActiveRecord: 13.9ms)
127.0.0.1 - - [04/Oct/2014:19:48:52 +0200] "GET / HTTP/1.1" 200 - 1.6863
Completed 200 OK in 279ms (Views: 278.7ms | ActiveRecord: 0.0ms)
127.0.0.1 - - [04/Oct/2014:19:49:41 +0200] "GET / HTTP/1.1" 200 - 0.2895
在制作中:
curl 'http://localhost:3000' 0.01s user 0.00s system 3% cpu 0.329 total
curl 'http://localhost:3000' 0.00s user 0.01s system 11% cpu 0.090 total
I, [2014-10-04T19:54:02.739988 #27830] INFO -- : Completed 200 OK in 143ms (Views: 123.0ms | ActiveRecord: 6.3ms)
I, [2014-10-04T19:54:17.521175 #27830] INFO -- : Completed 200 OK in 41ms (Views: 40.9ms | ActiveRecord: 0.0ms)
因此存在差异,但这可能是由于时间从curl发送请求到服务器然后接收响应。我仍然认为,重新加载和编译会导致更大的开发差异。