Rails 4 Login Performance very slow
Not sure if this has been mentioned before or maybe I am the only one experiencing this issue but when logging in using devise I am waiting almost a minute before being authenticated. I know that there is stretches option but i didn't think it would slow down the request this much even at a value of 1. I am using a very basic setup with custom controllers that use the strong parameters override snippet found in the devise instructions and I am permitting the user to login with either the username or email. So i permit the :login attribute and create an attr_accessor for it. It logs in just fine but takes very long.
Any help would be greatly appreciated.
Could you share some info from your requests logs and more details of your application? It's hard to diagnose anything related to performance without such kind of information.
So this is not something you have heard of or experienced? I mean it is a fairly simple setup. Not sure if the query is causing a problem or the redirect. I should also mention i'm using postgresql if that matters at all.
Here is the request log:
Started POST "/users/login" for 192.168.8.208 at 2013-05-08 23:59:53 -0400 Processing by Users::SessionsController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"M1KDzw4wZ8gCDmiTjdnF4P+lSJN87ZV2arxq23jpwFw=", "user"=>{"login"=>"grex", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Login"} [1m[35mUser Load (1.2ms)[0m SELECT "users".* FROM "users" WHERE (lower(username) = 'grex' OR lower(email) = 'grex') ORDER BY "users"."id" ASC LIMIT 1 Redirected to http://192.168.8.208/ Completed 302 Found in 87406ms (ActiveRecord: 4.3ms)
I am also using Rails 4.0.0.rc and devise 3.0.0.rc
@grex84 inside your Rails console, what is the value of Devise.stretches?
10 I configured the stretch within my model.
You'll need to configure the stretches on a Rails.env basis - 1 for test and 10 for development/production. The stretches is intended to set the bcrypt work factor for password hashing and there's no reason to set it to 10 for test mode. Large stretches value is definitely what is causing your request to take a long time. The default devise.rb has config that you can copy for this:
config.stretches = Rails.env.test? ? 1 : 10
I have tried this already with the default settings and I get the same results. I have tries recreating my project with a fresh install of rails 4 and I get the same problem. Even with a stretch of 10, a minute and a half seems very long still. No?
On Friday, May 10, 2013, Drew Ulmer wrote:
You'll need to configure the stretches on a Rails.env basis - 1 for test and 10 for development/production. The stretches is intended to set the bcrypt work factor for password storage and there's no reason to set it to 10 for test mode and that is definitely what is causing your request to take a long time. The default devise.rbhttps://github.com/plataformatec/devise/blob/master/lib/generators/templates/devise.rb#L86has config that you can copy for this:
config.stretches = Rails.env.test? ? 1 : 10
— Reply to this email directly or view it on GitHubhttps://github.com/plataformatec/devise/issues/2411#issuecomment-17726123 .
If you have tried it with a fresh project, please push it to Github so we can take a look at it.
Regenerating my devise user model and re-migrating everything fixed the issue. Thanks for your help guys!