script-manager
node.js manager for running foreign and potentially dangerous scripts in the cluster
Basics
You can use node.js vm module for running a custom javascript code, but when the code is bad it can quickly get your node.js process into an endless loop. For this reason it is better to run users's custom code in a separate node process which you can recycle when the script reaches timeout. This can be achieved using node child_process module, but a simple implementation has limitations in performance and scale because running each script in a new node child process can quickly spawn whole system with node processes. This package solves the problem of running user's custom javascript code in a load balanced cluster of node processes which are reused over the requests and recycled when needed.
var path = var scriptManager = numberOfWorkers: 2 ; scriptManager;
/*script.jswrapper usually does some fancy thing and then runs the custom script using node.js vm module*/module { var result = ; ;};
Callbacks
The executing script can also callback to the caller process. The callback is provided using node.js
cross process messages so it has some limitations, but should work when transferring just common objects in parameters.
To provide caller callback you can add the callback
property to the execute
options:
scriptManager;
Then in the wrapper you can for example offer a function funcA
to the users script which uses callback parameter to contact the original caller.
module { var result = ; ;});
Options
var scriptManager = /* number of worker node.js processes */ numberOfWorkers: 2 /* set a custom hostname on which script execution server is started, useful is cloud environments where you need to set specific IP */ host: '127.0.0.1' /* set a specific port range for script execution server */ portLeftBoundary: 1000 portRightBoundary: 2000 /* maximum size of message sent/received from/to worker in http-server strategy, pass -1 to have no limit*/ inputRequestLimit: 200e6 /* switch to use dedicated process for script evalution, this can help with some issues caused by corporate proxies */ strategy: "http-server | dedicated-process | in-process" /* options passed to forked node worker process: { execArgv: ['�-max-old-space-size=128'] } */ forkOptions: {} ;
License
See license