Skip to content

Commit

Permalink
Optimized pipelining
Browse files Browse the repository at this point in the history
Performance gains for pipelining commands over the network.
Using tile38-benchmark and the -P flag it's possible to see 2x-10x boost
in requests per second.
  • Loading branch information
tidwall committed Oct 1, 2017
1 parent 033f782 commit d817814
Show file tree
Hide file tree
Showing 15 changed files with 2,621 additions and 411 deletions.
18 changes: 10 additions & 8 deletions controller/aof.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func (c *Controller) cmdAOF(msg *server.Message) (res string, err error) {
return "", s
}

func (c *Controller) liveAOF(pos int64, conn net.Conn, rd *server.AnyReaderWriter, msg *server.Message) error {
func (c *Controller) liveAOF(pos int64, conn net.Conn, rd *server.PipelineReader, msg *server.Message) error {
c.mu.Lock()
c.aofconnM[conn] = true
c.mu.Unlock()
Expand Down Expand Up @@ -394,19 +394,21 @@ func (c *Controller) liveAOF(pos int64, conn net.Conn, rd *server.AnyReaderWrite
cond.L.Unlock()
}()
for {
v, err := rd.ReadMessage()
vs, err := rd.ReadMessages()
if err != nil {
if err != io.EOF {
log.Error(err)
}
return
}
switch v.Command {
default:
log.Error("received a live command that was not QUIT")
return
case "quit", "":
return
for _, v := range vs {
switch v.Command {
default:
log.Error("received a live command that was not QUIT")
return
case "quit", "":
return
}
}
}
}()
Expand Down
2 changes: 1 addition & 1 deletion controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func ListenAndServeEx(host string, port int, dir string, ln *net.Listener, http
c.stopWatchingMemory.set(true)
c.stopWatchingAutoGC.set(true)
}()
handler := func(conn *server.Conn, msg *server.Message, rd *server.AnyReaderWriter, w io.Writer, websocket bool) error {
handler := func(conn *server.Conn, msg *server.Message, rd *server.PipelineReader, w io.Writer, websocket bool) error {
c.connsmu.RLock()
if cc, ok := c.conns[conn]; ok {
cc.last.set(time.Now())
Expand Down
24 changes: 13 additions & 11 deletions controller/live.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func writeMessage(conn net.Conn, message []byte, wrapRESP bool, connType server.
return err
}

func (c *Controller) goLive(inerr error, conn net.Conn, rd *server.AnyReaderWriter, msg *server.Message, websocket bool) error {
func (c *Controller) goLive(inerr error, conn net.Conn, rd *server.PipelineReader, msg *server.Message, websocket bool) error {
addr := conn.RemoteAddr().String()
log.Info("live " + addr)
defer func() {
Expand Down Expand Up @@ -114,22 +114,24 @@ func (c *Controller) goLive(inerr error, conn net.Conn, rd *server.AnyReaderWrit
conn.Close()
}()
for {
v, err := rd.ReadMessage()
vs, err := rd.ReadMessages()
if err != nil {
if err != io.EOF && !(websocket && err == io.ErrUnexpectedEOF) {
log.Error(err)
}
return
}
if v == nil {
continue
}
switch v.Command {
default:
log.Error("received a live command that was not QUIT")
return
case "quit", "":
return
for _, v := range vs {
if v == nil {
continue
}
switch v.Command {
default:
log.Error("received a live command that was not QUIT")
return
case "quit", "":
return
}
}
}
}()
Expand Down
Loading

0 comments on commit d817814

Please sign in to comment.