Skip to content

Commit

Permalink
perf: by default call setNoDelay on the stream (#406)
Browse files Browse the repository at this point in the history
Disables Nagle's algorithm on the underlaying socket by default. Can be controlled via `options.noDelay`
  • Loading branch information
luin committed Jan 25, 2017
1 parent 73a79ba commit f085d62
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Creates a Redis instance
| [options.family] | <code>string</code> | <code>4</code> | Version of IP stack. Defaults to 4. |
| [options.path] | <code>string</code> | <code>null</code> | Local domain socket path. If set the `port`, `host` and `family` will be ignored. |
| [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. |
| [options.noDelay] | <code>boolean</code> | <code>true</code> | Whether to disable the Nagle's Algorithm. By default we disable it to reduce the latency. |
| [options.connectionName] | <code>string</code> | <code>null</code> | Connection name. |
| [options.db] | <code>number</code> | <code>0</code> | Database index to use. |
| [options.password] | <code>string</code> | <code>null</code> | If set, client will send AUTH command with the value of this option when connected. |
Expand Down Expand Up @@ -99,7 +100,7 @@ This method will be invoked automatically when creating a new Redis instance.

| Param | Type |
| --- | --- |
| callback | <code>function</code> |
| callback | <code>function</code> |

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

Expand Down Expand Up @@ -270,7 +271,7 @@ Quit the cluster gracefully.

| Param | Type |
| --- | --- |
| callback | <code>function</code> |
| callback | <code>function</code> |

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

Expand Down
7 changes: 7 additions & 0 deletions lib/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -153,6 +155,7 @@ Redis.defaultOptions = {
return Math.min(times * 2, 2000);
},
keepAlive: 0,
noDelay: true,
connectionName: null,
// Sentinel
sentinels: null,
Expand Down Expand Up @@ -288,6 +291,10 @@ Redis.prototype.connect = function (callback) {
});
}

if (_this.options.noDelay) {
stream.setNoDelay(true);
}

var connectionConnectHandler = function () {
_this.removeListener('close', connectionCloseHandler);
resolve();
Expand Down

0 comments on commit f085d62

Please sign in to comment.