pause traffic if sql_queue gets to big

This commit is contained in:
Anthony Minessale 2011-07-11 21:27:06 -05:00
parent 01861950cc
commit 2939262e23
1 changed files with 21 additions and 2 deletions

View 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;