From e0beb13b066d27ce32347a1c18c9d441828dc553 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 9 May 2018 10:24:35 -0700 Subject: fixes #423 desire tunable stress time and pressure in stress tests Use -p STRESSPRESSURE= (default 32) and -p STRESSTIME= to affect stress run. Pressure should be a number [2,x] where x is determined by the number of threads and file descriptors your platform can handle. Modern platforms should be able to handle at least 100. --- tests/reqstress.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'tests/reqstress.c') diff --git a/tests/reqstress.c b/tests/reqstress.c index 81249946..f2ee502d 100644 --- a/tests/reqstress.c +++ b/tests/reqstress.c @@ -150,13 +150,17 @@ req_client(void *arg) nng_msleep(rand() % 10); - if (((rv = nng_msg_alloc(&msg, 0)) != 0) || - ((rv = nng_msg_append(msg, buf, strlen(buf) + 1)) != 0)) { + if ((rv = nng_msg_alloc(&msg, 0)) != 0) { error(c, "alloc fail", rv); return; } - + if ((rv = nng_msg_append(msg, buf, strlen(buf) + 1)) != 0) { + nng_msg_free(msg); + error(c, "append fail", rv); + return; + } if ((rv = nng_sendmsg(req, msg, 0)) != 0) { + nng_msg_free(msg); error(c, "sendmsg", rv); return; } @@ -169,6 +173,7 @@ req_client(void *arg) if (strcmp(nng_msg_body(msg), buf) != 0) { error(c, "mismatched message", NNG_EINTERNAL); + nng_msg_free(msg); return; } @@ -226,7 +231,22 @@ reqrep_test(int ntests) } Main({ - int i; + int i; + int tmo; + char *str; + + atexit(nng_fini); + + if (((str = ConveyGetEnv("STRESSTIME")) == NULL) || + ((tmo = atoi(str)) < 1)) { + tmo = 30; + } + // We have to keep this relatively low by default because some + // platforms don't support large numbers of threads. + if (((str = ConveyGetEnv("STRESSPRESSURE")) == NULL) || + ((ncases = atoi(str)) < 1)) { + ncases = 32; + } // Each run should truly be random. srand((int) time(NULL)); @@ -235,10 +255,6 @@ Main({ // subsequent runs. next_port += (rand() % 100) * 100; - // We have to keep this relatively low because some platforms - // don't support large numbers of threads. - ncases = 32; - i = ncases; cases = calloc(ncases, sizeof(test_case)); @@ -251,8 +267,8 @@ Main({ i -= x; } - dprintf("WAITING for 30 sec...\n"); - nng_msleep(30000); // sleep 30 sec + dprintf("WAITING for %d sec...\n", tmo); + nng_msleep(tmo * 1000); // sleep 30 sec nng_closeall(); Test("Req/Rep Stress", { -- cgit v1.2.3-70-g09d2