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

feat: add DisableTCPNoDelay #650

Merged
merged 2 commits into from
Oct 20, 2024
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: 5 additions & 0 deletions pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type pipe struct {
waits int32
recvs int32
r2ps bool // identify this pipe is used for resp2 pubsub or not
noNoDelay bool
}

type pipeFn func(connFn func() (net.Conn, error), option *ClientOption) (p *pipe, err error)
Expand All @@ -98,6 +99,7 @@ func _newPipe(connFn func() (net.Conn, error), option *ClientOption, r2ps, nobg
timeout: option.ConnWriteTimeout,
pinggap: option.Dialer.KeepAlive,
maxFlushDelay: option.MaxFlushDelay,
noNoDelay: option.DisableTCPNoDelay,

r2ps: r2ps,
}
Expand Down Expand Up @@ -321,6 +323,9 @@ func (p *pipe) _exit(err error) {

func (p *pipe) _background() {
p.conn.SetDeadline(time.Time{})
if conn, ok := p.conn.(*net.TCPConn); ok && p.noNoDelay {
conn.SetNoDelay(false)
}
go func() {
p._exit(p._backgroundWrite())
close(p.close)
Expand Down
5 changes: 5 additions & 0 deletions rueidis.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ type ClientOption struct {
// produce notable CPU usage reduction under load. Ref: https://github.com/redis/rueidis/issues/156
MaxFlushDelay time.Duration

// DisableTCPNoDelay turns on Nagle's algorithm in pipelining mode by using conn.SetNoDelay(false).
// Turning this on can result in lower p99 latencies and lower CPU usages if all your requests are small.
// But if you have large requests or fast network, this might degrade the performance. Ref: https://github.com/redis/rueidis/pull/650
DisableTCPNoDelay bool

// ShuffleInit is a handy flag that shuffles the InitAddress after passing to the NewClient() if it is true
ShuffleInit bool
// ClientNoTouch controls whether commands alter LRU/LFU stats
Expand Down