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

bcrypt.compare very slow on production servers #42

Closed
adamreisnz opened this issue Sep 8, 2016 · 7 comments
Closed

bcrypt.compare very slow on production servers #42

adamreisnz opened this issue Sep 8, 2016 · 7 comments

Comments

@adamreisnz
Copy link

I am using the bcryptjs library in a Node project and am comparing a password that has been salted with 15 rounds. On any of my computers, this comparison is done in about 150ms. However, on Heroku servers, this comparison takes 8-9 seconds (for a 18 character password):

Sep 9 10:09:58 app[web] info Comparing password: 8967.025ms
Sep 9 10:12:25 app[web] info Comparing password: 8562.370ms

After switching to bcrypt for comparison, it reduced to about 2.5 seconds:

Sep 9 10:15:38 app[web] info Comparing password: 2635.010ms

While about 3.5 times faster, this still seems rather long compared to running on a local machine. Is it memory or processing power that affects this duration?

@dcodeIO
Copy link
Owner

dcodeIO commented Sep 8, 2016

Looks like an issue with processing power to me. Also, if you have the opportunity to use native packages, you should favor bcrypt instead of this library.

@adamreisnz
Copy link
Author

Yep I've switched it bcrypt now, that's at least somewhat faster, but still 10x as slow as on a local machine :(

@julianlam
Copy link

By any chance... are you using 16.04 in your dyno?

@adamreisnz
Copy link
Author

Nah, it runs on the cedar-14 stack, which is Ubuntu 14.04

@julianlam
Copy link

Oh well. I happen to be running into the same problem on DigitalOcean via their 16.04 image.

@Smert
Copy link

Smert commented Dec 26, 2016

EventLoop blocking:

  console.time('A');
  bcrypt.compare(record.password, admin.password, () => {});
  bcrypt.compare(record.password, admin.password, () => {});
  bcrypt.compare(record.password, admin.password, () => {});
  console.timeEnd('A');

A: 410.287ms

After switching to bcrypt

A: 5.101ms

WOW

@Ruffio
Copy link

Ruffio commented Sep 27, 2017

It looks like this 'issue' can be closed now...

@dcodeIO dcodeIO closed this as completed Sep 27, 2017
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

5 participants