manager: be more aggressive about purging http sessions.

If we find that n_max (currently hard wired to 1) sessions were purged,
schedule the next purge for 1ms into the future rather than 5000ms (as
per current).  This way we will purge up to 1000 sessions per second
rather than 1 every 5 seconds.

This mitigates a build-up of sessions should http sessions gets
established faster than 1 per 5 seconds.

Change-Id: I9820d39aa080109df44fe98c1325cafae48d54f5
Signed-off-by: Jaco Kroon <jaco@uls.co.za>
This commit is contained in:
Jaco Kroon 2022-09-05 08:59:30 +02:00 committed by Friendly Automation
parent 086b1abf66
commit ef20afda63
1 changed files with 16 additions and 3 deletions

View File

@ -7014,16 +7014,17 @@ done:
}
/*! \brief remove at most n_max stale session from the list. */
static void purge_sessions(int n_max)
static int purge_sessions(int n_max)
{
struct ao2_container *sessions;
struct mansession_session *session;
time_t now = time(NULL);
struct ao2_iterator i;
int purged = 0;
sessions = ao2_global_obj_ref(mgr_sessions);
if (!sessions) {
return;
return 0;
}
i = ao2_iterator_init(sessions, 0);
ao2_ref(sessions, -1);
@ -7039,12 +7040,14 @@ static void purge_sessions(int n_max)
ao2_unlock(session);
session_destroy(session);
n_max--;
purged++;
} else {
ao2_unlock(session);
unref_mansession(session);
}
}
ao2_iterator_destroy(&i);
return purged;
}
/*! \brief
@ -8637,7 +8640,17 @@ static int webregged = 0;
*/
static void purge_old_stuff(void *data)
{
purge_sessions(1);
struct ast_tcptls_session_args *ser = data;
/* purge_sessions will return the number of sessions actually purged,
* up to a maximum of it's arguments, purge one at a time, keeping a
* purge interval of 1ms as long as we purged a session, otherwise
* revert to a purge check every 5s
*/
if (purge_sessions(1) == 1) {
ser->poll_timeout = 1;
} else {
ser->poll_timeout = 5000;
}
purge_events();
}