You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A NodeJS package for running code in parallel. Initially created to provide multiprocessing in an AWS Lambda function, but it can be used in any NodeJS environment.
2
+
A NodeJS package for running code in parallel. Initially created to provide multiprocessing in an **AWS Lambda function**, but it can be used in any NodeJS environment.
3
3
4
4
## Supported parallelizers
5
5
- Child Process
6
-
- Worker threads[Coming soon]
6
+
- Worker threads
7
7
8
8
### Child Process Parallelizer
9
-
This parallelizer is specifically designed for processing hundreds or thousands of records in a single invocation when your code performs both CPU-intensive and I/O-intensive operations. It uses the NodeJS [child process module](https://nodejs.org/api/child_process.html) behind the scenes.
9
+
This parallelizer is specifically designed for processing hundreds or thousands of records in a single invocation when your code performs both CPU-intensive and **I/O-intensive operations**.
10
10
11
11
When you call the `runBatch(records)` method in this parallelizer, the package will split the list of records you provide into smaller subsets, and your code will be used to execute each subset in parallel.
12
12
13
-
## AWS Lambda & Child Process Parallelizer
14
-
The package can detect the number of vCPU cores allocated to your Lambda function and maximize their utilization. By default, it generates one child process per vCPU core, but this setting can be customized to meet your specific requirements. Alternatively, you can manually specify the number of child processes the library creates, regardless of the number of vCPU cores available.
13
+
It uses the NodeJS [child process module](https://nodejs.org/api/child_process.html) behind the scenes.
14
+
15
+
### Worker Threads Parallelizer
16
+
This parallelizer is specifically designed for processing hundreds or thousands of records in a single invocation when your code performs **CPU-intensive operations**.
17
+
18
+
When you call the `runBatch(records)` method in this parallelizer, the package will split the list of records you provide into smaller subsets, and your code will be used to execute each subset in parallel.
19
+
20
+
It uses the NodeJS [worker threads module](https://nodejs.org/api/worker_threads.html) behind the scenes.
21
+
22
+
## AWS Lambda & Node Parallelizer
23
+
This package can detect the number of vCPU cores allocated to your Lambda function and maximize their utilization. By default, it generates one child process/thread per vCPU core, but this setting can be customized to meet your specific requirements. Alternatively, you can manually specify the number of child processes/threads the library creates, regardless of the number of vCPU cores available.
15
24
16
25
It uses the Lambda function environment `/tmp` folder to create the required module that runs in the child.
17
26
18
-
When you call the `parallelizerFunction` method outside of the Lambda handler function, it will reuse the child processes across the different invocations within a Lambda instance, improving performance. Furthermore, if the package detects a disconnection of any of the child processes, it will recreate it automatically without affecting the execution.
27
+
On the Child Process Parallelizer, when you call the `parallelizerFunction` method outside of the Lambda handler function, it will reuse the child processes across the different invocations within a Lambda instance, minimazing the impact of creating child process on every invocation. Furthermore, if the package detects a disconnection of any of the child processes, it will recreate it automatically without affecting the execution.
19
28
20
29
## Installation
21
30
To add this package to your dependency list, run:
@@ -24,34 +33,37 @@ To add this package to your dependency list, run:
-`tmpPath` (String) (Default value: '/tmp'): The path where the module that runs in the child will be created.
33
-
-`maxProcesses` (Number|false) (Default value: false): The maximum number of child processes that will be created. If false, it is based on the CPU cores available.
34
-
-`processesPerCPU` (Number) (Default value: 1): If the `maxProcesses` is set to `false`, this parameter defines the amount of processes per CPU.
45
+
-`maxParallelization` (Number|false) (Default value: false): The maximum number of child processes that will be created. If false, it is based on the CPU cores available.
46
+
-`parallelizationPerCPU` (Number) (Default value: 1): If the `maxParallelization` is set to `false`, this parameter defines the amount of processes per CPU.
35
47
-`debug` (Boolean) (Default value: false): Enables the internal logs for debuggin purposes.
> Make sure to provide the filePath parameter as an absolute path. In this example, we've included '/var/task/' in the path for the child code, as Lambda deploys your code within that folder.
90
+
> Make sure to provide the filePath parameter as an absolute path. In this example, we've included '/var/task/' prefix in the path because Lambda deploys your code within that folder.
79
91
80
92
The below snippet represents the code you want to run in parallel
> Verify that the input signature of your function (in this case, batchProcessor) includes batch as a parameter, as it contains the subset of records that a child process will handle.
-`tmpPath` (String) (Default value: '/tmp'): The path where the module that runs in the thread will be created.
120
+
-`maxParallelization` (Number|false) (Default value: false): The maximum number of threads that will be created. If false, it is based on the CPU cores available.
121
+
-`parallelizationPerCPU` (Number) (Default value: 1): If the `maxParallelization` is set to `false`, this parameter defines the amount of threads per CPU.
122
+
-`debug` (Boolean) (Default value: false): Enables the internal logs for debuggin purposes.
> Make sure to provide the filePath parameter as an absolute path. In this example, we've included '/var/task/' prefix in the path because Lambda deploys your code within that folder.
166
+
167
+
The below snippet represents the code you want to run in parallel
168
+
```javascript
169
+
// parallel.js
170
+
171
+
constbatchProcessor= ({ batch }) => {
172
+
173
+
//
174
+
// HERE YOUR CODE
175
+
//
176
+
177
+
return { success:true, count:batch.length }
178
+
}
179
+
180
+
181
+
module.exports= { batchProcessor }
182
+
183
+
```
184
+
> Verify that the input signature of your function (in this case, batchProcessor) includes batch as a parameter, as it contains the subset of records that a child process will handle.
185
+
186
+
</details>
98
187
99
188
## Contribution
100
-
We welcome contributions to this project. If you are interested in contributing, please feel free to submit a pull request.
189
+
We welcome contributions to this project. If you are interested in contributing, please feel free to submit a pull request.
Copy file name to clipboardExpand all lines: package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
{
2
2
"name": "node-parallelizer",
3
-
"version": "1.2.0",
3
+
"version": "2.0.0",
4
4
"description": "A NodeJS package for running code in parallel. Initially created to provide multiprocessing in an AWS Lambda function, but it can be used in any NodeJS environment.",
0 commit comments