Daninet / hash-wasm

Lightning fast hash functions using hand-tuned WebAssembly binaries
https://npmjs.com/package/hash-wasm
Other
881 stars 49 forks source link

Web Worker support for bcrypt in Deno #31

Closed beingflo closed 3 years ago

beingflo commented 3 years ago

I'm implementing a service with oak and use bcrypt for hashing passwords. It appears to me that the bcrypt call is blocking the main thread in Deno, as no other request is served while a costly hash is running. Am I misunderstanding web workers or is this not supported for bcrypt?

Thanks for your work!

Daninet commented 3 years ago

All algorithms should work within web workers. There is nothing special in bcrypt.

I don't have a lot of experience with Deno, but according to the docs it seems to behave similarly to Node.js: execution is single-threaded even if you have async code.

So, if you don't want to block the main thread, you will have to create web workers and compute hashes there.

Daninet commented 3 years ago

When writing backends, the traditional solution in Node.js is to create a "cluster" of backend instances. So basically you run multiple backend processes with all of them listening on the same port.

beingflo commented 3 years ago

Aha, I misunderstood the documentation to mean that the worker is already built into the library. Starting a worker at the call site works as expected. Thanks!