Skip to content

Commit

Permalink
fix: disable Nagle's algorithm by default (#2242)
Browse files Browse the repository at this point in the history
By default Node.js enables Nagle's algorithm. This adds a small
delay when sending tiny buffers to batch-send them later.

Unfortunately this makes protocol negotiation slower as the
protocol strings are small enough to be batch sent.

The change here is to turn it off by default, this reduces the
perf test connection establisment from 1.2s to 0.8s.

See the latency measurements in the "Connection Establishment"
test [on this run](https://observablehq.com/@libp2p-workspace/performance-dashboard?branch=cac8364ac83a4d8856851687a605e50b1e3855fb)
for an example.
  • Loading branch information
achingbrain authored Nov 20, 2023
1 parent 2557fc2 commit 13a870c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/transport-tcp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class TCP implements Transport {

async dial (ma: Multiaddr, options: TCPDialOptions): Promise<Connection> {
options.keepAlive = options.keepAlive ?? true
options.noDelay = options.noDelay ?? true

// options.signal destroys the socket before 'connect' event
const socket = await this._connect(ma, options)
Expand Down
1 change: 1 addition & 0 deletions packages/transport-tcp/src/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export class TCPListener extends TypedEventEmitter<ListenerEvents> implements Li
super()

context.keepAlive = context.keepAlive ?? true
context.noDelay = context.noDelay ?? true

this.log = context.logger.forComponent('libp2p:tcp:listener')
this.addr = 'unknown'
Expand Down

0 comments on commit 13a870c

Please sign in to comment.