DEV Community

loading...

Discussion on: How to Manage Multiple Threads in Node JS

Collapse
johnjardincodes profile image
💻 JOHN JARDIN | Bleeding Code Author

Hi there thank you very much for watching and for the comment.

So, with my 2nd point...take note that I used the "bcryptjs", and not the well known "bcrypt" module, which would get offloaded to the libuv thread-pool because it runs on the OS level. "bcryptjs" is purposely designed to be written completely in JavaScript and to be synchronous, because it's actually a security feature to hash passwords synchronously and cause the delay.

I hope that clears up my 2nd point? Below is from their NPM Docs:

"While bcrypt.js is compatible to the C++ bcrypt binding, it is written in pure JavaScript and thus slower (about 30%), effectively reducing the number of iterations that can be processed in an equal time span."

Collapse
srikanth597 profile image
srikanth597

yes, it makes all sense now.
Thanks for your efforts,
But I wonder what kind of such huge computational tasks exists especially on DB operations from Node.js programs so that I could use these techniques to improve the performance w.r.t to DB operations

Thread Thread
johnjardincodes profile image
💻 JOHN JARDIN | Bleeding Code Author

Always a pleasure. Most of the time it's going to come to advanced business logic that needs to perform a series of processes on returned data from DB or 3rd party queries, etc.

What you always want to be doing is keeping the primary thread and event loop spinning as fast as it can and processing those incoming requests. The moment you have tasks that contain synchronous logic that cause even the slightest of delays, hand it over to Worker Pool 👍.