For some user queries, I need to do some heavy calculations (about 100 ms of time); and, of course, I donβt want to execute them in the loop of the main node event, so that it does not allow serving other requests.
The most obvious, but certainly not the cleanest way to solve this problem is to upload the calculations to another program and wait for the results asynchronously.
Is there a way to do this without leaving the node process (and implementing interprocess communications)? For instance. something like that:
var compute = function (input) { var i, result = input; for (i = 0; i < 1000000; i++) { result = md5(result); } } var controller = function (req, res) { offload(compute, req.params.input, function(result) { res.send(result); }); }
source share