[Asterisk-code-review] test astobj2 thrash: Fix multithreaded issues (asterisk[master])

Anonymous Coward asteriskteam at digium.com
Wed Oct 26 17:20:12 CDT 2016


Anonymous Coward #1000019 has submitted this change and it was merged. ( https://gerrit.asterisk.org/4179 )

Change subject: test_astobj2_thrash:  Fix multithreaded issues
......................................................................


test_astobj2_thrash:  Fix multithreaded issues

The test uses 4 threads to grow, count, lookup and shrink 15K objects
in a container.  If there's only 1 execution engine available, the test
will complete in <50ms.  If each threads gets its own execution engine,
the test may timeout after 60 seconds because the count thread does a
locked ao2_callback on the whole container in a tight loop with only
a sched_yield to give up time.  The lock contention makes the test
execution times wildly variable and mostly timeout.  2 execution
engines are OK, 3 results in about 33% failure rate and >=4 causes
a 80% failure rate.

To fix, the sched_yield was changed to a usleep(500).

Also, the number of buckets specified for the container was an even
number so that was changed to the next prime number greater than
(MAX_HASH_ENTRIES / 100).  That's 151 currently.

Change-Id: I50cd2344161ea61bfe4b96d2a29a6ccf88385c77
---
M tests/test_astobj2_thrash.c
1 file changed, 9 insertions(+), 2 deletions(-)

Approvals:
  Mark Michelson: Looks good to me, approved
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, but someone else must approve



diff --git a/tests/test_astobj2_thrash.c b/tests/test_astobj2_thrash.c
index eaadbb6..ef0da44 100644
--- a/tests/test_astobj2_thrash.c
+++ b/tests/test_astobj2_thrash.c
@@ -46,6 +46,13 @@
 #include "asterisk/utils.h"
 
 #define MAX_HASH_ENTRIES 15000
+/*
+ * Use one of the online calculators to find the first prime number
+ * greater than MAX_HASH_ENTRIES / 100.
+ */
+#define HASH_BUCKETS 151
+
+#define COUNT_SLEEP_US 500
 #define MAX_TEST_SECONDS 60
 
 struct hash_test {
@@ -207,7 +214,7 @@
 
 		if (last_count == count) {
 			/* Allow other threads to run. */
-			sched_yield();
+			usleep(COUNT_SLEEP_US);
 		} else if (last_count > count) {
 			/* Make sure the ao2 container never shrinks */
 			return "ao2 container unexpectedly shrank";
@@ -261,7 +268,7 @@
 	data.preload = MAX_HASH_ENTRIES / 2;
 	data.max_grow = MAX_HASH_ENTRIES - data.preload;
 	data.deadline = ast_tvadd(ast_tvnow(), ast_tv(MAX_TEST_SECONDS, 0));
-	data.to_be_thrashed = ao2_container_alloc(MAX_HASH_ENTRIES / 100, hash_string,
+	data.to_be_thrashed = ao2_container_alloc(HASH_BUCKETS, hash_string,
 		compare_strings);
 
 	if (data.to_be_thrashed == NULL) {

-- 
To view, visit https://gerrit.asterisk.org/4179
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I50cd2344161ea61bfe4b96d2a29a6ccf88385c77
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>



More information about the asterisk-code-review mailing list