1

I'have been trying out the module "tiny-worker", but I feel that it's pretty slow to communicate between a worker thread and main thread using postMessage and onmessage, is this generally slow, because nodejs doesn't natively support multithreading? is there any other way to optimize the process? maybe using other modules?

1 Answer 1

1

I have tried a couple of modules out in npm and there is not very noticeable difference in performance for doing multi-threading in nodejs. Node.JS essentially spawns up child processes for doing multi-threading and all modules you use does the same thing in the background. Some modules you can try are 1. https://nodejs.org/api/worker_threads.html 2. https://nodejs.org/api/child_process.html 3. https://www.npmjs.com/package/worker-farm 4. https://www.npmjs.com/package/cluster 5. https://www.npmjs.com/package/tiny-worker (which you tried) and there are much more but I have tried this 5 only

I would recommend before going to multi-threading in nodejs please read about it's advantages and disadvantages and check if you really need it for your use case.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.