Skip to content

Commit

Permalink
Add a noDelay client option that defaults to false
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrove committed Aug 23, 2023
1 parent 0832889 commit 3a343d2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/memcache-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ const options = {
lifetime: 100, // TTL 100 seconds
cmdTimeout: 3000, // command timeout in milliseconds
connectTimeout: 8000, // connect to server timeout in ms
noDelay: true, // whether to enable TCP_NODELAY on connections
compressor: require("custom-compressor"),
logger: require("./custom-logger"),
Promise,
Expand All @@ -185,6 +186,7 @@ const client = new MemcacheClient(options);
- `ignoreNotStored` - **_optional_** If set to true, then will not treat `NOT_STORED` reply from any store commands as error. Use this for [Mcrouter AllAsyncRoute] mode.
- `lifetime` - **_optional_** Your cache TTL in **_seconds_** to use for all entries. DEFAULT: 60 seconds.
- `noDelay` - **_optional_** Whether to enable `TCP_NODELAY` on connections to decrease latency. DEFAULT: false
- `cmdTimeout` - **_optional_** Command timeout in milliseconds. DEFAULT: 5000 ms.
- If a command didn't receive response before this timeout value, then it will cause the connection to shutdown and returns Error.
- `connectTimeout` - **_optional_** Custom self connect to server timeout in milliseconds. It's disabled if set to 0. DEFAULT: 0
Expand Down
4 changes: 3 additions & 1 deletion packages/memcache-client/src/lib/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,9 @@ export class MemcacheConnection extends MemcacheParser {
}

_setupConnection(socket: Socket): void {
socket.setNoDelay(true);
if (this.client?.options?.noDelay) {
socket.setNoDelay(true);
}

socket.on("data", this.onData.bind(this));

Expand Down
1 change: 1 addition & 0 deletions packages/memcache-client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export type MemcacheClientOptions = {
server: ServerDefinition | SingleServerEntry | MultipleServerEntry | string;
ignoreNotStored?: boolean;
lifetime?: number;
noDelay?: boolean;
cmdTimeout?: number;
connectTimeout?: number;
keepDangleSocket?: boolean;
Expand Down

0 comments on commit 3a343d2

Please sign in to comment.