简体   繁体   English

如何在Rails 3应用程序中配置memprof?

[英]How to configure memprof in a Rails 3 application?

(First of all I don't speak english as well as I wish, I hope you forgive my mistakes :S ) (首先,我的英语说得不好,希望您能原谅我的错误:S)

I am very newbie with Ruby and Rails and I am very confused and frustrated because of the memory leaks that I'm having in my application when it runs in production mode. 我是Ruby和Rails的新手,由于在生产模式下运行应用程序时发生内存泄漏,我感到非常困惑和沮丧。

My server is shutting down my app because it reaches 800MB of memory :O I've google about it and I found that one solution is to use a tool to find leaks: Bleackhouse (I have not managed to install the application) or memprof (no problems to install it) . 我的服务器正在关闭我的应用程序,因为它达到了800MB的内存:我已经在Google上搜索了,发现一种解决方案是使用一种工具来查找泄漏:Bleackhouse(我尚未设法安装该应用程序)或memprof(没问题安装)。

I install memprof with: 我用以下命令安装memprof:

$ gem install memprof

Once installed I could use it with "irb" and test it, but it is imposible to me to make it run with my Rails 3 application, I know it is because I am very rookie with Rails :( 一旦安装,我可以将其与“ irb”一起使用并对其进行测试,但是我无法使其与我的Rails 3应用程序一起运行,我知道这是因为我对Rails非常新手:(

I have read too much webs, tutos and slides about memprof but I can't found any reference that explains how to install it in Rails. 我已经阅读了太多有关memprof的网络,教程和幻灯片,但是找不到任何说明如何在Rails中安装它的参考。

I add these line to my config/environment.rb 我将这些行添加到我的config / environment.rb

require `gem which memprof/signal`.strip

config/environment.rb: config / environment.rb:

# -*- encoding : utf-8 -*-

require `gem which memprof/signal`.strip

# Load the rails application
require File.expand_path('../application', __FILE__)

# Initialize the rails application
NameApp::Application.initialize!

but when I run my app (Apache + Phusion Passenger) it throws an error: 但是当我运行我的应用程序(Apache + Phusion Passenger)时,它会引发错误:

"Ruby (Rack) application could not be started"

A source file that the application requires, is missing.
It is possible that you didn't upload your application files correctly. Please check whether all your application files are uploaded.
A required library may not installed. Please install all libraries that this application requires.

Error message:
no such file to load --

/path/to/my/app/config/environment.rb   3   in `require'
...

I really don't know why I could run memprof in irb but I can't use it with my Rails application. 我真的不知道为什么我可以在irb中运行memprof,但不能在Rails应用程序中使用它。


Edit 1: 编辑1:

I do the advices that Frederick Cheung give, and now I got it running but I don't know how to start it and write the data to a json file :S 我执行了Frederick Cheung的建议,现在我开始运行它,但是我不知道如何启动它并将数据写入json文件:S

I would be very grateful if someone could help me with this issue. 如果有人可以帮助我解决这个问题,我将不胜感激。

Thanks. 谢谢。

With the signal stuff you just need to send a URG signal (kill -s URG pid) and it will write to a file in /tmp 使用信号东西,您只需要发送一个URG信号(kill -s URG pid),它将写入/ tmp中的文件

You can also use use the middleware that memprof includes ( see the documentation 您还可以使用memprof包含的中间件( 请参阅文档

There are two middlewares, that allow you to wrap each request either with Memprof.track or Memprof.trace_request . 有两种中间件,使您可以使用Memprof.trackMemprof.trace_request包装每个请求。 You can turn them on by putting this in an initialiser (in config/initializers) 您可以通过将其放入初始化程序(在config / initializers中)来打开它们

require 'memprof/middleware'
config.middlewares.use(Memprof::Middleware)

require 'memprof/tracer'
config.middleware.insert(0, Memprof::Tracer)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM