]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
limit simo reg processing threads to 25 and add param to raise it
authorAnthony Minessale <anthm@freeswitch.org>
Thu, 21 Feb 2013 18:26:30 +0000 (12:26 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Thu, 21 Feb 2013 18:26:30 +0000 (12:26 -0600)
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia.c

index 468473cc0e958aebd829b573e9ad3aaf55e83583..6617acd35b6e6121fb933175dfa1b257e6f00a88 100644 (file)
@@ -392,6 +392,7 @@ struct mod_sofia_globals {
        int rewrite_multicasted_fs_path;
        int presence_flush;
        switch_thread_t *presence_thread;
+       uint32_t max_reg_threads;
 };
 extern struct mod_sofia_globals mod_sofia_globals;
 
index 60ab5e49ece7d90c1453491a9a38d55f21d31d17..743a0371ecb0fba18d755ebd3479f02a773e1659 100644 (file)
@@ -1506,11 +1506,17 @@ static void our_sofia_event_callback(nua_event_t event,
        }
 }
 
+static uint32_t DE_THREAD_CNT = 0;
+
 void *SWITCH_THREAD_FUNC sofia_msg_thread_run_once(switch_thread_t *thread, void *obj)
 {
        sofia_dispatch_event_t *de = (sofia_dispatch_event_t *) obj;
        switch_memory_pool_t *pool = NULL;
 
+       switch_mutex_lock(mod_sofia_globals.mutex);
+       DE_THREAD_CNT++;
+       switch_mutex_unlock(mod_sofia_globals.mutex); 
+
        if (de) {
                pool = de->pool;
                de->pool = NULL;
@@ -1521,6 +1527,10 @@ void *SWITCH_THREAD_FUNC sofia_msg_thread_run_once(switch_thread_t *thread, void
                switch_core_destroy_memory_pool(&pool);
        }
 
+       switch_mutex_lock(mod_sofia_globals.mutex);
+       DE_THREAD_CNT--;
+       switch_mutex_unlock(mod_sofia_globals.mutex); 
+
        return NULL;
 }
 
@@ -1660,7 +1670,8 @@ void sofia_queue_message(sofia_dispatch_event_t *de)
        }
 
 
-       if (de->profile && sofia_test_pflag(de->profile, PFLAG_THREAD_PER_REG) && de->data->e_event == nua_i_register) {
+       if (de->profile && sofia_test_pflag(de->profile, PFLAG_THREAD_PER_REG) && 
+               de->data->e_event == nua_i_register && DE_THREAD_CNT < mod_sofia_globals.max_reg_threads) {
                sofia_process_dispatch_event_in_thread(&de);
                return;
        }
@@ -3430,6 +3441,13 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name)
                                mod_sofia_globals.debug_presence = atoi(val);
                        } else if (!strcasecmp(var, "debug-sla")) {
                                mod_sofia_globals.debug_sla = atoi(val);
+                       } else if (!strcasecmp(var, "max-reg-threads") && val) {
+                               int x = atoi(val);
+
+                               if (x > 0) {
+                                       mod_sofia_globals.max_reg_threads = x;
+                               }
+                               
                        } else if (!strcasecmp(var, "auto-restart")) {
                                mod_sofia_globals.auto_restart = switch_true(val);
                        } else if (!strcasecmp(var, "reg-deny-binding-fetch-and-no-lookup")) {          /* backwards compatibility */
@@ -3831,7 +3849,7 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name)
                                                        sofia_clear_pflag(profile, PFLAG_MESSAGE_QUERY_ON_REGISTER);
                                                        sofia_clear_pflag(profile, PFLAG_MESSAGE_QUERY_ON_FIRST_REGISTER);
                                                }
-                                       } else if (!strcasecmp(var, "inbound-reg-in-new-thread")) {
+                                       } else if (!strcasecmp(var, "inbound-reg-in-new-thread") && val) {
                                                if (switch_true(val)) {
                                                        sofia_set_pflag(profile, PFLAG_THREAD_PER_REG);
                                                } else {