Diff

net/server_epoll.lua @ 12512:b7f07585ec4c

net.server_epoll: Add support for TCP Fast Open Requires a patch to LuaSocket adding this socket option, https://github.com/lunarmodules/luasocket/pull/378 sysctl tweaks net.ipv4.tcp_fastopen=3 net.ipv4.tcp_fastopen_blackhole_timeout_sec = 0 net.ipv4.tcp_fastopen_key=$(</proc/sys/kernel/random/uuid) Disabled by default since it an advanced performance tweak unlikely to be needed by most servers.
author Kim Alvefur <zash@zash.se>
date Thu, 08 Jul 2021 12:29:50 +0200
parent 12481:2ee27587fec7
child 12513:6efbcd52db21
line wrap: on
line diff
--- a/net/server_epoll.lua	Mon May 16 14:51:58 2022 +0200
+++ b/net/server_epoll.lua	Thu Jul 08 12:29:50 2021 +0200
@@ -92,6 +92,9 @@
 
 	--- How long to wait after getting the shutdown signal before forcefully tearing down every socket
 	shutdown_deadline = 5;
+
+	-- TCP Fast Open
+	tcp_fastopen = false;
 }};
 local cfg = default_config.__index;
 
@@ -906,6 +909,9 @@
 		log = logger.init(("serv%s"):format(new_id()));
 	}, interface_mt);
 	server:debug("Server %s created", server);
+	if cfg.tcp_fastopen then
+		server:setoption("tcp-fastopen", cfg.tcp_fastopen);
+	end
 	server:add(true, false);
 	return server;
 end
@@ -962,6 +968,9 @@
 	if not conn then return conn, err; end
 	local ok, err = conn:settimeout(0);
 	if not ok then return ok, err; end
+	if cfg.tcp_fastopen then
+		pcall(conn.setoption, conn, "tcp-fastopen-connect", 1);
+	end
 	local ok, err = conn:setpeername(addr, port);
 	if not ok and err ~= "timeout" then return ok, err; end
 	local client = wrapsocket(conn, nil, read_size, listeners, tls_ctx, extra)