Rework and improve the scheduling of the server lag check

Previously the server lag check was run by update_clock() if the number of
seconds since client startup was a multiple of 20 (unless it had already been
done this second).  This meant that if update_clock() was not being called
frequently (eg. if your IRC connection was very quiet), it might go a long
time between lag checks.

This commit adds a /set LAG_CHECK_INTERVAL (defaulting to 30).  For each
server, a lag check ping is scheduled for every LAG_CHECK_INTERVAL seconds
after the connection is finalised/registered.  Setting this value to 0
disables the lag check pings entirely.

The old code set the lag to 'unknown' immediately after sending out a ping,
which meant that it was quite unpredictable how long the lag value would
stay around for.  The new code only sets this once the current lag value
has become stale (ie. a ping reply is overdue based on the current lag
value).  If your lag is staying the same or reducing, you shouldn't see
the [Lag ??] at all.
This commit is contained in:
Kevin Easton
2015-06-12 15:54:43 +10:00
parent 7eae2aba86
commit 6dbc712046
8 changed files with 87 additions and 88 deletions

View File

@@ -129,6 +129,7 @@ void BX_close_server (int cs_index, char *message)
server_list[cs_index].server_change_pending = 0;
server_list[cs_index].operator = 0;
server_list[cs_index].connected = 0;
server_list[cs_index].lag = -1;
server_list[cs_index].buffer = NULL;
server_list[cs_index].link_look = 0;
server_list[cs_index].login_flags = 0;
@@ -241,6 +242,26 @@ void set_server_bits (fd_set *rd, fd_set *wr, struct timeval *wake_time)
if (time_cmp(wake_time, &connect_wake_time) > 0)
*wake_time = connect_wake_time;
}
if (is_server_connected(i))
{
/* Time to send another ping */
int lag_check_interval = get_int_var(LAG_CHECK_INTERVAL_VAR);
struct timeval lag_wake_time = server_list[i].lag_sent;
lag_wake_time.tv_sec += lag_check_interval;
if (lag_check_interval > 0 && time_cmp(wake_time, &lag_wake_time) > 0)
*wake_time = lag_wake_time;
if (server_list[i].lag != -1)
{
/* Time that previous lag value becomes stale */
lag_wake_time = server_list[i].lag_recv;
lag_wake_time.tv_sec += lag_check_interval + 1;
if (time_cmp(wake_time, &lag_wake_time) > 0)
*wake_time = lag_wake_time;
}
}
if (server_list[i].read > -1)
FD_SET(server_list[i].read, rd);
@@ -410,28 +431,6 @@ static void scan_nonblocking(void)
}
#endif
int check_serverlag(void)
{
int i;
struct timeval tv;
get_time(&tv);
for (i = 0; i < server_list_size(); i++)
{
if (is_server_connected(i) && now != get_server_lagtime(i))
{
set_server_lagtime(i, now);
my_send_to_server(i, "PING LAG!%lu.%ld.%ld :%s",
get_server_lag_cookie(i),
(long)tv.tv_sec, (long)tv.tv_usec, get_server_itsname(i));
set_server_lag(i, -1);
}
}
return 0;
}
void do_idle_server (void)
{
int i;
@@ -445,7 +444,7 @@ void do_idle_server (void)
for (i = 0; i < number_of_servers && i > -1; i++)
{
/* We were told to reconnect, to avoid recursion. */
if(get_server_reconnect(i) > 0)
if (get_server_reconnect(i) > 0)
{
int connect_delay = get_int_var(CONNECT_DELAY_VAR);
@@ -457,6 +456,29 @@ void do_idle_server (void)
reconnect_server(&servernum, &times, &last_timeout);
}
}
if (is_server_connected(i))
{
int lag_check_interval = get_int_var(LAG_CHECK_INTERVAL_VAR);
if (lag_check_interval > 0 &&
time_since(&server_list[i].lag_sent) > lag_check_interval)
{
get_time(&server_list[i].lag_sent);
my_send_to_server(i, "PING LAG!%lu.%ld.%ld :%s",
server_list[i].lag_cookie,
(long)server_list[i].lag_sent.tv_sec,
(long)server_list[i].lag_sent.tv_usec,
get_server_itsname(i));
}
if (server_list[i].lag != -1 &&
time_since(&server_list[i].lag_recv) > lag_check_interval + 1)
{
/* Lag reply overdue */
set_server_lag(i, -1);
update_all_status(current_window, NULL, 0);
}
}
}
}
@@ -475,29 +497,13 @@ void do_server (fd_set *rd, fd_set *wr)
char buffer[BIG_BUFFER_SIZE + 1];
int des,
i;
static int times = 1;
static time_t last_timeout = 0;
#ifdef NON_BLOCKING_CONNECTS
scan_nonblocking();
#endif
/* Process server timeouts */
do_idle_server();
for (i = 0; i < number_of_servers; i++)
{
/* We were told to reconnect, to avoid recursion. */
if(get_server_reconnect(i) > 0)
{
int connect_delay = get_int_var(CONNECT_DELAY_VAR);
if (time_since(&server_list[i].connect_time) > connect_delay)
{
int servernum = i;
set_server_reconnect(i, 0);
reconnect_server(&servernum, &times, &last_timeout);
}
}
#ifdef NON_BLOCKING_CONNECTS
if (((des = server_list[i].write) > -1) && FD_ISSET(des, wr) && !(server_list[i].login_flags & LOGGED_IN))
{
@@ -638,6 +644,25 @@ static time_t last_timeout = 0;
window_check_servers(-1);
}
/* server_lag_reply()
*
* Called when a reply to a lag check ping has been recieved.
*/
void server_lag_reply(int s, unsigned long cookie, struct timeval lag_recv, struct timeval lag_sent)
{
if (cookie == server_list[s].lag_cookie)
{
int new_lag = (int)(BX_time_diff(lag_sent, lag_recv) + 0.5);
server_list[s].lag_recv = lag_recv;
if (server_list[s].lag != new_lag)
{
server_list[s].lag = new_lag;
update_all_status(current_window, NULL, 0);
}
}
}
/*
* find_in_server_list: given a server name, this tries to match it against
* names in the server list, returning the index into the list if found, or
@@ -2367,26 +2392,6 @@ void BX_set_server_lag (int gso_index, int secs)
server_list[gso_index].lag = secs;
}
time_t get_server_lagtime (int gso_index)
{
if ((gso_index < 0 || gso_index >= number_of_servers))
return 0;
return(server_list[gso_index].lag_time);
}
void set_server_lagtime (int gso_index, time_t secs)
{
if ((gso_index != -1 && gso_index < number_of_servers))
server_list[gso_index].lag_time = secs;
}
unsigned long get_server_lag_cookie(int gso_index)
{
if ((gso_index < 0 || gso_index >= number_of_servers))
return 0;
return server_list[gso_index].lag_cookie;
}
int BX_get_server_motd (int gsm_index)
{
if (gsm_index != -1 && gsm_index < number_of_servers)
@@ -2401,7 +2406,10 @@ void BX_server_is_connected (int sic_index, int value)
server_list[sic_index].connected = value;
if (value)
{
server_list[sic_index].eof = 0;
get_time(&server_list[sic_index].lag_sent);
}
}
void set_server_version_string (int servnum, const char *ver)