http リクエストを別のサーバーに送信する必要があります。これは 2 つの方法で行うことができます: 1) http.request() を使用する 2) 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) {});
最初のケースでは、最小実行時間は 0.08 秒です。2 番目のケース - 0.04 秒
2 番目のオプションを使用した場合、どのような問題が発生する可能性がありますか? 特にサーバーの負荷が高い場合。
ありがとう。
ベンチマーク 1:
//...
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();
ベンチマーク 2:
// ...
timeStart = +new Date().getTime();
exec('curl --max-time ' + timeout + ' -d \'' + data + '\' ' + url, function (error, stdout, stderr) {
timeEnd = (+new Date().getTime() - timeStart) / 1000;
// log timeEnd
});