]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
manager: be more aggressive about purging http sessions.
authorJaco Kroon <jaco@uls.co.za>
Mon, 5 Sep 2022 06:59:30 +0000 (08:59 +0200)
committerFriendly Automation <jenkins2@gerrit.asterisk.org>
Thu, 22 Sep 2022 16:20:52 +0000 (11:20 -0500)
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>
main/manager.c

index 4ea3d972977d6d07e8ebc3032b96d8d0e72f818b..7a6b14d86cb2aa8a24517410087530abcb64182f 100644 (file)
@@ -7019,16 +7019,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);
@@ -7044,12 +7045,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
@@ -8642,7 +8645,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();
 }