Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Huge memory hole with restful_auth in Rails 3 #11

Open
jensb opened this issue Mar 20, 2011 · 2 comments
Open

Huge memory hole with restful_auth in Rails 3 #11

jensb opened this issue Mar 20, 2011 · 2 comments

Comments

@jensb
Copy link

jensb commented Mar 20, 2011

I'm experiencing a huge memory leak issue in Rails 3.0.4 and 3.0.5. Both on WEBrick and Apache Passenger 3.0.3, both on OS X and Linux (Debian Lenny), using Ruby 1.8.7.

I had a Rails 2.3.10 application running with restful_auth, and upgraded it to 3.0.4. This is when the leak started. See also http://stackoverflow.com/questions/5369623/tracing-memory-leak-in-ruby-on-rails-3-postgres-apache-passenger-application.

class ApplicationController < ActionController::Base
  include AuthenticatedSystem
  include RoleRequirementSystem
  ...
end

With these two includes, "ab -n 1000 -c1" (Apachebench, 1000 requests) will make my WEBrick process grow from 60 MB to about 600-800 MB. This also happens in tests, because of the fact that the tests won't run when I don't use the above includes in test_helper.rb. (Why not?)

Without these two includes, the same apachebench will only make it grow about 20MB.

I suspect the two included modules are somehow implicitly preloading User, and doing this again on every request. User is (in my case) the object which should be authenticable, and fairly large, with about 50 associations; it probably triggers another heap of objects being preloaded.

Is there a way to avoid this behaviour?

Thanks!

@jensb
Copy link
Author

jensb commented Mar 21, 2011

I dug further and identified AASM (Acts As State Machine) as the probable cause for this. When I put "gem 'aasm'" in my Gemfile and "include AASM" in a model, the memory usage grows with each request, it seems, depending on how complex your state definitions are. See here: https://github.com/rubyist/aasm/issues/31

@jensb
Copy link
Author

jensb commented Mar 21, 2011

BTW: this only happens when cache_classes == false. (i.e. in development mode)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant