Comparison

net/server_select.lua @ 7095:3e1dac35af87

server_select: Retry accepting clients from full servers after 10s (matches libevent behaviour)
author Kim Alvefur <zash@zash.se>
date Fri, 22 Jan 2016 01:59:25 +0100
parent 7094:e8f202856fc0
child 7096:95e4c81291cc
comparison
equal deleted inserted replaced
7094:e8f202856fc0 7095:3e1dac35af87
101 local _readtraffic 101 local _readtraffic
102 102
103 local _selecttimeout 103 local _selecttimeout
104 local _sleeptime 104 local _sleeptime
105 local _tcpbacklog 105 local _tcpbacklog
106 local _accepretry
106 107
107 local _starttime 108 local _starttime
108 local _currenttime 109 local _currenttime
109 110
110 local _maxsendlen 111 local _maxsendlen
141 _readtraffic = 0 142 _readtraffic = 0
142 143
143 _selecttimeout = 1 -- timeout of socket.select 144 _selecttimeout = 1 -- timeout of socket.select
144 _sleeptime = 0 -- time to wait at the end of every loop 145 _sleeptime = 0 -- time to wait at the end of every loop
145 _tcpbacklog = 128 -- some kind of hint to the OS 146 _tcpbacklog = 128 -- some kind of hint to the OS
147 _accepretry = 10 -- seconds to wait until the next attempt of a full server to accept
146 148
147 _maxsendlen = 51000 * 1024 -- max len of send buffer 149 _maxsendlen = 51000 * 1024 -- max len of send buffer
148 _maxreadlen = 25000 * 1024 -- max len of read buffer 150 _maxreadlen = 25000 * 1024 -- max len of read buffer
149 151
150 _checkinterval = 1200000 -- interval in secs to check idle clients 152 _checkinterval = 1200000 -- interval in secs to check idle clients
796 send_timeout = _sendtimeout; 798 send_timeout = _sendtimeout;
797 read_timeout = _readtimeout; 799 read_timeout = _readtimeout;
798 max_connections = _maxselectlen; 800 max_connections = _maxselectlen;
799 max_ssl_handshake_roundtrips = _maxsslhandshake; 801 max_ssl_handshake_roundtrips = _maxsslhandshake;
800 highest_allowed_fd = _maxfd; 802 highest_allowed_fd = _maxfd;
803 accept_retry_interval = _accepretry;
801 } 804 }
802 end 805 end
803 806
804 changesettings = function( new ) 807 changesettings = function( new )
805 if type( new ) ~= "table" then 808 if type( new ) ~= "table" then
811 _maxreadlen = tonumber( new.max_receive_buffer_size ) or _maxreadlen 814 _maxreadlen = tonumber( new.max_receive_buffer_size ) or _maxreadlen
812 _checkinterval = tonumber( new.select_idle_check_interval ) or _checkinterval 815 _checkinterval = tonumber( new.select_idle_check_interval ) or _checkinterval
813 _tcpbacklog = tonumber( new.tcp_backlog ) or _tcpbacklog 816 _tcpbacklog = tonumber( new.tcp_backlog ) or _tcpbacklog
814 _sendtimeout = tonumber( new.send_timeout ) or _sendtimeout 817 _sendtimeout = tonumber( new.send_timeout ) or _sendtimeout
815 _readtimeout = tonumber( new.read_timeout ) or _readtimeout 818 _readtimeout = tonumber( new.read_timeout ) or _readtimeout
819 _accepretry = tonumber( new.accept_retry_interval ) or _accepretry
816 _maxselectlen = new.max_connections or _maxselectlen 820 _maxselectlen = new.max_connections or _maxselectlen
817 _maxsslhandshake = new.max_ssl_handshake_roundtrips or _maxsslhandshake 821 _maxsslhandshake = new.max_ssl_handshake_roundtrips or _maxsslhandshake
818 _maxfd = new.highest_allowed_fd or _maxfd 822 _maxfd = new.highest_allowed_fd or _maxfd
819 return true 823 return true
820 end 824 end
897 if t then next_timer_time = math_min(next_timer_time, t); end 901 if t then next_timer_time = math_min(next_timer_time, t); end
898 end 902 end
899 _timer = _currenttime 903 _timer = _currenttime
900 else 904 else
901 next_timer_time = next_timer_time - (_currenttime - _timer); 905 next_timer_time = next_timer_time - (_currenttime - _timer);
906 end
907
908 for server, paused_time in pairs( _fullservers ) do
909 if _currenttime - paused_time > _accepretry then
910 _fullservers[ server ] = nil;
911 server.resume();
912 end
902 end 913 end
903 914
904 -- wait some time (0 by default) 915 -- wait some time (0 by default)
905 socket_sleep( _sleeptime ) 916 socket_sleep( _sleeptime )
906 until quitting; 917 until quitting;