Changeset

5531:483f795f6f99

net.server*: Allow the TCP backlog parameter to be set in the config
author Kim Alvefur <zash@zash.se>
date Sat, 27 Apr 2013 22:46:01 +0200
parents 5530:d83482fc4a81
children 5532:d5cbcdcdb2f7 5537:15464633d8fb
files net/server.lua net/server_event.lua net/server_select.lua
diffstat 3 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/net/server.lua	Sat Apr 27 19:44:37 2013 +0200
+++ b/net/server.lua	Sat Apr 27 22:46:01 2013 +0200
@@ -51,6 +51,7 @@
 		if use_luaevent then
 			local event_settings = {
 				ACCEPT_DELAY = settings.event_accept_retry_interval;
+				ACCEPT_QUEUE = settings.tcp_backlog;
 				CLEAR_DELAY = settings.event_clear_interval;
 				CONNECT_TIMEOUT = settings.connect_timeout;
 				DEBUG = settings.debug;
--- a/net/server_event.lua	Sat Apr 27 19:44:37 2013 +0200
+++ b/net/server_event.lua	Sat Apr 27 22:46:01 2013 +0200
@@ -23,6 +23,7 @@
 	HANDSHAKE_TIMEOUT     = 60,  -- timeout in seconds per handshake attempt
 	MAX_READ_LENGTH       = 1024 * 1024 * 1024 * 1024,  -- max bytes allowed to read from sockets
 	MAX_SEND_LENGTH       = 1024 * 1024 * 1024 * 1024,  -- max bytes size of write buffer (for writing on sockets)
+	ACCEPT_QUEUE          = 128,  -- might influence the length of the pending sockets queue
 	ACCEPT_DELAY          = 10,  -- seconds to wait until the next attempt of a full server to accept
 	READ_TIMEOUT          = 60 * 60 * 6,  -- timeout in seconds for read data from socket
 	WRITE_TIMEOUT         = 180,  -- timeout in seconds for write data on socket
--- a/net/server_select.lua	Sat Apr 27 19:44:37 2013 +0200
+++ b/net/server_select.lua	Sat Apr 27 22:46:01 2013 +0200
@@ -101,6 +101,7 @@
 
 local _selecttimeout
 local _sleeptime
+local _tcpbacklog
 
 local _starttime
 local _currenttime
@@ -139,6 +140,7 @@
 
 _selecttimeout = 1 -- timeout of socket.select
 _sleeptime = 0 -- time to wait at the end of every loop
+_tcpbacklog = 128 -- some kind of hint to the OS
 
 _maxsendlen = 51000 * 1024 -- max len of send buffer
 _maxreadlen = 25000 * 1024 -- max len of read buffer
@@ -211,7 +213,7 @@
 	handler.resume = function( )
 		if handler.paused then
 			if not socket then
-				socket = socket_bind( ip, serverport );
+				socket = socket_bind( ip, serverport, _tcpbacklog );
 				socket:settimeout( 0 )
 			end
 			_readlistlen = addsocket(_readlist, socket, _readlistlen)
@@ -720,7 +722,7 @@
 		return nil, err
 	end
 	addr = addr or "*"
-	local server, err = socket_bind( addr, port )
+	local server, err = socket_bind( addr, port, _tcpbacklog )
 	if err then
 		out_error( "server.lua, [", addr, "]:", port, ": ", err )
 		return nil, err
@@ -772,6 +774,7 @@
 	return {
 		select_timeout = _selecttimeout;
 		select_sleep_time = _sleeptime;
+		tcp_backlog = _tcpbacklog;
 		max_send_buffer_size = _maxsendlen;
 		max_receive_buffer_size = _maxreadlen;
 		select_idle_check_interval = _checkinterval;
@@ -792,6 +795,7 @@
 	_maxsendlen = tonumber( new.max_send_buffer_size ) or _maxsendlen
 	_maxreadlen = tonumber( new.max_receive_buffer_size ) or _maxreadlen
 	_checkinterval = tonumber( new.select_idle_check_interval ) or _checkinterval
+	_tcpbacklog = tonumber( new.tcp_backlog ) or _tcpbacklog
 	_sendtimeout = tonumber( new.send_timeout ) or _sendtimeout
 	_readtimeout = tonumber( new.read_timeout ) or _readtimeout
 	_maxselectlen = new.max_connections or _maxselectlen