https://github.com/stjepangolemac/pareach
a tiny function that "parallelizes" work in NodeJS
https://github.com/stjepangolemac/pareach
concurrent node nodejs parallel processing
Last synced: about 1 year ago
JSON representation
a tiny function that "parallelizes" work in NodeJS
- Host: GitHub
- URL: https://github.com/stjepangolemac/pareach
- Owner: stjepangolemac
- License: mit
- Created: 2020-06-07T18:14:53.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-07-13T06:56:52.000Z (almost 3 years ago)
- Last Synced: 2025-03-18T10:48:26.677Z (about 1 year ago)
- Topics: concurrent, node, nodejs, parallel, processing
- Language: JavaScript
- Homepage: https://sgolem.com
- Size: 29.3 KB
- Stars: 19
- Watchers: 0
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# parEach - a tiny function that "parallelizes" work for NodeJS
## How to install:
```
npm install pareach
```
## How to use:
```
const parEach = require('pareach');
await parEach(work, args[, options]);
```
- `work` - an async function that accepts the args provided
- `args` - an array of arguments to call the `work` function (if you pass more than one then use a nested array `[['foo', 'bar'], ...]`)
- `options` - a configuration object
- `concurrencyLimit` - which is `5` by default, controls concurrency per thread
- `parallel` - process work with multiple threads
## Example of parallel processing
```
await parEach(work, args, { concurrencyLimit: 10, parallel: true });
```
This was will spawn a thread for every logical CPU and split the work.
## Performance
```
Sequential took 155.45 seconds
Batched took 16.04 seconds
Parallelized took 3.55 seconds
```
This was made for the article:
[Kicking Node into high gear for data processing or how to hire 100 cats to catch a mouse](https://sgolem.com/)