diff --git a/eventloop_unix.go b/eventloop_unix.go index 1377c2258..db85174d0 100644 --- a/eventloop_unix.go +++ b/eventloop_unix.go @@ -132,6 +132,12 @@ func (el *eventloop) loopOpen(c *conn) error { } func (el *eventloop) loopRead(c *conn) error { + // If there is pending data in outbound buffer, then we should omit this readable event + // and prioritize the writable events to achieve a higher performance. + if !c.outboundBuffer.IsEmpty() { + return nil + } + n, err := unix.Read(c.fd, el.packet) if n == 0 || err != nil { if err == unix.EAGAIN { diff --git a/loop_linux.go b/loop_linux.go index f794b43fb..a94bc1ceb 100644 --- a/loop_linux.go +++ b/loop_linux.go @@ -40,7 +40,7 @@ func (el *eventloop) handleEvent(fd int, ev uint32) error { return err } } - if ev&netpoll.InEvents != 0 && c.outboundBuffer.IsEmpty() { + if ev&netpoll.InEvents != 0 { return el.loopRead(c) } return nil diff --git a/reactor_linux.go b/reactor_linux.go index 78a1fc5cc..24ba2b433 100644 --- a/reactor_linux.go +++ b/reactor_linux.go @@ -74,7 +74,7 @@ func (svr *server) activateSubReactor(el *eventloop, lockOSThread bool) { return err } } - if ev&netpoll.InEvents != 0 && c.outboundBuffer.IsEmpty() { + if ev&netpoll.InEvents != 0 { return el.loopRead(c) } }