From 41e24ee4f2a0d43019bcd07966050092a7d3166e Mon Sep 17 00:00:00 2001 From: luin Date: Fri, 2 Dec 2016 17:08:07 +0800 Subject: [PATCH] perf: by default calling setNoDelay on the stream --- API.md | 5 +++-- lib/cluster/index.js | 1 + lib/redis.js | 7 +++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/API.md b/API.md index ca1897e6..00162fdf 100644 --- a/API.md +++ b/API.md @@ -56,6 +56,7 @@ Creates a Redis instance | [options.family] | string | 4 | Version of IP stack. Defaults to 4. | | [options.path] | string | null | Local domain socket path. If set the `port`, `host` and `family` will be ignored. | | [options.keepAlive] | number | 0 | TCP KeepAlive on the socket with a X ms delay before start. Set to a non-number value to disable keepAlive. | +| [options.noDelay] | boolean | true | Whether to disable the Nagle's Algorithm. By default we disable it to reduce the latency. | | [options.connectionName] | string | null | Connection name. | | [options.db] | number | 0 | Database index to use. | | [options.password] | string | null | If set, client will send AUTH command with the value of this option when connected. | @@ -99,7 +100,7 @@ This method will be invoked automatically when creating a new Redis instance. | Param | Type | | --- | --- | -| callback | function | +| callback | function | @@ -270,7 +271,7 @@ Quit the cluster gracefully. | Param | Type | | --- | --- | -| callback | function | +| callback | function | diff --git a/lib/cluster/index.js b/lib/cluster/index.js index 61620a91..006653b9 100644 --- a/lib/cluster/index.js +++ b/lib/cluster/index.js @@ -179,6 +179,7 @@ Cluster.prototype.connect = function () { /** * Called when closed to check whether a reconnection should be made + * @private */ Cluster.prototype._handleCloseEvent = function () { var retryDelay; diff --git a/lib/redis.js b/lib/redis.js index ca2bb88b..f24f687a 100644 --- a/lib/redis.js +++ b/lib/redis.js @@ -33,6 +33,8 @@ var commands = require('redis-commands'); * `host` and `family` will be ignored. * @param {number} [options.keepAlive=0] - TCP KeepAlive on the socket with a X ms delay before start. * Set to a non-number value to disable keepAlive. + * @param {boolean} [options.noDelay=true] - Whether to disable the Nagle's Algorithm. By default we disable + * it to reduce the latency. * @param {string} [options.connectionName=null] - Connection name. * @param {number} [options.db=0] - Database index to use. * @param {string} [options.password=null] - If set, client will send AUTH command @@ -159,6 +161,7 @@ Redis.defaultOptions = { return Math.min(times * 2, 2000); }, keepAlive: 0, + noDelay: true, connectionName: null, // Sentinel sentinels: null, @@ -295,6 +298,10 @@ Redis.prototype.connect = function (callback) { }); } + if (_this.options.noDelay) { + stream.setNoDelay(true); + } + var connectionConnectHandler = function () { _this.removeListener('close', connectionCloseHandler); resolve();