From 09937f33e566e783c1db9a8ca03db8735e82ef24 Mon Sep 17 00:00:00 2001 From: Micooz Date: Sun, 1 Jul 2018 17:36:32 +0800 Subject: [PATCH] transports: disables the Nagle algorithm, enable keep-alive functionality of tcp --- src/transports/tcp.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/transports/tcp.js b/src/transports/tcp.js index cee4746..0270e89 100644 --- a/src/transports/tcp.js +++ b/src/transports/tcp.js @@ -30,6 +30,8 @@ export class TcpInbound extends Inbound { this._socket.on('timeout', this.onTimeout); this._socket.on('end', this.onHalfClose); this._socket.on('close', this.onClose); + this._socket.setNoDelay(true); + this._socket.setKeepAlive(true); this._socket.setTimeout && this._socket.setTimeout(this._config.timeout); } @@ -299,6 +301,8 @@ export class TcpOutbound extends Outbound { this._socket.on('timeout', this.onTimeout); this._socket.on('data', this.onReceive); this._socket.on('drain', this.onDrain); + this._socket.setNoDelay(true); + this._socket.setKeepAlive(true); this._socket.setTimeout(this._config.timeout); } catch (err) { logger.error(`[${this.name}] [${this.remote}] cannot connect to ${targetHost}:${targetPort}, ${err.message}`);