Skip to content

Commit 48e12b1

Browse files
committed
proxy: optimize FlushEncoder for better performance
1 parent 9f29de4 commit 48e12b1

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

config/proxy.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ backend_send_bufsize = "128kb"
6060
backend_send_timeout = "30s"
6161

6262
# Set backend pipeline buffer size.
63-
backend_max_pipeline = 1024
63+
backend_max_pipeline = 20480
6464

6565
# Set backend never read replica groups, default is false
6666
backend_primary_only = false

pkg/proxy/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ func (bc *BackendConn) loopWriter(round int) (err error) {
337337

338338
p := c.FlushEncoder()
339339
p.MaxInterval = time.Millisecond
340-
p.MaxBuffered = math2.MinInt(256, cap(tasks))
340+
p.MaxBuffered = cap(tasks) / 2
341341

342342
for r := range bc.input {
343343
if r.IsReadOnly() && r.IsBroken() {

pkg/proxy/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ backend_send_bufsize = "128kb"
7676
backend_send_timeout = "30s"
7777
7878
# Set backend pipeline buffer size.
79-
backend_max_pipeline = 1024
79+
backend_max_pipeline = 20480
8080
8181
# Set backend never read replica groups, default is false
8282
backend_primary_only = false

pkg/proxy/session.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,14 @@ func (s *Session) loopWriter(tasks *RequestChan) (err error) {
197197
s.flushOpStats(true)
198198
}()
199199

200-
var breakOnFailure = s.config.SessionBreakOnFailure
200+
var (
201+
breakOnFailure = s.config.SessionBreakOnFailure
202+
maxPipelineLen = s.config.SessionMaxPipeline
203+
)
201204

202205
p := s.Conn.FlushEncoder()
203206
p.MaxInterval = time.Millisecond
204-
p.MaxBuffered = 256
207+
p.MaxBuffered = maxPipelineLen / 2
205208

206209
return tasks.PopFrontAll(func(r *Request) error {
207210
resp, err := s.handleResponse(r)

0 commit comments

Comments
 (0)