Parallelized Lambda, a wrapper to help run lambda/anonymous function in parallel easily.
PambdaJS is to orchestrate different child process to finish one heavy iteration work.
Start to use PambdaJS
import pambda from 'pambdajs';
const p = await pambda.init(5);
data = [1,2,3];
const heavyWork = (x) => {
return x+x;
}
// original single process way
const singleProcess = () => {
data.map(heavyWork);
}
// PambdaJS multi process way
const pambdaProcess = async () => {
await p.map(heavyWork, data);
}
Run your own anonymous functions in Parallel.
The lambda function itself has to be a pure function, and it has to use only node build-in packages.
for example:
// good
const heavyWork = (x) => {
return x+x;
}
// bad
const sumItSelf = (x) => {
return x + x;
}
const heavyWork = (x) => {
return sumItSelf(x)
}
The best case to repeat summing 10k number 100k times, is to spawn 5 child process, and it saves more than hald of time than single process.
Besides, for simple work, multi process does not help at all. So make sure usig PambdaJS for heavy work only. (more diagrams)
Yeah, why not. child_process is the native module of Node, if you seek better flexibility, use child_process. However, if you want to make your life easier, trust me use PambdaJS, you do not need to worry about the message between child and parent process anymore.
No, PambdaJS is a tool for Node environment, not for browser, because browser does not support multi-process, but you can try web worker which is multi-thread solution. or Gpu.js which is using GPU instead of CPU for getting better performance.
Author: tim-hub
Source Code: https://github.com/tim-hub/pambdajs
#nodejs #node #javascript