Comparison

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
comparison
equal deleted inserted replaced
12511:a24d2b3c19a3 12512:b7f07585ec4c
90 -- Reuse write buffer tables 90 -- Reuse write buffer tables
91 keep_buffers = true; 91 keep_buffers = true;
92 92
93 --- How long to wait after getting the shutdown signal before forcefully tearing down every socket 93 --- How long to wait after getting the shutdown signal before forcefully tearing down every socket
94 shutdown_deadline = 5; 94 shutdown_deadline = 5;
95
96 -- TCP Fast Open
97 tcp_fastopen = false;
95 }}; 98 }};
96 local cfg = default_config.__index; 99 local cfg = default_config.__index;
97 100
98 local fds = createtable(10, 0); -- FD -> conn 101 local fds = createtable(10, 0); -- FD -> conn
99 102
904 sockname = addr; 907 sockname = addr;
905 sockport = port; 908 sockport = port;
906 log = logger.init(("serv%s"):format(new_id())); 909 log = logger.init(("serv%s"):format(new_id()));
907 }, interface_mt); 910 }, interface_mt);
908 server:debug("Server %s created", server); 911 server:debug("Server %s created", server);
912 if cfg.tcp_fastopen then
913 server:setoption("tcp-fastopen", cfg.tcp_fastopen);
914 end
909 server:add(true, false); 915 server:add(true, false);
910 return server; 916 return server;
911 end 917 end
912 918
913 local function listen(addr, port, listeners, config) 919 local function listen(addr, port, listeners, config)
960 end 966 end
961 local conn, err = create(); 967 local conn, err = create();
962 if not conn then return conn, err; end 968 if not conn then return conn, err; end
963 local ok, err = conn:settimeout(0); 969 local ok, err = conn:settimeout(0);
964 if not ok then return ok, err; end 970 if not ok then return ok, err; end
971 if cfg.tcp_fastopen then
972 pcall(conn.setoption, conn, "tcp-fastopen-connect", 1);
973 end
965 local ok, err = conn:setpeername(addr, port); 974 local ok, err = conn:setpeername(addr, port);
966 if not ok and err ~= "timeout" then return ok, err; end 975 if not ok and err ~= "timeout" then return ok, err; end
967 local client = wrapsocket(conn, nil, read_size, listeners, tls_ctx, extra) 976 local client = wrapsocket(conn, nil, read_size, listeners, tls_ctx, extra)
968 local ok, err = client:init(); 977 local ok, err = client:init();
969 if not client.peername then 978 if not client.peername then