For some user requests, I need to do some heavy computations (taking about 100ms of time); and, of course, I do not want to perform these in node's main event loop so that it will prevent other requests from serving.
The most obvious, but definitely not the cleanest way to solve this problem would be to offload the computations to another program and wait for the results asynchronously.
Is there any way to do it without leaving the node process (and implementing inter-process communications)? E.g. something like this:
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);
});
}
child_process- basically it's the only way to instantiate external processes, so i don't understand why did you put "still" in your message. I'd like to do it without implementing IPC and writing another program though (especially considering the computation results might be partially cached); basically, the only way to do it right with the IPC is to run another node cluster with a lot of workers (more than # of cores) and to do IPC-over-http.