From cc12510e510bc8e7f1b6d9e3816c6779caeee46c Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 7 May 2018 19:42:33 -0700 Subject: fixes #304 perf tool exits too quickly on throughput client This adds a synchronization at exit step, where the server sends a completion message to the client. This permits the client to to be sure that the server has got all the data. There is a 5 second timeout, which should allow this to work (albeit with a weird 5 second completion delay) with legacy servers. --- perf/perf.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/perf/perf.c b/perf/perf.c index 2002ad7f..6bf6a2aa 100644 --- a/perf/perf.c +++ b/perf/perf.c @@ -431,6 +431,10 @@ throughput_server(const char *addr, size_t msgsize, int count) nng_msg_free(msg); } end = nng_clock(); + // Send a synchronization message (empty) to the other side, + // and wait a bit to make sure it goes out the wire. + nng_send(s, "", 0, 0); + nng_msleep(200); nng_close(s); total = (float) ((end - start)) / 1000; msgpersec = (float) (count) / total; @@ -465,6 +469,11 @@ throughput_client(const char *addr, size_t msgsize, int count) die("nng_setopt(nng_opt_sendbuf): %s", nng_strerror(rv)); } + rv = nng_setopt_ms(s, NNG_OPT_RECVTIMEO, 5000); + if (rv != 0) { + die("nng_setopt(nng_opt_recvtimeo): %s", nng_strerror(rv)); + } + if ((rv = nng_dial(s, addr, NULL, 0)) != 0) { die("nng_dial: %s", nng_strerror(rv)); } @@ -486,7 +495,10 @@ throughput_client(const char *addr, size_t msgsize, int count) } } - // Wait 100msec for pipes to drain. - nng_msleep(100); + // Attempt to get the completion indication from the other side. + if (nng_recvmsg(s, &msg, 0) == 0) { + nng_msg_free(msg); + } + nng_close(s); } -- cgit v1.2.3-70-g09d2