diff --git a/test1.c b/test1.c index e0cd37b..2e0d791 100644 --- a/test1.c +++ b/test1.c @@ -24,6 +24,7 @@ int main(int argc, char *argv[]) { FILE *f; struct timeval start_time; long bytecount = -1; + long last_report_bytecount = 0; if (argc < 2) { fprintf(stderr, "Usage: test1 \n"); @@ -66,7 +67,7 @@ int main(int argc, char *argv[]) { } if (bytecount >= 0) { bytecount += n; - if ((bytecount % 100000) < MESSAGESIZE) { + if ((bytecount - last_report_bytecount) > (100000 * MESSAGESIZE)) { struct timeval now; double delta; gettimeofday(&now, NULL); @@ -77,6 +78,7 @@ int main(int argc, char *argv[]) { bytecount / delta, bytecount / (delta * MESSAGESIZE)); fflush(stdout); + last_report_bytecount = bytecount; } } } diff --git a/test1_latency.c b/test1_latency.c index f801853..2d713a3 100644 --- a/test1_latency.c +++ b/test1_latency.c @@ -20,10 +20,11 @@ #define EXPECTEDPREFIX "(4:post8:consumer8:" -static void hunt_for_latencies_in(char *buf, size_t count) { +static size_t hunt_for_latencies_in(char *buf, size_t count) { struct timeval now; char *pos = buf; char *sentinel = buf + count; + size_t msgsize = 0; gettimeofday(&now, NULL); @@ -47,8 +48,12 @@ static void hunt_for_latencies_in(char *buf, size_t count) { printf("Latency %g microseconds (%g milliseconds)\n", delta, delta / 1000.0); } + msgsize = closeptr + 1 - openptr; + pos = closeptr + 1; } + + return msgsize; } int main(int argc, char *argv[]) { @@ -57,6 +62,8 @@ int main(int argc, char *argv[]) { FILE *f; struct timeval start_time; long bytecount = -1; + size_t message_size = 0; + long last_report_bytecount = 0; if (argc < 2) { fprintf(stderr, "Usage: test1 \n"); @@ -81,9 +88,6 @@ int main(int argc, char *argv[]) { fprintf(f, "(9:subscribe5:test10:0:5:test15:login)(4:post7:factory(6:create5:queue(2:q1)5:test11:k)0:)(4:post2:q1(9:subscribe0:5:test18:consumer5:test11:k)0:)\n"); fflush(f); -#define PAYLOADSIZE 8 -#define MESSAGESIZE 59 + PAYLOADSIZE /* 59by overhead, incl 36by subscription token (!) */ - while (1) { char buf[1024]; size_t n = read(fd, buf, sizeof(buf)); @@ -99,19 +103,26 @@ int main(int argc, char *argv[]) { } } if (bytecount >= 0) { - hunt_for_latencies_in(buf, n); + size_t detected_msgsize = hunt_for_latencies_in(buf, n); bytecount += n; - if ((bytecount % 100000) < MESSAGESIZE) { - struct timeval now; - double delta; - gettimeofday(&now, NULL); - delta = (now.tv_sec - start_time.tv_sec) + (now.tv_usec - start_time.tv_usec) / 1000000.0; - printf("So far received %ld bytes in %g seconds = %g bytes/sec and %g msgs/sec\n", - bytecount, - delta, - bytecount / delta, - bytecount / (delta * MESSAGESIZE)); - fflush(stdout); + if (detected_msgsize != 0 && message_size == 0) { + message_size = detected_msgsize; + printf("message_size = %lu\n", message_size); + } + if (message_size != 0) { + if ((bytecount - last_report_bytecount) > (100000 * message_size)) { + struct timeval now; + double delta; + gettimeofday(&now, NULL); + delta = (now.tv_sec - start_time.tv_sec) + (now.tv_usec - start_time.tv_usec) / 1000000.0; + printf("So far received %ld bytes in %g seconds = %g bytes/sec and %g msgs/sec\n", + bytecount, + delta, + bytecount / delta, + bytecount / (delta * message_size)); + fflush(stdout); + last_report_bytecount = bytecount; + } } } }