some perfomance tweaks

This commit is contained in:
Anthony Minessale
2012-05-03 16:31:21 -05:00
parent 2368f556ac
commit 8664dc6d5a
10 changed files with 141 additions and 105 deletions
+14 -4
View File
@@ -91,6 +91,10 @@ static switch_status_t sofia_on_init(switch_core_session_t *session)
sofia_set_flag(tech_pvt, TFLAG_RECOVERED);
}
if (switch_channel_direction(tech_pvt->channel) == SWITCH_CALL_DIRECTION_INBOUND) {
nua_respond(tech_pvt->nh, 101, "Dialing", TAG_END());
}
if (sofia_test_flag(tech_pvt, TFLAG_OUTBOUND) || sofia_test_flag(tech_pvt, TFLAG_RECOVERING)) {
const char *var;
@@ -5343,7 +5347,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load)
switch_chat_interface_t *chat_interface;
switch_api_interface_t *api_interface;
switch_management_interface_t *management_interface;
uint32_t cpus = switch_core_cpu_count();
struct in_addr in;
memset(&mod_sofia_globals, 0, sizeof(mod_sofia_globals));
@@ -5381,9 +5384,16 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Waiting for profiles to start\n");
switch_yield(1500000);
/* start one message thread per cpu */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Starting %u message threads.\n", cpus);
sofia_msg_thread_start(cpus);
mod_sofia_globals.cpu_count = switch_core_cpu_count();
mod_sofia_globals.max_msg_queues = mod_sofia_globals.cpu_count + 1;
if (mod_sofia_globals.max_msg_queues > SOFIA_MAX_MSG_QUEUE) {
mod_sofia_globals.max_msg_queues = SOFIA_MAX_MSG_QUEUE;
}
/* start one message thread */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Starting initial message thread.\n");
sofia_msg_thread_start(0);
if (switch_event_bind_removable(modname, SWITCH_EVENT_CUSTOM, MULTICAST_EVENT, event_handler, NULL,
&mod_sofia_globals.custom_node) != SWITCH_STATUS_SUCCESS) {
+4 -2
View File
@@ -336,8 +336,8 @@ typedef enum {
TFLAG_MAX
} TFLAGS;
#define SOFIA_MAX_MSG_QUEUE 101
#define SOFIA_MSG_QUEUE_SIZE 5000
#define SOFIA_MAX_MSG_QUEUE 64
#define SOFIA_MSG_QUEUE_SIZE 100
struct mod_sofia_globals {
switch_memory_pool_t *pool;
@@ -347,6 +347,8 @@ struct mod_sofia_globals {
uint32_t callid;
int32_t running;
int32_t threads;
int cpu_count;
int max_msg_queues;
switch_mutex_t *mutex;
char guess_ip[80];
char hostname[512];
+40 -34
View File
@@ -1236,8 +1236,25 @@ void *SWITCH_THREAD_FUNC sofia_msg_thread_run(switch_thread_t *thread, void *obj
{
void *pop;
switch_queue_t *q = (switch_queue_t *) obj;
int my_id;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "MSG Thread Started\n");
for (my_id = 0; my_id < mod_sofia_globals.msg_queue_len; my_id++) {
if (mod_sofia_globals.msg_queue[my_id] == q) {
break;
}
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "MSG Thread %d Started\n", my_id);
#ifdef HAVE_CPU_SET_MACROS
{
cpu_set_t set;
CPU_ZERO(&set);
CPU_SET(my_id, &set);
sched_setaffinity(0, sizeof(set), &set);
}
#endif
while(switch_queue_pop(q, &pop) == SWITCH_STATUS_SUCCESS && pop) {
@@ -1251,12 +1268,11 @@ void *SWITCH_THREAD_FUNC sofia_msg_thread_run(switch_thread_t *thread, void *obj
return NULL;
}
static int IDX = 0;
void sofia_msg_thread_start(int idx)
{
if (idx >= SOFIA_MAX_MSG_QUEUE || (idx < mod_sofia_globals.msg_queue_len && mod_sofia_globals.msg_queue_thread[idx])) {
if (idx >= mod_sofia_globals.max_msg_queues ||
idx >= SOFIA_MAX_MSG_QUEUE || (idx < mod_sofia_globals.msg_queue_len && mod_sofia_globals.msg_queue_thread[idx])) {
return;
}
@@ -1274,7 +1290,7 @@ void sofia_msg_thread_start(int idx)
switch_threadattr_create(&thd_attr, mod_sofia_globals.pool);
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
//switch_threadattr_priority_increase(thd_attr);
switch_threadattr_priority_increase(thd_attr);
switch_thread_create(&mod_sofia_globals.msg_queue_thread[i],
thd_attr,
sofia_msg_thread_run,
@@ -1290,31 +1306,32 @@ void sofia_msg_thread_start(int idx)
static void sofia_queue_message(sofia_dispatch_event_t *de)
{
int idx = 0;
int idx = 0, queued = 0;
if (mod_sofia_globals.running == 0) {
if (mod_sofia_globals.running == 0 || !mod_sofia_globals.msg_queue[0]) {
sofia_process_dispatch_event(&de);
return;
}
again:
switch_mutex_lock(mod_sofia_globals.mutex);
idx = IDX;
IDX++;
if (IDX >= mod_sofia_globals.msg_queue_len) IDX = 0;
switch_mutex_unlock(mod_sofia_globals.mutex);
sofia_msg_thread_start(idx);
if (switch_queue_trypush(mod_sofia_globals.msg_queue[idx], de) != SWITCH_STATUS_SUCCESS) {
if (mod_sofia_globals.msg_queue_len < SOFIA_MAX_MSG_QUEUE) {
sofia_msg_thread_start(idx + 1);
goto again;
} else {
switch_queue_push(mod_sofia_globals.msg_queue[idx], de);
for (idx = 0; idx < mod_sofia_globals.msg_queue_len; idx++) {
if (switch_queue_trypush(mod_sofia_globals.msg_queue[idx], de) == SWITCH_STATUS_SUCCESS) {
queued++;
break;
}
}
if (!queued) {
if (mod_sofia_globals.msg_queue_len < mod_sofia_globals.max_msg_queues) {
sofia_msg_thread_start(mod_sofia_globals.msg_queue_len + 1);
goto again;
}
switch_queue_push(mod_sofia_globals.msg_queue[0], de);
}
}
@@ -1959,6 +1976,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
NUTAG_AUTOACK(0),
NUTAG_AUTOALERT(0),
NUTAG_ENABLEMESSENGER(1),
NTATAG_EXTRA_100(0),
TAG_IF((profile->mflags & MFLAG_REGISTER), NUTAG_ALLOW("REGISTER")),
TAG_IF((profile->mflags & MFLAG_REFER), NUTAG_ALLOW("REFER")),
TAG_IF(!sofia_test_pflag(profile, PFLAG_DISABLE_100REL), NUTAG_ALLOW("PRACK")),
@@ -3652,18 +3670,6 @@ switch_status_t config_sofia(int reload, char *profile_name)
mod_sofia_globals.debug_sla = atoi(val);
} else if (!strcasecmp(var, "auto-restart")) {
mod_sofia_globals.auto_restart = switch_true(val);
} else if (!strcasecmp(var, "message-threads")) {
int num = atoi(val);
if (num < 1 || num > SOFIA_MAX_MSG_QUEUE - 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "message-threads must be between 1 and %d", SOFIA_MAX_MSG_QUEUE -1);
}
if (num < 1) num = 1;
if (num > SOFIA_MAX_MSG_QUEUE - 1) num = SOFIA_MAX_MSG_QUEUE -1;
sofia_msg_thread_start(num);
} else if (!strcasecmp(var, "reg-deny-binding-fetch-and-no-lookup")) { /* backwards compatibility */
mod_sofia_globals.reg_deny_binding_fetch_and_no_lookup = switch_true(val); /* remove when noone complains about the extra lookup */
if (switch_true(val)) {
@@ -7521,7 +7527,7 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
nua_respond(nh, 400, "Missing Contact Header", TAG_END());
goto fail;
}
sofia_glue_get_addr(de->data->e_msg, network_ip, sizeof(network_ip), &network_port);
if (sofia_test_pflag(profile, PFLAG_AGGRESSIVE_NAT_DETECTION)) {