When creating a TCP server/client connected through the loopback address in NodeJS, I'm getting 1-2 ms round trip times for simple, low-data messages.
I don't have too much context for how fast Node should be, but it seems that it should be <1ms as there aren't very many operations going on and loopback ping times are in the microseconds.
Is there some buffering built into the net package that I'm missing, or is this latency to be expected?
Server:
var net = require('net');
var server = net.createServer((socket) => {
socket.setNoDelay();
setInterval(()=>{
socket.write(process.hrtime.bigint().toString());
}, 1000)
socket.on('data', (data)=>{
console.log("Completed in: " + parseFloat((process.hrtime.bigint() - BigInt(data))/BigInt(1e3))/1000 + "ms")
})
});
server.listen(1337, '127.0.0.1');
Client:
var net = require('net');
var client = new net.Socket();
client.connect(1337, '127.0.0.1', () => {
console.log('Connected');
});
client.on('data', (data) => {
client.write(data.toString());
});
client.on('close', () => {
console.log('Connection closed');
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…