Skip to content

Commit 990a221

Browse files
luinAVVS
authored andcommitted
perf: by default call setNoDelay on the stream (#406)
Disables Nagle's algorithm on the underlaying socket by default. Can be controlled via `options.noDelay`
1 parent ea6fbf2 commit 990a221

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

API.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Creates a Redis instance
5656
| [options.family] | <code>string</code> | <code>4</code> | Version of IP stack. Defaults to 4. |
5757
| [options.path] | <code>string</code> | <code>null</code> | Local domain socket path. If set the `port`, `host` and `family` will be ignored. |
5858
| [options.keepAlive] | <code>number</code> | <code>0</code> | TCP KeepAlive on the socket with a X ms delay before start. Set to a non-number value to disable keepAlive. |
59+
| [options.noDelay] | <code>boolean</code> | <code>true</code> | Whether to disable the Nagle's Algorithm. By default we disable it to reduce the latency. |
5960
| [options.connectionName] | <code>string</code> | <code>null</code> | Connection name. |
6061
| [options.db] | <code>number</code> | <code>0</code> | Database index to use. |
6162
| [options.password] | <code>string</code> | <code>null</code> | 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.
99100

100101
| Param | Type |
101102
| --- | --- |
102-
| callback | <code>function</code> |
103+
| callback | <code>function</code> |
103104

104105
<a name="Redis+disconnect"></a>
105106

@@ -270,7 +271,7 @@ Quit the cluster gracefully.
270271

271272
| Param | Type |
272273
| --- | --- |
273-
| callback | <code>function</code> |
274+
| callback | <code>function</code> |
274275

275276
<a name="Cluster+nodes"></a>
276277

lib/cluster/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ Cluster.prototype.connect = function () {
179179

180180
/**
181181
* Called when closed to check whether a reconnection should be made
182+
* @private
182183
*/
183184
Cluster.prototype._handleCloseEvent = function () {
184185
var retryDelay;

lib/redis.js

+7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ var commands = require('redis-commands');
3333
* `host` and `family` will be ignored.
3434
* @param {number} [options.keepAlive=0] - TCP KeepAlive on the socket with a X ms delay before start.
3535
* Set to a non-number value to disable keepAlive.
36+
* @param {boolean} [options.noDelay=true] - Whether to disable the Nagle's Algorithm. By default we disable
37+
* it to reduce the latency.
3638
* @param {string} [options.connectionName=null] - Connection name.
3739
* @param {number} [options.db=0] - Database index to use.
3840
* @param {string} [options.password=null] - If set, client will send AUTH command
@@ -159,6 +161,7 @@ Redis.defaultOptions = {
159161
return Math.min(times * 2, 2000);
160162
},
161163
keepAlive: 0,
164+
noDelay: true,
162165
connectionName: null,
163166
// Sentinel
164167
sentinels: null,
@@ -295,6 +298,10 @@ Redis.prototype.connect = function (callback) {
295298
});
296299
}
297300

301+
if (_this.options.noDelay) {
302+
stream.setNoDelay(true);
303+
}
304+
298305
var connectionConnectHandler = function () {
299306
_this.removeListener('close', connectionCloseHandler);
300307
resolve();

0 commit comments

Comments
 (0)