Skip to content

Commit

Permalink
Use a bufio.Reader in proxycore.Conn (#80)
Browse files Browse the repository at this point in the history
After profiling I noticed that significant time is spent in the read system
call reading a single byte for the CQL native protocol header. It's
possible that we can eliminate some system calls by using a buffered
reader.
  • Loading branch information
mpenick committed Feb 15, 2022
1 parent 7a02afd commit ea8421b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion proxycore/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Conn struct {
err error
recv Receiver
writer *bufio.Writer
reader *bufio.Reader
mu *sync.Mutex
}

Expand Down Expand Up @@ -95,6 +96,7 @@ func NewConn(conn net.Conn, recv Receiver) *Conn {
conn: conn,
recv: recv,
writer: bufio.NewWriterSize(conn, MaxCoalesceSize),
reader: bufio.NewReader(conn),
closed: make(chan struct{}),
messages: make(chan Sender, MaxMessages),
mu: &sync.Mutex{},
Expand All @@ -109,7 +111,7 @@ func (c *Conn) Start() {
func (c *Conn) read() {
done := false
for !done {
done = c.checkErr(c.recv.Receive(c.conn))
done = c.checkErr(c.recv.Receive(c.reader))
}
c.recv.Closing(c.Err())
}
Expand Down

0 comments on commit ea8421b

Please sign in to comment.