diff options
author | Kim Alvefur <zash@zash.se> | 2021-07-16 02:28:32 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2021-07-16 02:28:32 +0200 |
commit | 07afd46b58ce91ac96a64140c3a1b7479a6e01fc (patch) | |
tree | 330d0d071802a1acb5aad8241189a3bd4b1e1382 /net/server_epoll.lua | |
parent | 8318977ef41196def77aa3d662578e2fb18580b8 (diff) | |
download | prosody-07afd46b58ce91ac96a64140c3a1b7479a6e01fc.tar.gz prosody-07afd46b58ce91ac96a64140c3a1b7479a6e01fc.zip |
net.server_epoll: Optionally let go of buffers
Reusing an already existing buffer table would reduce garbage, but
keeping it while idle is a waste.
Diffstat (limited to 'net/server_epoll.lua')
-rw-r--r-- | net/server_epoll.lua | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/net/server_epoll.lua b/net/server_epoll.lua index 504dc8d5..6ab07996 100644 --- a/net/server_epoll.lua +++ b/net/server_epoll.lua @@ -86,6 +86,9 @@ local default_config = { __index = { -- Whether to let the Nagle algorithm stay enabled nagle = true; + + -- Reuse write buffer tables + keep_buffers = true; }}; local cfg = default_config.__index; @@ -472,17 +475,25 @@ function interface:onwritable() local ok, err, partial = self.conn:send(data); if ok then self:set(nil, false); - for i = #buffer, 1, -1 do - buffer[i] = nil; + if cfg.keep_buffers then + for i = #buffer, 1, -1 do + buffer[i] = nil; + end + else + self.writebuffer = nil; end self:setwritetimeout(false); self:ondrain(); -- Be aware of writes in ondrain return ok; elseif partial then self:debug("Sent %d out of %d buffered bytes", partial, #data); - buffer[1] = data:sub(partial+1); - for i = #buffer, 2, -1 do - buffer[i] = nil; + if cfg.keep_buffers then + buffer[1] = data:sub(partial+1); + for i = #buffer, 2, -1 do + buffer[i] = nil; + end + else + data.writebuffer = { data:sub(partial+1) }; end self:set(nil, true); self:setwritetimeout(); @@ -509,6 +520,7 @@ function interface:write(data) if buffer then t_insert(buffer, data); else + self:noise("Allocating buffer!") self.writebuffer = { data }; end if not self._write_lock then |