我在rails console中看到了这些统计信息
879ms完成200 OK(浏览次数:57.5ms | ActiveRecord:3.2ms)
您可以看到视图加载时间和活动记录时间需要~60ms。但相反,加载时间为879毫秒。其他800毫秒可归于何处? (有时高达2000毫秒)
完整追踪
Started GET "/index" for 127.0.0.1 at 2017-03-17 02:10:13 +0200
Processing by HomeController#index as HTML
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 2]]
User Exists (0.6ms) SELECT 1 AS one FROM "users" WHERE ("users"."firstname" = 'Andr' AND "users"."id" != 2 AND "users"."is_artist" = 't') LIMIT 1
User Exists (0.4ms) SELECT 1 AS one FROM "users" WHERE ("users"."cname" = 'chic' AND "users"."id" != 2 AND "users"."is_artist" = 't') LIMIT 1
User Exists (0.4ms) SELECT 1 AS one FROM "users" WHERE ("users"."email" = 'pk00218@surrey.ac.uk' AND "users"."id" != 2 AND "users"."is_artist" = 't') LIMIT 1
User Exists (0.4ms) SELECT 1 AS one FROM "users" WHERE ("users"."spotify_name" = 'nickelback' AND "users"."id" != 2 AND "users"."is_artist" = 't') LIMIT 1
User Exists (0.2ms) SELECT 1 AS one FROM "users" WHERE ("users"."soundcloud_link" = 'nickelback' AND "users"."id" != 2 AND "users"."is_artist" = 't') LIMIT 1
Rendered layouts/_search_bar.html.erb (0.3ms)
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."is_artist" = $1 [["is_artist", "t"]]
Tagging Load (0.4ms) SELECT "taggings".* FROM "taggings" WHERE "taggings"."user_id" IN (1, 2)
Tag Load (0.3ms) SELECT "tags".* FROM "tags" WHERE "tags"."id" IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30)
Rendered shared/_artist_tile.html.erb (3.4ms)
Rendered shared/_artist_tile.html.erb (1.6ms)
Rendered shared/_artist_tile.html.erb (1.6ms)
Rendered home/index.html.erb within layouts/application (17.6ms)
(0.2ms) SELECT COUNT(*) FROM "collective_requests" WHERE "collective_requests"."receiver_id" = $1 AND "collective_requests"."accepted" IS NULL [["receiver_id", 2]]
CACHE (0.0ms) SELECT COUNT(*) FROM "collective_requests" WHERE "collective_requests"."receiver_id" = $1 AND "collective_requests"."accepted" IS NULL [["receiver_id", 2]]
Rendered layouts/_navlinks.html.erb (3.1ms)
Rendered layouts/_header.html.erb (4.8ms)
Rendered layouts/_footer.html.erb (1.1ms)
Completed 200 OK in 879ms (Views: 57.5ms | ActiveRecord: 3.2ms)
Rails版本 4.2.6
答案 0 :(得分:1)
Rails无法测量代码所做的一切(例如,连接到Redis,方法中的复杂逻辑)。您需要像New Relic这样的APM工具来确定代码的哪一部分很慢。
以下是每种方法和时间的示例跟踪:
参考 - https://blog.newrelic.com/2012/06/21/adventures-in-performance-tuning/