microjob | tiny wrapper for turning Node | Runtime Evironment library
kandi X-RAY | microjob Summary
kandi X-RAY | microjob Summary
Microjob is a tiny wrapper for Node.js threads and is intended to perform heavy CPU loads using anonymous functions. ~~So, Microjob treats Node.js threads as temporary working units: if you need to spawn a long-living thread, then you should use the default API.~~. From version v0.1.0 microjob uses a Worker Pool .
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of microjob
microjob Key Features
microjob Examples and Code Snippets
Community Discussions
Trending Discussions on microjob
QUESTION
I was looking around for my question but to no avail. I wanted to know if there was a way to force a worker to terminate a worker thread even if its task hadn't been completed. I have some code in there that calls itself if it somehow fails, which is intentional even though it might be bad code practice. I tried using libraries such as microjob and threads, but those didn't have what I wanted. Here is what I tried to do with threads but didn't work:
...ANSWER
Answered 2021-Feb-07 at 06:16I have solved my issue by using clusters in Node.JS, which uses the child_process
to run the workers.
Here is a link to the documentation if anyone needs it: https://nodejs.org/api/cluster.html
QUESTION
I'm trying to find a better way to run some cpu bound tasks using NodeJS. There are 2 options as I know, fork processes and worker threads. So I have ran a benchmark between them and found out that fork process is faster.
So, I have some questions here:
- Why is the fork process method faster?
- Are the worker threads useless? Or what are the worker threads advantages, consumes less cpu/memory?
I'm running the code on MacOS(2.2 GHz Intel Core i7, 16 GB 1600 MHz DDR3) using node v10.15.3
the benchmark code is in my gist:
threads pool library microjob and process pool library node-worker-farm are used in my code as you can see. The running cmd is : node --experimental-worker benchmark.js
ANSWER
Answered 2019-Jul-08 at 07:22I think @gireeshpunathil's comment from https://github.com/nodejs/help/issues/1920 can help a lot:
there is no single formulae that computes which method will be faster. It depends on a number of parameters:
- the running time of the job itself
- the interaction of the job with the spawning code
- the machine characteristics, specifically cpu, memory and scheduling
the fork uses native fork and exec, that is heavy-weight than thread creation. fork creates a new node instance with new v8, isolate, libuv etc. worker does not create new node instance. forked process uses IPC channel to talk to the forking process, if needed. workers use in-memory buffers.
So:
- if the execution time of the microjob is too small compared to the process creation, worker method will be faster.
- if the job communicates with the driver, the frequency of communication and the cost of communication will decide the winner
- if the job runs as long independent piece of code with no interaction, fork method will eventually prove faster (I think that
is happening here)
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install microjob
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page