Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Test: recycle server reader buffers #253

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 10 additions & 1 deletion go/mysql/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ func newConn(conn net.Conn) *Conn {
}
}

var readersPool = sync.Pool{New: func() interface{} { return bufio.NewReaderSize(nil, 16*1024) }}

// newServerConn should be used to create server connections.
//
// It stashes a reference to the listener to be able to determine if
Expand All @@ -241,11 +243,18 @@ func newServerConn(conn net.Conn, listener *Listener) *Conn {
PrepareData: make(map[uint32]*PrepareData),
}
if listener.connReadBufferSize > 0 {
c.bufferedReader = bufio.NewReaderSize(conn, listener.connReadBufferSize)
buf := readersPool.Get().(*bufio.Reader)
buf.Reset(conn)
c.bufferedReader = buf
}
return c
}

func (c *Conn) returnReader() {
c.bufferedReader.Reset(nil)
readersPool.Put(c.bufferedReader)
}

// startWriterBuffering starts using buffered writes. This should
// be terminated by a call to endWriteBuffering.
func (c *Conn) startWriterBuffering() {
Expand Down
2 changes: 2 additions & 0 deletions go/mysql/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ func (l *Listener) handle(conn net.Conn, connectionID uint32, acceptTime time.Ti
// startWriterBuffering is called
c.endWriterBuffering()

c.returnReader()

conn.Close()
}()

Expand Down