Changeset

10228:e77bf4222fae

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.
author Kim Alvefur <zash@zash.se>
date Wed, 28 Aug 2019 01:41:00 +0200
parents 10227:eeb711b92da5
children 10229:3b769e53b33f
files net/server_epoll.lua
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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