Changeset

11738:3f1450ec37f4

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.
author Kim Alvefur <zash@zash.se>
date Sat, 14 Aug 2021 13:07:29 +0200
parents 11737:59cf555b4698
children 11739:e0d0680e04cc
files net/server_epoll.lua
diffstat 1 files changed, 3 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/net/server_epoll.lua	Thu Aug 12 19:34:17 2021 +0200
+++ b/net/server_epoll.lua	Sat Aug 14 13:07:29 2021 +0200
@@ -484,6 +484,7 @@
 		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 @@
 		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 @@
 	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);