fix some contention issues under really high load...That doesn't mean you need to push it this hard and bug me about it =p

This commit is contained in:
Anthony Minessale committed 2012-11-07 12:10:50 -06:00
1 parent feb38cece2
commit f60962ae87
7 files changed
+89 -78

No files matched your search

+54 -23
View File
@@ -1027,7 +1027,7 @@ static void conference_data_event_handler(switch_event_t *event)
switch_safe_free(dup_domain);
}
static void actual_sofia_presence_event_handler(switch_event_t *event)
static switch_event_t *actual_sofia_presence_event_handler(switch_event_t *event)
{
sofia_profile_t *profile = NULL;
char *from = switch_event_get_header(event, "from");
@@ -1047,10 +1047,10 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
switch_console_callback_match_t *matches;
struct presence_helper helper = { 0 };
int hup = 0;
switch_event_t *s_event = NULL;
if (!mod_sofia_globals.running) {
return;
goto done;
}
if (zstr(proto) || !strcasecmp(proto, "any")) {
@@ -1091,7 +1091,7 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
if (!mod_sofia_globals.profile_hash) {
return;
goto done;
}
if (from) {
@@ -1171,7 +1171,7 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
}
switch_safe_free(sql);
return;
goto done;
}
if (zstr(event_type)) {
@@ -1195,7 +1195,7 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
}
} else {
switch_safe_free(user);
return;
goto done;
}
if ((euser = strchr(user, '+'))) {
euser++;
@@ -1203,7 +1203,7 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
euser = user;
}
} else {
return;
goto done;
}
switch (event->event_id) {
@@ -1462,8 +1462,7 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
if (hup && dh.hits < 1) {
/* so many phones get confused when whe hangup we have to reprobe to get them all to reset to absolute states so the lights stay correct */
switch_event_t *s_event;
if (switch_event_create(&s_event, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "login", profile->name);
@@ -1471,10 +1470,9 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "to", "%s@%s", euser, host);
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "event_type", "presence");
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog");
switch_event_fire(&s_event);
}
}
if (!zstr((char *) helper.stream.data)) {
char *this_sql = (char *) helper.stream.data;
@@ -1509,11 +1507,24 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
switch_safe_free(sql);
switch_safe_free(user);
return s_event;
}
static int EVENT_THREAD_RUNNING = 0;
static int EVENT_THREAD_STARTED = 0;
static void do_flush(void)
{
void *pop = NULL;
while (mod_sofia_globals.presence_queue && switch_queue_trypop(mod_sofia_globals.presence_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
switch_event_t *event = (switch_event_t *) pop;
switch_event_destroy(&event);
}
}
void *SWITCH_THREAD_FUNC sofia_presence_event_thread_run(switch_thread_t *thread, void *obj)
{
void *pop;
@@ -1544,6 +1555,15 @@ void *SWITCH_THREAD_FUNC sofia_presence_event_thread_run(switch_thread_t *thread
break;
}
if (mod_sofia_globals.presence_flush) {
switch_mutex_lock(mod_sofia_globals.mutex);
if (mod_sofia_globals.presence_flush) {
do_flush();
mod_sofia_globals.presence_flush = 0;
}
switch_mutex_unlock(mod_sofia_globals.mutex);
}
switch(event->event_id) {
case SWITCH_EVENT_MESSAGE_WAITING:
actual_sofia_presence_mwi_event_handler(event);
@@ -1552,7 +1572,11 @@ void *SWITCH_THREAD_FUNC sofia_presence_event_thread_run(switch_thread_t *thread
conference_data_event_handler(event);
break;
default:
actual_sofia_presence_event_handler(event);
do {
switch_event_t *ievent = event;
event = actual_sofia_presence_event_handler(ievent);
switch_event_destroy(&ievent);
} while (event);
break;
}
@@ -1561,10 +1585,7 @@ void *SWITCH_THREAD_FUNC sofia_presence_event_thread_run(switch_thread_t *thread
}
}
while (switch_queue_trypop(mod_sofia_globals.presence_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
switch_event_t *event = (switch_event_t *) pop;
switch_event_destroy(&event);
}
do_flush();
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Event Thread Ended\n");
@@ -1606,13 +1627,23 @@ void sofia_presence_event_handler(switch_event_t *event)
{
switch_event_t *cloned_event;
switch_event_dup(&cloned_event, event);
switch_assert(cloned_event);
switch_queue_push(mod_sofia_globals.presence_queue, cloned_event);
if (!EVENT_THREAD_STARTED) {
sofia_presence_event_thread_start();
switch_yield(500000);
}
switch_event_dup(&cloned_event, event);
switch_assert(cloned_event);
if (switch_queue_trypush(mod_sofia_globals.presence_queue, cloned_event) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Presence queue overloaded.... Flushing queue\n");
switch_mutex_lock(mod_sofia_globals.mutex);
mod_sofia_globals.presence_flush = 1;
switch_mutex_unlock(mod_sofia_globals.mutex);
switch_event_destroy(&cloned_event);
}
}
@@ -1640,7 +1671,7 @@ static int sofia_presence_sub_reg_callback(void *pArg, int argc, char **argv, ch
}
switch_event_fire(&event);
sofia_event_fire(profile, &event);
}
return 0;
}
@@ -1653,7 +1684,7 @@ static int sofia_presence_sub_reg_callback(void *pArg, int argc, char **argv, ch
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_subtype", "probe");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto-specific-event-name", event_name);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "expires", expires);
switch_event_fire(&event);
sofia_event_fire(profile, &event);
}
return 0;
@@ -1777,7 +1808,7 @@ static int sofia_presence_resub_callback(void *pArg, int argc, char **argv, char
}
}
switch_event_fire(&event);
sofia_event_fire(profile, &event);
}
switch_safe_free(free_me);