I need send a http request to another server. I can do this in two ways: 1) using http.request() 2) using child_process.exec
// ... define timeout, data, url
var __exec = require('child_process').exec;
exec('curl --max-time ' + timeout + ' -d \'' + data + '\' ' + url, function (error, stdout, stderr) {});
In the first case, the minimum execution time is 0.08 seconds. In the second case - 0.04 seconds
Which problems can appear in case, if i use the second option? Especially in case of high-load on server.
Thanks.
Benchmark1:
//...
timeStart = +new Date().getTime();
request = http.request(options, function (result) {
//...
result.on('end', function () {
timeEnd = (+new Date().getTime() - timeStart) / 1000;
// log timeEnd
});
});
request.on('error', function (error) {
timeEnd = (+new Date().getTime() - timeStart) / 1000;
// log timeEnd
});
request.end();
Benchmark2:
// ...
timeStart = +new Date().getTime();
exec('curl --max-time ' + timeout + ' -d \'' + data + '\' ' + url, function (error, stdout, stderr) {
timeEnd = (+new Date().getTime() - timeStart) / 1000;
// log timeEnd
});