net.server_epoll: Add support for opportunistic writes
This tries to flush data to the underlying sockets when receiving
writes. This should lead to fewer timer objects being around. On the
other hand, this leads to more and smaller writes which may translate to
more TCP/IP packets being sent, depending on how the kernel handles
this. This trades throughput for lower latency.
--- a/net/server_epoll.lua Sun Aug 25 23:25:42 2019 +0200
+++ b/net/server_epoll.lua Wed Aug 28 01:41:00 2019 +0200
@@ -66,6 +66,9 @@
-- EXPERIMENTAL
-- Whether to kill connections in case of callback errors.
fatal_errors = false;
+
+ -- Attempt writes instantly
+ opportunistic_writes = false;
}};
local cfg = default_config.__index;
@@ -413,6 +416,7 @@
for i = #buffer, 2, -1 do
buffer[i] = nil;
end
+ self:set(nil, true);
self:setwritetimeout();
end
if err == "wantwrite" or err == "timeout" then
@@ -439,6 +443,10 @@
self.writebuffer = { data };
end
if not self._write_lock then
+ if cfg.opportunistic_writes then
+ self:onwritable();
+ return #data;
+ end
self:setwritetimeout();
self:set(nil, true);
end