From d4b9f814fe698f60a2b08f27f45d2aab4d2523e7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 14 Aug 2021 13:07:29 +0200 Subject: net.server_epoll: Improve efficiency of opportunistic writes Should prevent further opportunistic write attempts after the kernel buffers are full and stops accepting writes. When combined with `keep_buffers = false` it should stop it from repeatedly recreating the buffer table and concatenating it back into a string when there's a lot to write. --- net/server_epoll.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/server_epoll.lua b/net/server_epoll.lua index 7b6f4680..b737ee59 100644 --- a/net/server_epoll.lua +++ b/net/server_epoll.lua @@ -484,6 +484,7 @@ function interface:onwritable() end end local ok, err, partial = self.conn:send(data); + self._writable = ok; if ok then self:set(nil, false); if cfg.keep_buffers and type(buffer) == "table" then @@ -539,7 +540,7 @@ function interface:write(data) self.writebuffer = data; end if not self._write_lock then - if cfg.opportunistic_writes and not self._opportunistic_write then + if self._writable and cfg.opportunistic_writes and not self._opportunistic_write then self._opportunistic_write = true; local ret, err = self:onwritable(); self._opportunistic_write = nil; @@ -745,6 +746,7 @@ function interface:onacceptable() local client = wrapsocket(conn, self, nil, self.listeners); client:debug("New connection %s on server %s", client, self); client:defaultoptions(); + client._writable = cfg.opportunistic_writes; if self.tls_direct then client:add(true, true); client:inittls(self.tls_ctx, true); -- cgit v1.2.3