From 2939262e233bef8039abd5ed1dca9a625243c5c3 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 11 Jul 2011 21:27:06 -0500 Subject: [PATCH] pause traffic if sql_queue gets to big --- src/switch_core_sqldb.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index dc307be11d..7d40114ed1 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -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;