]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
a few optimizations
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 15 Apr 2011 16:18:26 +0000 (16:18 +0000)
committerAnthony Minessale <anthm@freeswitch.org>
Fri, 15 Apr 2011 16:18:26 +0000 (16:18 +0000)
src/switch_core_sqldb.c
src/switch_event.c

index 940b1c4698a0bf7024218da31f6cd416ae35b626..a1baa9e2c52482a9bafe8331062ac8d1ce716c1c 100644 (file)
@@ -201,9 +201,11 @@ SWITCH_DECLARE(switch_status_t) _switch_core_db_handle(switch_cache_db_handle_t
                r = _switch_cache_db_get_db_handle(dbh, SCDB_TYPE_CORE_DB, &options, file, func, line);
        }
 
+       /* I *think* we can do without this now, if not let me know 
        if (r == SWITCH_STATUS_SUCCESS && !(*dbh)->io_mutex) {
                (*dbh)->io_mutex = sql_manager.io_mutex;
        }
+       */
 
        return r;
 }
index 86bf0c245cee99421dfd6ad3733a25a933ce7c34..9816834d37ba026f395948546674437022c51098 100644 (file)
@@ -291,6 +291,7 @@ static void *SWITCH_THREAD_FUNC switch_event_thread(switch_thread_t *thread, voi
        switch_queue_t *queue = (switch_queue_t *) obj;
        uint32_t index = 0;
        int my_id = 0;
+       int auto_pause = 0;
 
        switch_mutex_lock(EVENT_QUEUE_MUTEX);
        THREAD_COUNT++;
@@ -307,6 +308,14 @@ static void *SWITCH_THREAD_FUNC switch_event_thread(switch_thread_t *thread, voi
                switch_event_t *event = NULL;
                int loops = 0;
 
+               if (auto_pause) {
+                       if (!--auto_pause) {
+                               switch_core_session_ctl(SCSC_PAUSE_INBOUND, &auto_pause);
+                       } else {
+                               switch_cond_next();
+                       }
+               }
+
                if (switch_queue_pop(queue, &pop) != SWITCH_STATUS_SUCCESS) {
                        break;
                }
@@ -323,8 +332,22 @@ static void *SWITCH_THREAD_FUNC switch_event_thread(switch_thread_t *thread, voi
 
                while (event) {
 
+
                        if (++loops > 2) {
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Event system overloading\n");
+                               uint32_t last_sps = 0, sess_count = switch_core_session_count();
+                               if (auto_pause) {
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Event system *still* overloading.\n");
+                               } else {
+                                       switch_core_session_ctl(SCSC_LAST_SPS, &last_sps);
+                                       last_sps = (uint32_t) (float) (last_sps * 0.75f);
+                                       sess_count = (uint32_t) (float) (sess_count * 0.75f);
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, 
+                                                                         "Event system overloading. Taking a 10 second break, Reducing max_sessions to %d %dsps\n", sess_count, last_sps);
+                                       switch_core_session_limit(sess_count);
+                                       switch_core_session_ctl(SCSC_SPS, &last_sps);
+                                       auto_pause = 10;
+                                       switch_core_session_ctl(SCSC_PAUSE_INBOUND, &auto_pause);
+                               }
                                switch_yield(1000000);
                        }