]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
pause traffic if sql_queue gets to big
authorAnthony Minessale <anthm@freeswitch.org>
Tue, 12 Jul 2011 02:27:06 +0000 (21:27 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Tue, 12 Jul 2011 02:27:36 +0000 (21:27 -0500)
src/switch_core_sqldb.c

index dc307be11ddd2d4c14c474bbbeb2868de47bc38a..7d40114ed1e1b3bfe075136e33e2b51e4c1fbf81 100644 (file)
@@ -942,7 +942,9 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
        switch_size_t newlen;
        int lc = 0, wrote = 0, do_sleep = 1;
        uint32_t sanity = 120;
-       
+       int too_long = SWITCH_SQL_QUEUE_LEN / 2;
+       int auto_pause = 0;
+
        switch_assert(sqlbuf);
 
        while (!sql_manager.event_db) {
@@ -1021,6 +1023,23 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
 
                lc = switch_queue_size(sql_manager.sql_queue[0]) + switch_queue_size(sql_manager.sql_queue[1]);
 
+
+               if (lc > too_long) {
+                       if (!auto_pause) {
+                               auto_pause = 1;
+                               switch_core_session_ctl(SCSC_PAUSE_INBOUND, &auto_pause);
+                               auto_pause = 1;
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "SQL Queue overflowing [%d], Pausing calls.\n", lc);
+                       }
+               } else {
+                       if (auto_pause && lc < 1000) {
+                               auto_pause = 0;
+                               switch_core_session_ctl(SCSC_PAUSE_INBOUND, &auto_pause);
+                               auto_pause = 0;
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "SQL Queue back to normal size, resuming..\n");
+                       }
+               }
+
        skip:
                
                wrote = 0;
@@ -1052,7 +1071,7 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
                if (!lc) {
                        switch_thread_cond_wait(sql_manager.cond, sql_manager.cond_mutex);
                } else if (wrote) {
-                       if (lc > 200) {
+                       if (lc > 2000) {
                                do_sleep = 0;
                        } else {
                                do_sleep = 1;