# HG changeset patch # User Kim Alvefur # Date 1566949260 -7200 # Node ID e77bf4222fae7c94ab41e51fffc0021d8c01f998 # Parent eeb711b92da5dc6067bd1a29a22bf2b7319b0c62 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. diff -r eeb711b92da5 -r e77bf4222fae net/server_epoll.lua --- 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