Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: by default calling setNoDelay on the stream #406

Merged
merged 1 commit into from
Dec 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions lib/cluster/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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 @@ -159,6 +161,7 @@ Redis.defaultOptions = {
return Math.min(times * 2, 2000);
},
keepAlive: 0,
noDelay: true,
connectionName: null,
// Sentinel
sentinels: null,
Expand Down Expand Up @@ -295,6 +298,10 @@ Redis.prototype.connect = function (callback) {
});
}

if (_this.options.noDelay) {
stream.setNoDelay(true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for TLS stream interface would look like stream.socket.setNoDelay(), I suppose we should add extra checks here

}

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