[Asterisk-code-review] manager: be more aggressive about purging http sessions. (asterisk[master])

Jaco Kroon asteriskteam at digium.com
Mon Aug 15 16:29:17 CDT 2022


Jaco Kroon has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/18976 )


Change subject: manager: be more aggressive about purging http sessions.
......................................................................

manager: be more aggressive about purging http sessions.

If we find that max_n (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: I4117ae25acc9c92bd1d3cfa73d7d334f5c3480c2
Signed-off-by: Jaco Kroon <jaco at uls.co.za>
---
M main/manager.c
1 file changed, 11 insertions(+), 4 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/76/18976/1

diff --git a/main/manager.c b/main/manager.c
index eb0459e..5939b07 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -7014,16 +7014,17 @@
 }
 
 /*! \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 @@
 			ao2_unlock(session);
 			session_destroy(session);
 			n_max--;
+			purged++;
 		} else {
 			ao2_unlock(session);
 			unref_mansession(session);
 		}
 	}
 	ao2_iterator_destroy(&i);
+	return purged;
 }
 
 /*! \brief
@@ -8635,9 +8638,13 @@
 /*! \brief cleanup code called at each iteration of server_root,
  * guaranteed to happen every 5 seconds at most
  */
-static void purge_old_stuff(void *data)
+static void purge_old_stuff(struct ast_tcptls_session_args *data)
 {
-	purge_sessions(1);
+	if (purge_sessions(1) == 1) {
+		data->poll_timeout = 1;
+	} else {
+		data->poll_timeout = 5000;
+	}
 	purge_events();
 }
 

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/18976
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I4117ae25acc9c92bd1d3cfa73d7d334f5c3480c2
Gerrit-Change-Number: 18976
Gerrit-PatchSet: 1
Gerrit-Owner: Jaco Kroon <jaco at uls.co.za>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220815/9352a9b1/attachment.html>


More information about the asterisk-code-review mailing list