If you're using passenger the quick workaround (just to minimize effects for now) could be killing worker after it grows too much: PassengerMaxRequests
Still we don't know what caused that. You might try to search for long requests and assume that they the one but long response doesn't need to mean memory leak.
You can easily count the number of objects created during the request.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#app/controllers/application_controller.rb | |
around_filter :log_objects_creation | |
protected | |
def log_objects_creation | |
started = ObjectSpace.count_objects[:T_OBJECT] | |
yield | |
elapsed = ObjectSpace.count_objects[:T_OBJECT] - started | |
MemoryLogger.info("#{Time.now}| #{elapsed}| #{params}| #{current_user.nil? ? '' : current_user.id}") if elapsed > 2000 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#config/initializers/memory_logger.rb | |
MemoryLogger = Logger.new("#{Rails.root}/log/ruby_memory.log") |
If you are using ruby 2.1 you can gather more detailed information: http://stackoverflow.com/questions/20956401/how-do-i-track-down-a-memory-leak-in-my-ruby-code