ruby - rails profiler - oink ,集成了 memorylogic, 查看rails项目占用的内存

访问量: 41

参考:https://github.com/noahd1/oink

Gemfile: 

gem 'oink'

Rails.application.middleware.use Oink::Middleware

之后重启rails, 看log

(会发现每次请求url之后, 内存会上升。。。找到明显上升的地方即可)

106 Dec 03 08:20:59 main-production-japan rails[33573]: Oink Action: private/managements#index
107 Dec 03 08:20:59 main-production-japan rails[33573]: Memory usage: 1151276 | PID: 33573
108 Dec 03 08:20:59 -main-production-japan rails[33573]: Instantiation Breakdown: Total: 4 | Manager: 2 | Role: 2
109 Dec 03 08:20:59 -main-production-japan rails[33573]: Oink Log Entry Complete
110 Dec 03 08:25:55 -main-production-japan rails[33573]: Oink Action: private/withdraws#index
111 Dec 03 08:25:55 -main-production-japan rails[33573]: Memory usage: 1151276 | PID: 33573
112 Dec 03 08:25:55 -main-production-japan rails[33573]: Instantiation Breakdown: Total: 474 | Currency: 170 | Withdraw: 100 | Member: 100 |
113 Dec 03 08:25:55 -main-production-japan rails[33573]: Oink Log Entry Complete
114 Dec 03 08:25:57 -main-production-japan rails[33573]: Oink Action: private/withdraws#index
115 Dec 03 08:25:57 -main-production-japan rails[33573]: Memory usage: 1151276 | PID: 33573
116 Dec 03 08:25:57 -main-production-japan rails[33573]: Instantiation Breakdown: Total: 474 | Currency: 170 | Withdraw: 100 | Member: 100 |
117 Dec 03 08:25:57 -main-production-japan rails[33573]: Oink Log Entry Complete
118 Dec 03 08:26:01 -main-production-japan rails[33573]: Oink Action: private/withdraws#index
119 Dec 03 08:26:01 -main-production-japan rails[33573]: Memory usage: 1216812 | PID: 33573
120 Dec 03 08:26:01 -main-production-japan rails[33573]: Instantiation Breakdown: Total: 474 | Currency: 170 | Withdraw: 100 | Member: 100 |
121 Dec 03 08:26:01 -main-production-japan rails[33573]: Oink Log Entry Complete

然后,使用oink 来分析日志

$ oink <log_file>

---- MEMORY THRESHOLD ----
THRESHOLD: 75 MB

-- SUMMARY --
Worst Requests:
1. Dec 03 10:26:15, 19091140 KB, managers/sessions#new
2. Dec 03 10:22:44, 5642988 KB, managers/sessions#create
3. Dec 03 10:16:11, 4153928 KB, disputes#index
4. Dec 03 10:15:41, 4058000 KB, disputes#force_release
5. Dec 03 10:17:30, 3744456 KB, managers/sessions#new
6. Dec 03 10:17:03, 3737700 KB, disputes#force_release
7. Dec 03 10:15:03, 3300212 KB, private/members#edit_inviter_code
8. Dec 03 10:12:54, 2885724 KB, private/members#create_id_card
9. Dec 03 10:13:11, 2339664 KB, managers/sessions#create
10. Dec 03 10:14:24, 1155164 KB, private/members#show

Worst Actions:
40, private/actual_k_lines#index
19, private/members#index
16, managers/sessions#new
11, private/members#edit
6, scheduled_unlockings#import
6, disputes#index
5, private/managements#index
3, managers/sessions#create


Aggregated Totals:
Action                                                	Max	Mean	Min	Total	Number of requests
managers/sessions#new                                  19091140 1648466	101340 26375460 16
private/members#index                                 	1128612	452494	131072	8597392	19
private/actual_k_lines#index                          	271284	206140	131072	8245636	40
managers/sessions#create                              	5642988	2713917	159100	8141752	3
disputes#force_release                                	4058000	3897850	3737700	7795700	2
disputes#index                                        	4153928	1051313	195496	6307880	6

订阅/RSS Feed

Subscribe

分类/category