This is a bit odd and I am not sure what is really going on, but http requests have varying delays that sometimes become huge. I time it as,
process.time = new Date().getTime();
console.log('voice ' + voice)
var req = http.get(config.host_ip + ":" + config.host_port + "/sendSpeech/" + voice, function (response) {
response.on('data', function (d) {
console.log("TOTAL TIME " + (new Date().getTime() - process.time))
});
}).on('error', function (e) {
// Call callback function with the error object which comes from the request
});
req.end();
Sometimes, total time is sub second and other times it is upwards of 6 seconds. I timed the process that actually runs the function it is sending it to and it operates at less than 100 millisecond speeds.
If I do the call via the browser from the server it stands up, the call is often sub second. Significantly faster than calling it from a separate node application.
Does anyone know what is going on? The most connections that it handles is about 6-10 so I don't think the workload is especially heavy, although it runs on a raspberry pi.
Edit: I am using Node 5.4.1 .
Edit 2: I just tried switching to websockets via socket.io and the speed is about the same. Meaning I think the issue is network related.