From d065b979dae3b2474f413eecff551313c37c5a7d Mon Sep 17 00:00:00 2001 From: tidwall Date: Sat, 10 Nov 2018 16:21:07 -0700 Subject: [PATCH] net prewrite optimization --- internal/server/server.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/internal/server/server.go b/internal/server/server.go index 9a21b438..3ed61699 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -653,14 +653,18 @@ func (server *Server) netServe() error { // write to client if len(client.out) > 0 { - func() { - // prewrite - server.mu.Lock() - defer server.mu.Unlock() - server.flushAOF() - }() + if atomic.LoadInt32(&server.aofdirty) != 0 { + func() { + // prewrite + server.mu.Lock() + defer server.mu.Unlock() + server.flushAOF() + }() + atomic.StoreInt32(&server.aofdirty, 0) + } conn.Write(client.out) client.out = nil + } if close { break