summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid M. Lee <dlee@digium.com>2013-09-30 18:55:27 +0000
committerDavid M. Lee <dlee@digium.com>2013-09-30 18:55:27 +0000
commit2de42c2a257947d0a376d861dbd1ca76923e7930 (patch)
treea01a063af4857ba99e8fa3f7892dd41c6edf826a /tests
parentdb7c8691a06bd896070e1a9c4f90309104509190 (diff)
Multiple revisions 399887,400138,400178,400180-400181
........ r399887 | dlee | 2013-09-26 10:41:47 -0500 (Thu, 26 Sep 2013) | 1 line Minor performance bump by not allocate manager variable struct if we don't need it ........ r400138 | dlee | 2013-09-30 10:24:00 -0500 (Mon, 30 Sep 2013) | 23 lines Stasis performance improvements This patch addresses several performance problems that were found in the initial performance testing of Asterisk 12. The Stasis dispatch object was allocated as an AO2 object, even though it has a very confined lifecycle. This was replaced with a straight ast_malloc(). The Stasis message router was spending an inordinate amount of time searching hash tables. In this case, most of our routers had 6 or fewer routes in them to begin with. This was replaced with an array that's searched linearly for the route. We more heavily rely on AO2 objects in Asterisk 12, and the memset() in ao2_ref() actually became noticeable on the profile. This was #ifdef'ed to only run when AO2_DEBUG was enabled. After being misled by an erroneous comment in taskprocessor.c during profiling, the wrong comment was removed. Review: https://reviewboard.asterisk.org/r/2873/ ........ r400178 | dlee | 2013-09-30 13:26:27 -0500 (Mon, 30 Sep 2013) | 24 lines Taskprocessor optimization; switch Stasis to use taskprocessors This patch optimizes taskprocessor to use a semaphore for signaling, which the OS can do a better job at managing contention and waiting that we can with a mutex and condition. The taskprocessor execution was also slightly optimized to reduce the number of locks taken. The only observable difference in the taskprocessor implementation is that when the final reference to the taskprocessor goes away, it will execute all tasks to completion instead of discarding the unexecuted tasks. For systems where unnamed semaphores are not supported, a really simple semaphore implementation is provided. (Which gives identical performance as the original taskprocessor implementation). The way we ended up implementing Stasis caused the threadpool to be a burden instead of a boost to performance. This was switched to just use taskprocessors directly for subscriptions. Review: https://reviewboard.asterisk.org/r/2881/ ........ r400180 | dlee | 2013-09-30 13:39:34 -0500 (Mon, 30 Sep 2013) | 28 lines Optimize how Stasis forwards are dispatched This patch optimizes how forwards are dispatched in Stasis. Originally, forwards were dispatched as subscriptions that are invoked on the publishing thread. This did not account for the vast number of forwards we would end up having in the system, and the amount of work it would take to walk though the forward subscriptions. This patch modifies Stasis so that rather than walking the tree of forwards on every dispatch, when forwards and subscriptions are changed, the subscriber list for every topic in the tree is changed. This has a couple of benefits. First, this reduces the workload of dispatching messages. It also reduces contention when dispatching to different topics that happen to forward to the same aggregation topic (as happens with all of the channel, bridge and endpoint topics). Since forwards are no longer subscriptions, the bulk of this patch is simply changing stasis_subscription objects to stasis_forward objects (which, admittedly, I should have done in the first place.) Since this required me to yet again put in a growing array, I finally abstracted that out into a set of ast_vector macros in asterisk/vector.h. Review: https://reviewboard.asterisk.org/r/2883/ ........ r400181 | dlee | 2013-09-30 13:48:57 -0500 (Mon, 30 Sep 2013) | 28 lines Remove dispatch object allocation from Stasis publishing While looking for areas for performance improvement, I realized that an unused feature in Stasis was negatively impacting performance. When a message is sent to a subscriber, a dispatch object is allocated for the dispatch, containing the topic the message was published to, the subscriber the message is being sent to, and the message itself. The topic is actually unused by any subscriber in Asterisk today. And the subscriber is associated with the taskprocessor the message is being dispatched to. First, this patch removes the unused topic parameter from Stasis subscription callbacks. Second, this patch introduces the concept of taskprocessor local data, data that may be set on a taskprocessor and provided along with the data pointer when a task is pushed using the ast_taskprocessor_push_local() call. This allows the task to have both data specific to that taskprocessor, in addition to data specific to that invocation. With those two changes, the dispatch object can be removed completely, and the message is simply refcounted and sent directly to the taskprocessor. Review: https://reviewboard.asterisk.org/r/2884/ ........ Merged revisions 399887,400138,400178,400180-400181 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@400186 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'tests')
-rw-r--r--tests/test_devicestate.c4
-rw-r--r--tests/test_stasis.c62
-rw-r--r--tests/test_stasis_endpoints.c9
-rw-r--r--tests/test_taskprocessor.c160
4 files changed, 142 insertions, 93 deletions
diff --git a/tests/test_devicestate.c b/tests/test_devicestate.c
index ff5d681f4..5a3d255d1 100644
--- a/tests/test_devicestate.c
+++ b/tests/test_devicestate.c
@@ -309,7 +309,7 @@ static struct consumer *consumer_create(void) {
return consumer;
}
-static void consumer_exec(void *data, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *message)
+static void consumer_exec(void *data, struct stasis_subscription *sub, struct stasis_message *message)
{
struct consumer *consumer = data;
RAII_VAR(struct consumer *, consumer_needs_cleanup, NULL, ao2_cleanup);
@@ -342,7 +342,7 @@ static void consumer_exec(void *data, struct stasis_subscription *sub, struct st
}
}
-static void consumer_finalize(void *data, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *message)
+static void consumer_finalize(void *data, struct stasis_subscription *sub, struct stasis_message *message)
{
struct consumer *consumer = data;
diff --git a/tests/test_stasis.c b/tests/test_stasis.c
index da9c50874..1e911e092 100644
--- a/tests/test_stasis.c
+++ b/tests/test_stasis.c
@@ -183,7 +183,7 @@ static struct consumer *consumer_create(int ignore_subscriptions) {
return consumer;
}
-static void consumer_exec(void *data, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *message)
+static void consumer_exec(void *data, struct stasis_subscription *sub, struct stasis_message *message)
{
struct consumer *consumer = data;
RAII_VAR(struct consumer *, consumer_needs_cleanup, NULL, ao2_cleanup);
@@ -427,7 +427,7 @@ AST_TEST_DEFINE(forward)
RAII_VAR(struct consumer *, parent_consumer, NULL, ao2_cleanup);
RAII_VAR(struct consumer *, consumer, NULL, ao2_cleanup);
- RAII_VAR(struct stasis_subscription *, forward_sub, NULL, stasis_unsubscribe);
+ RAII_VAR(struct stasis_forward *, forward_sub, NULL, stasis_forward_cancel);
RAII_VAR(struct stasis_subscription *, parent_sub, NULL, stasis_unsubscribe);
RAII_VAR(struct stasis_subscription *, sub, NULL, stasis_unsubscribe);
@@ -499,8 +499,8 @@ AST_TEST_DEFINE(interleaving)
RAII_VAR(struct stasis_message *, test_message2, NULL, ao2_cleanup);
RAII_VAR(struct stasis_message *, test_message3, NULL, ao2_cleanup);
- RAII_VAR(struct stasis_subscription *, forward_sub1, NULL, stasis_unsubscribe);
- RAII_VAR(struct stasis_subscription *, forward_sub2, NULL, stasis_unsubscribe);
+ RAII_VAR(struct stasis_forward *, forward_sub1, NULL, stasis_forward_cancel);
+ RAII_VAR(struct stasis_forward *, forward_sub2, NULL, stasis_forward_cancel);
RAII_VAR(struct stasis_subscription *, sub, NULL, stasis_unsubscribe);
RAII_VAR(struct consumer *, consumer, NULL, ao2_cleanup);
@@ -711,7 +711,6 @@ AST_TEST_DEFINE(cache)
/* Check for new snapshot messages */
ast_test_validate(test, stasis_cache_update_type() == stasis_message_type(consumer->messages_rxed[0]));
actual_update = stasis_message_data(consumer->messages_rxed[0]);
- ast_test_validate(test, topic == actual_update->topic);
ast_test_validate(test, NULL == actual_update->old_snapshot);
ast_test_validate(test, test_message1_1 == actual_update->new_snapshot);
ast_test_validate(test, test_message1_1 == stasis_cache_get(cache, cache_type, "1"));
@@ -720,7 +719,6 @@ AST_TEST_DEFINE(cache)
ast_test_validate(test, stasis_cache_update_type() == stasis_message_type(consumer->messages_rxed[1]));
actual_update = stasis_message_data(consumer->messages_rxed[1]);
- ast_test_validate(test, topic == actual_update->topic);
ast_test_validate(test, NULL == actual_update->old_snapshot);
ast_test_validate(test, test_message2_1 == actual_update->new_snapshot);
ast_test_validate(test, test_message2_1 == stasis_cache_get(cache, cache_type, "2"));
@@ -736,7 +734,6 @@ AST_TEST_DEFINE(cache)
ast_test_validate(test, 3 == actual_len);
actual_update = stasis_message_data(consumer->messages_rxed[2]);
- ast_test_validate(test, topic == actual_update->topic);
ast_test_validate(test, test_message2_1 == actual_update->old_snapshot);
ast_test_validate(test, test_message2_2 == actual_update->new_snapshot);
ast_test_validate(test, test_message2_2 == stasis_cache_get(cache, cache_type, "2"));
@@ -752,7 +749,6 @@ AST_TEST_DEFINE(cache)
ast_test_validate(test, 4 == actual_len);
actual_update = stasis_message_data(consumer->messages_rxed[3]);
- ast_test_validate(test, topic == actual_update->topic);
ast_test_validate(test, test_message1_1 == actual_update->old_snapshot);
ast_test_validate(test, NULL == actual_update->new_snapshot);
ast_test_validate(test, NULL == stasis_cache_get(cache, cache_type, "1"));
@@ -867,52 +863,6 @@ AST_TEST_DEFINE(cache_dump)
return AST_TEST_PASS;
}
-AST_TEST_DEFINE(route_conflicts)
-{
- RAII_VAR(struct stasis_topic *, topic, NULL, ao2_cleanup);
- RAII_VAR(struct stasis_message_router *, uut, NULL, stasis_message_router_unsubscribe_and_join);
- RAII_VAR(struct stasis_message_type *, test_message_type, NULL, ao2_cleanup);
- RAII_VAR(struct consumer *, consumer1, NULL, ao2_cleanup);
- RAII_VAR(struct consumer *, consumer2, NULL, ao2_cleanup);
- int ret;
-
- switch (cmd) {
- case TEST_INIT:
- info->name = __func__;
- info->category = test_category;
- info->summary =
- "Multiple routes to the same message_type should fail";
- info->description =
- "Multiple routes to the same message_type should fail";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
-
- topic = stasis_topic_create("TestTopic");
- ast_test_validate(test, NULL != topic);
-
- consumer1 = consumer_create(1);
- ast_test_validate(test, NULL != consumer1);
- consumer2 = consumer_create(1);
- ast_test_validate(test, NULL != consumer2);
-
- test_message_type = stasis_message_type_create("TestMessage", NULL);
- ast_test_validate(test, NULL != test_message_type);
-
- uut = stasis_message_router_create(topic);
- ast_test_validate(test, NULL != uut);
-
- ret = stasis_message_router_add(
- uut, test_message_type, consumer_exec, consumer1);
- ast_test_validate(test, 0 == ret);
- ret = stasis_message_router_add(
- uut, test_message_type, consumer_exec, consumer2);
- ast_test_validate(test, 0 != ret);
-
- return AST_TEST_PASS;
-}
-
AST_TEST_DEFINE(router)
{
RAII_VAR(struct stasis_topic *, topic, NULL, ao2_cleanup);
@@ -1272,7 +1222,7 @@ AST_TEST_DEFINE(to_ami)
}
static void noop(void *data, struct stasis_subscription *sub,
- struct stasis_topic *topic, struct stasis_message *message)
+ struct stasis_message *message)
{
/* no-op */
}
@@ -1373,7 +1323,6 @@ static int unload_module(void)
AST_TEST_UNREGISTER(cache_filter);
AST_TEST_UNREGISTER(cache);
AST_TEST_UNREGISTER(cache_dump);
- AST_TEST_UNREGISTER(route_conflicts);
AST_TEST_UNREGISTER(router);
AST_TEST_UNREGISTER(router_cache_updates);
AST_TEST_UNREGISTER(interleaving);
@@ -1397,7 +1346,6 @@ static int load_module(void)
AST_TEST_REGISTER(cache_filter);
AST_TEST_REGISTER(cache);
AST_TEST_REGISTER(cache_dump);
- AST_TEST_REGISTER(route_conflicts);
AST_TEST_REGISTER(router);
AST_TEST_REGISTER(router_cache_updates);
AST_TEST_REGISTER(interleaving);
diff --git a/tests/test_stasis_endpoints.c b/tests/test_stasis_endpoints.c
index c0be07ca8..bc0f57572 100644
--- a/tests/test_stasis_endpoints.c
+++ b/tests/test_stasis_endpoints.c
@@ -264,11 +264,14 @@ AST_TEST_DEFINE(channel_messages)
type = stasis_message_type(msg);
ast_test_validate(test, ast_channel_snapshot_type() == type);
+ /* The ordering of the cache clear and endpoint snapshot are
+ * unspecified */
msg = sink->messages[3];
- type = stasis_message_type(msg);
- ast_test_validate(test, stasis_cache_clear_type() == type);
+ if (stasis_message_type(msg) == stasis_cache_clear_type()) {
+ /* Okay; the next message should be the endpoint snapshot */
+ msg = sink->messages[4];
+ }
- msg = sink->messages[4];
type = stasis_message_type(msg);
ast_test_validate(test, ast_endpoint_snapshot_type() == type);
actual_snapshot = stasis_message_data(msg);
diff --git a/tests/test_taskprocessor.c b/tests/test_taskprocessor.c
index 70400a9ec..be48f9248 100644
--- a/tests/test_taskprocessor.c
+++ b/tests/test_taskprocessor.c
@@ -48,6 +48,31 @@ struct task_data {
int task_complete;
};
+static void task_data_dtor(void *obj)
+{
+ struct task_data *task_data = obj;
+
+ ast_mutex_destroy(&task_data->lock);
+ ast_cond_destroy(&task_data->cond);
+}
+
+/*! \brief Create a task_data object */
+static struct task_data *task_data_create(void)
+{
+ struct task_data *task_data =
+ ao2_alloc(sizeof(*task_data), task_data_dtor);
+
+ if (!task_data) {
+ return NULL;
+ }
+
+ ast_cond_init(&task_data->cond, NULL);
+ ast_mutex_init(&task_data->lock);
+ task_data->task_complete = 0;
+
+ return task_data;
+}
+
/*!
* \brief Queued task for baseline test.
*
@@ -65,6 +90,30 @@ static int task(void *data)
}
/*!
+ * \brief Wait for a task to execute.
+ */
+static int task_wait(struct task_data *task_data)
+{
+ struct timeval start = ast_tvnow();
+ struct timespec end;
+ SCOPED_MUTEX(lock, &task_data->lock);
+
+ end.tv_sec = start.tv_sec + 30;
+ end.tv_nsec = start.tv_usec * 1000;
+
+ while (!task_data->task_complete) {
+ int res;
+ res = ast_cond_timedwait(&task_data->cond, &task_data->lock,
+ &end);
+ if (res == ETIMEDOUT) {
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+/*!
* \brief Baseline test for default taskprocessor
*
* This test ensures that when a task is added to a taskprocessor that
@@ -73,12 +122,9 @@ static int task(void *data)
*/
AST_TEST_DEFINE(default_taskprocessor)
{
- struct ast_taskprocessor *tps;
- struct task_data task_data;
- struct timeval start;
- struct timespec ts;
- enum ast_test_result_state res = AST_TEST_PASS;
- int timedwait_res;
+ RAII_VAR(struct ast_taskprocessor *, tps, NULL, ast_taskprocessor_unreference);
+ RAII_VAR(struct task_data *, task_data, NULL, ao2_cleanup);
+ int res;
switch (cmd) {
case TEST_INIT:
@@ -99,36 +145,21 @@ AST_TEST_DEFINE(default_taskprocessor)
return AST_TEST_FAIL;
}
- start = ast_tvnow();
-
- ts.tv_sec = start.tv_sec + 30;
- ts.tv_nsec = start.tv_usec * 1000;
-
- ast_cond_init(&task_data.cond, NULL);
- ast_mutex_init(&task_data.lock);
- task_data.task_complete = 0;
-
- ast_taskprocessor_push(tps, task, &task_data);
- ast_mutex_lock(&task_data.lock);
- while (!task_data.task_complete) {
- timedwait_res = ast_cond_timedwait(&task_data.cond, &task_data.lock, &ts);
- if (timedwait_res == ETIMEDOUT) {
- break;
- }
+ task_data = task_data_create();
+ if (!task_data) {
+ ast_test_status_update(test, "Unable to create task_data\n");
+ return AST_TEST_FAIL;
}
- ast_mutex_unlock(&task_data.lock);
- if (!task_data.task_complete) {
+ ast_taskprocessor_push(tps, task, task_data);
+
+ res = task_wait(task_data);
+ if (res != 0) {
ast_test_status_update(test, "Queued task did not execute!\n");
- res = AST_TEST_FAIL;
- goto test_end;
+ return AST_TEST_FAIL;
}
-test_end:
- tps = ast_taskprocessor_unreference(tps);
- ast_mutex_destroy(&task_data.lock);
- ast_cond_destroy(&task_data.cond);
- return res;
+ return AST_TEST_PASS;
}
#define NUM_TASKS 20000
@@ -631,12 +662,78 @@ AST_TEST_DEFINE(taskprocessor_shutdown)
return AST_TEST_PASS;
}
+static int local_task_exe(struct ast_taskprocessor_local *local)
+{
+ int *local_data = local->local_data;
+ struct task_data *task_data = local->data;
+
+ *local_data = 1;
+ task(task_data);
+
+ return 0;
+}
+
+AST_TEST_DEFINE(taskprocessor_push_local)
+{
+ RAII_VAR(struct ast_taskprocessor *, tps, NULL,
+ ast_taskprocessor_unreference);
+ struct task_data *task_data;
+ int local_data;
+ int res;
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = __func__;
+ info->category = "/main/taskprocessor/";
+ info->summary = "Test of pushing local data";
+ info->description =
+ "Ensures that local data is passed along.";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+
+ tps = ast_taskprocessor_get("test", TPS_REF_DEFAULT);
+ if (!tps) {
+ ast_test_status_update(test, "Unable to create test taskprocessor\n");
+ return AST_TEST_FAIL;
+ }
+
+
+ task_data = task_data_create();
+ if (!task_data) {
+ ast_test_status_update(test, "Unable to create task_data\n");
+ return AST_TEST_FAIL;
+ }
+
+ local_data = 0;
+ ast_taskprocessor_set_local(tps, &local_data);
+
+ ast_taskprocessor_push_local(tps, local_task_exe, task_data);
+
+ res = task_wait(task_data);
+ if (res != 0) {
+ ast_test_status_update(test, "Queued task did not execute!\n");
+ return AST_TEST_FAIL;
+ }
+
+ if (local_data != 1) {
+ ast_test_status_update(test,
+ "Queued task did not set local_data!\n");
+ return AST_TEST_FAIL;
+ }
+
+ return AST_TEST_PASS;
+}
+
static int unload_module(void)
{
ast_test_unregister(default_taskprocessor);
ast_test_unregister(default_taskprocessor_load);
ast_test_unregister(taskprocessor_listener);
ast_test_unregister(taskprocessor_shutdown);
+ ast_test_unregister(taskprocessor_push_local);
return 0;
}
@@ -646,6 +743,7 @@ static int load_module(void)
ast_test_register(default_taskprocessor_load);
ast_test_register(taskprocessor_listener);
ast_test_register(taskprocessor_shutdown);
+ ast_test_register(taskprocessor_push_local);
return AST_MODULE_LOAD_SUCCESS;
}