some priority queuing tweaks for performance

This commit is contained in:
Anthony Minessale 2012-10-01 11:47:26 -05:00
parent bf060c6396
commit 8733a2c895
7 changed files with 16 additions and 5 deletions

View File

@ -7748,6 +7748,7 @@ static void launch_conference_thread(conference_obj_t *conference)
switch_set_flag_locked(conference, CFLAG_RUNNING); switch_set_flag_locked(conference, CFLAG_RUNNING);
switch_threadattr_create(&thd_attr, conference->pool); switch_threadattr_create(&thd_attr, conference->pool);
switch_threadattr_detach_set(thd_attr, 1); switch_threadattr_detach_set(thd_attr, 1);
switch_threadattr_priority_increase(thd_attr);
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
switch_mutex_lock(globals.hash_mutex); switch_mutex_lock(globals.hash_mutex);
switch_mutex_unlock(globals.hash_mutex); switch_mutex_unlock(globals.hash_mutex);

View File

@ -1599,7 +1599,7 @@ void *SWITCH_THREAD_FUNC sofia_msg_thread_run(switch_thread_t *thread, void *obj
msg_queue_threads++; msg_queue_threads++;
switch_mutex_unlock(mod_sofia_globals.mutex); switch_mutex_unlock(mod_sofia_globals.mutex);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "MSG Thread %d Started\n", my_id); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "MSG Thread %d Started\n", my_id);
for(;;) { for(;;) {
@ -1612,12 +1612,13 @@ void *SWITCH_THREAD_FUNC sofia_msg_thread_run(switch_thread_t *thread, void *obj
if (pop) { if (pop) {
sofia_dispatch_event_t *de = (sofia_dispatch_event_t *) pop; sofia_dispatch_event_t *de = (sofia_dispatch_event_t *) pop;
sofia_process_dispatch_event(&de); sofia_process_dispatch_event(&de);
switch_os_yield();
} else { } else {
break; break;
} }
} }
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "MSG Thread Ended\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "MSG Thread Ended\n");
switch_mutex_lock(mod_sofia_globals.mutex); switch_mutex_lock(mod_sofia_globals.mutex);
msg_queue_threads--; msg_queue_threads--;
@ -1934,6 +1935,8 @@ void sofia_event_callback(nua_event_t event,
if (profile->pres_type) { if (profile->pres_type) {
switch_cond_next(); switch_cond_next();
} else {
switch_os_yield();
} }

View File

@ -736,7 +736,7 @@ SWITCH_DECLARE(int32_t) set_realtime_priority(void)
char data[] = "-1\n"; char data[] = "-1\n";
struct sched_param sched = { 0 }; struct sched_param sched = { 0 };
sched.sched_priority = 1; sched.sched_priority = 1;
if (sched_setscheduler(0, SCHED_FIFO, &sched)) { if (sched_setscheduler(0, SCHED_RR, &sched)) {
sched.sched_priority = 0; sched.sched_priority = 0;
if (sched_setscheduler(0, SCHED_OTHER, &sched)) { if (sched_setscheduler(0, SCHED_OTHER, &sched)) {
return -1; return -1;

View File

@ -112,6 +112,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
switch_assert(session != NULL); switch_assert(session != NULL);
switch_os_yield();
if (switch_mutex_trylock(session->codec_read_mutex) == SWITCH_STATUS_SUCCESS) { if (switch_mutex_trylock(session->codec_read_mutex) == SWITCH_STATUS_SUCCESS) {
switch_mutex_unlock(session->codec_read_mutex); switch_mutex_unlock(session->codec_read_mutex);
} else { } else {

View File

@ -2539,7 +2539,7 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
switch_threadattr_create(&thd_attr, sql_manager.memory_pool); switch_threadattr_create(&thd_attr, sql_manager.memory_pool);
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
switch_threadattr_priority_increase(thd_attr);
switch_core_sqldb_start_thread(); switch_core_sqldb_start_thread();
switch_thread_create(&sql_manager.db_thread, thd_attr, switch_core_sql_db_thread, NULL, sql_manager.memory_pool); switch_thread_create(&sql_manager.db_thread, thd_attr, switch_core_sql_db_thread, NULL, sql_manager.memory_pool);
@ -2641,6 +2641,7 @@ SWITCH_DECLARE(void) switch_core_sqldb_start_thread(void)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Starting SQL thread.\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Starting SQL thread.\n");
switch_threadattr_create(&thd_attr, sql_manager.memory_pool); switch_threadattr_create(&thd_attr, sql_manager.memory_pool);
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
switch_threadattr_priority_increase(thd_attr);
switch_thread_create(&sql_manager.thread, thd_attr, switch_core_sql_thread, NULL, sql_manager.memory_pool); switch_thread_create(&sql_manager.thread, thd_attr, switch_core_sql_thread, NULL, sql_manager.memory_pool);
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL thread is already running\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL thread is already running\n");

View File

@ -276,6 +276,7 @@ static void *SWITCH_THREAD_FUNC switch_event_dispatch_thread(switch_thread_t *th
event = (switch_event_t *) pop; event = (switch_event_t *) pop;
switch_event_deliver(&event); switch_event_deliver(&event);
switch_os_yield();
} }

View File

@ -150,6 +150,7 @@ SWITCH_DECLARE(void) switch_os_yield(void)
#if defined(WIN32) #if defined(WIN32)
SwitchToThread(); SwitchToThread();
#else #else
usleep(1);
sched_yield(); sched_yield();
#endif #endif
} }
@ -672,8 +673,10 @@ static switch_status_t timer_next(switch_timer_t *timer)
while (globals.RUNNING == 1 && private_info->ready && TIMER_MATRIX[timer->interval].tick < private_info->reference) { while (globals.RUNNING == 1 && private_info->ready && TIMER_MATRIX[timer->interval].tick < private_info->reference) {
check_roll(); check_roll();
switch_os_yield();
if (runtime.tipping_point && globals.timer_count >= runtime.tipping_point) { if (runtime.tipping_point && globals.timer_count >= runtime.tipping_point) {
switch_os_yield();
globals.use_cond_yield = 0; globals.use_cond_yield = 0;
} else { } else {
if (globals.use_cond_yield == 1) { if (globals.use_cond_yield == 1) {