aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-08-04 22:44:28 -0700
committerGarrett D'Amore <garrett@damore.org>2017-08-04 22:44:28 -0700
commit37c7608faa591cd8df4c3523cc3a9f3876835f77 (patch)
tree52ea0e29a10cbb57e2dce645cd5dda99d3d02eea
parentdc334d7193a2a0bc0194221b853a37e1be7f5b9a (diff)
downloadnng-37c7608faa591cd8df4c3523cc3a9f3876835f77.tar.gz
nng-37c7608faa591cd8df4c3523cc3a9f3876835f77.tar.bz2
nng-37c7608faa591cd8df4c3523cc3a9f3876835f77.zip
Hopefully improve scalability test results.
There is still a Windows mystery (and maybe not just Windows) where nng_close() appears to hang unless some output is performed. More testing and analysis is needed here -- but the main message exchanges seem to work fine.
-rw-r--r--tests/scalability.c90
1 files changed, 40 insertions, 50 deletions
diff --git a/tests/scalability.c b/tests/scalability.c
index eee9bc7a..026969ff 100644
--- a/tests/scalability.c
+++ b/tests/scalability.c
@@ -13,8 +13,9 @@
#include <string.h>
-static int nclients = 2000;
-static char *addr = "inproc:///atscale";
+static int nclients = 200;
+
+static char *addr = "inproc:///atscale";
void
serve(void *arg)
@@ -38,13 +39,28 @@ serve(void *arg)
int
openclients(nng_socket *clients, int num)
{
- int rv;
- int i;
+ int rv;
+ int i;
+ uint64_t t;
for (i = 0; i < num; i++) {
if ((rv = nng_open(&clients[i], NNG_PROTO_REQ)) != 0) {
printf("open #%d: %s\n", i, nng_strerror(rv));
return (rv);
}
+ t = 100000; // 100ms
+ rv = nng_setopt(clients[i], NNG_OPT_RCVTIMEO, &t, sizeof(t));
+ if (rv != 0) {
+ printf(
+ "setopt(RCVTIMEO) #%d: %s\n", i, nng_strerror(rv));
+ return (rv);
+ }
+ t = 100000; // 100ms
+ rv = nng_setopt(clients[i], NNG_OPT_SNDTIMEO, &t, sizeof(t));
+ if (rv != 0) {
+ printf(
+ "setopt(SNDTIMEO) #%d: %s\n", i, nng_strerror(rv));
+ return (rv);
+ }
rv = nng_dial(clients[i], addr, NULL, NNG_FLAG_SYNCH);
if (rv != 0) {
printf("dial #%d: %s\n", i, nng_strerror(rv));
@@ -55,7 +71,7 @@ openclients(nng_socket *clients, int num)
}
int
-sendreqs(nng_socket *clients, int num)
+transact(nng_socket *clients, int num)
{
nng_msg *msg;
int rv;
@@ -72,20 +88,9 @@ sendreqs(nng_socket *clients, int num)
printf("sendmsg #%d: %s", i, nng_strerror(rv));
return (rv);
}
- }
- return (0);
-}
-
-int
-recvreps(nng_socket *clients, int num)
-{
- nng_msg *msg;
- int rv;
- int i;
- for (i = 0; i < num; i++) {
if ((rv = nng_recvmsg(clients[i], &msg, 0)) != 0) {
- printf("sendmsg #%d: %s", i, nng_strerror(rv));
+ printf("recvmsg #%d: %s", i, nng_strerror(rv));
return (rv);
}
nng_msg_free(msg);
@@ -97,6 +102,7 @@ void
closeclients(nng_socket *clients, int num)
{
int i;
+ nng_usleep(1000);
for (i = 0; i < num; i++) {
if (clients[i] > 0) {
nng_close(clients[i]);
@@ -108,44 +114,28 @@ Main({
nng_socket *clients;
void * server;
int * results;
+ int depth = 256;
+ nng_socket rep;
clients = calloc(nclients, sizeof(nng_socket));
results = calloc(nclients, sizeof(int));
+ if ((nng_open(&rep, NNG_PROTO_REP) != 0) ||
+ (nng_setopt(rep, NNG_OPT_RCVBUF, &depth, sizeof(depth)) != 0) ||
+ (nng_setopt(rep, NNG_OPT_SNDBUF, &depth, sizeof(depth)) != 0) ||
+ (nng_listen(rep, addr, NULL, NNG_FLAG_SYNCH) != 0) ||
+ (nng_thread_create(&server, serve, &rep) != 0)) {
+ fprintf(stderr, "Unable to set up server!\n");
+ exit(1);
+ }
+
Test("Scalability", {
- Convey("Given a server socket", {
- nng_socket rep;
- int depth = 256;
-
- So(nng_open(&rep, NNG_PROTO_REP) == 0);
- So(nng_setopt(rep, NNG_OPT_RCVBUF, &depth,
- sizeof(depth)) == 0);
- So(nng_setopt(rep, NNG_OPT_SNDBUF, &depth,
- sizeof(depth)) == 0);
- So(nng_listen(rep, addr, NULL, NNG_FLAG_SYNCH) == 0);
-
- So(nng_thread_create(&server, serve, &rep) == 0);
-
- Reset({
- nng_usleep(1000);
- if (rep != 0) {
- nng_close(rep);
- rep = 0;
- }
- });
-
- Convey("We can open many many clients", {
- So(openclients(clients, nclients) == 0);
- Reset({ closeclients(clients, nclients); });
-
- Convey("And we send them messages", {
- So(sendreqs(clients, nclients) == 0);
- Convey("And they receive", {
- So(recvreps(clients,
- nclients) == 0);
- });
- });
- });
+ Convey("We can handle many many clients", {
+ So(openclients(clients, nclients) == 0);
+ So(transact(clients, nclients) == 0);
+ for (int i = 0; i < nclients; i++) {
+ So(nng_close(clients[i]) == 0);
+ }
});
});
});