From 6a5120b1f1c48d19b777f76ac756b00fb624d110 Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Wed, 2 Sep 2009 10:22:23 +0200 Subject: python extension & perf tests --- perf/c/local_thr.c | 6 +++++- perf/cpp/local_thr.cpp | 5 ++++- perf/python/local_lat.py | 42 ++++++++++++------------------------------ perf/python/local_thr.py | 44 ++++++++++++++++++++------------------------ perf/python/remote_lat.py | 43 ++++++++++++++++++++++--------------------- perf/python/remote_thr.py | 17 ++++++++--------- 6 files changed, 71 insertions(+), 86 deletions(-) (limited to 'perf') diff --git a/perf/c/local_thr.c b/perf/c/local_thr.c index 87c3220..b58fac3 100644 --- a/perf/c/local_thr.c +++ b/perf/c/local_thr.c @@ -38,6 +38,7 @@ int main (int argc, char *argv []) struct timeval end; uint64_t elapsed; uint64_t throughput; + double megabits; if (argc != 4) { printf ("usage: local_thr " @@ -81,12 +82,15 @@ int main (int argc, char *argv []) elapsed = ((uint64_t) end.tv_sec * 1000000 + end.tv_usec) - ((uint64_t) start.tv_sec * 1000000 + start.tv_usec); - + if (elapsed == 0) + elapsed = 1; throughput = (uint64_t) message_count * 1000000 / elapsed; + megabits = (double) (throughput * message_size * 8) / 1000000; printf ("message size: %d [B]\n", (int) message_size); printf ("message count: %d\n", (int) message_count); printf ("mean throughput: %d [msg/s]\n", (int) throughput); + printf ("mean throughput: %3f [Mb/s]\n", (double) megabits); return 0; } diff --git a/perf/cpp/local_thr.cpp b/perf/cpp/local_thr.cpp index fdcbc8d..e328117 100644 --- a/perf/cpp/local_thr.cpp +++ b/perf/cpp/local_thr.cpp @@ -63,12 +63,15 @@ int main (int argc, char *argv []) uint64_t elapsed = ((uint64_t) end.tv_sec * 1000000 + end.tv_usec) - ((uint64_t) start.tv_sec * 1000000 + start.tv_usec); - + if (elapsed == 0) + elapsed = 1; uint64_t throughput = (uint64_t) message_count * 1000000 / elapsed; + double megabits = (double) (throughput * message_size * 8) / 1000000; printf ("message size: %d [B]\n", (int) message_size); printf ("message count: %d\n", (int) message_count); printf ("mean throughput: %d [msg/s]\n", (int) throughput); + printf ("mean throughput: %3f [Mb/s]\n", (double) megabits); return 0; } diff --git a/perf/python/local_lat.py b/perf/python/local_lat.py index 9883dc0..7f1503f 100644 --- a/perf/python/local_lat.py +++ b/perf/python/local_lat.py @@ -18,50 +18,32 @@ # import sys -from datetime import datetime -import libpyzmq import time - +import libpyzmq def main (): - if len (sys.argv) != 5: - print 'usage: py_local_lat ' + if len (sys.argv) != 4: + print 'usage: local_lat ' sys.exit (1) try: - in_interface = sys.argv [1] - out_interface = sys.argv [2] + bind_to = sys.argv [1] + roundtrip_count = int (sys.argv [2]) message_size = int (sys.argv [3]) - roundtrip_count = int (sys.argv [4]) except (ValueError, OverflowError), e: print 'message-size and roundtrip-count must be integers' sys.exit (1) - print "message size:", message_size, "[B]" - print "roundtrip count:", roundtrip_count + ctx = libpyzmq.Context (1, 1); + s = libpyzmq.Socket (ctx, libpyzmq.REP) + s.bind (bind_to) - z = libpyzmq.Zmq () - context = z.context (1,1); - - in_socket = z.socket (context, libpyzmq.ZMQ_SUB) - out_socket = z.socket (context, libpyzmq.ZMQ_PUB) - - z.bind (in_socket, addr = in_interface) - z.bind (out_socket, addr = out_interface) - - msg_out = z.init_msg_data (string_msg, type) - - start = datetime.now () for i in range (0, roundtrip_count): - z.send (out_socket, msg_out, True) - list = z.receive (in_socket, True) - msg_in = list [1] - assert len(msg_in) == message_size - end = datetime.now () + msg = s.recv () + assert len (msg) == message_size + s.send (msg) - delta = end - start - delta_us = delta.seconds * 1000000 + delta.microseconds - print 'Your average latency is', delta_us / roundtrip_count, ' [us]' + time.sleep (1) if __name__ == "__main__": main () diff --git a/perf/python/local_thr.py b/perf/python/local_thr.py index 9b199df..6113c82 100644 --- a/perf/python/local_thr.py +++ b/perf/python/local_thr.py @@ -23,46 +23,42 @@ import libpyzmq def main (): if len (sys.argv) != 4: - print ('usage: py_local_thr ' + - '') + print 'usage: local_thr ' sys.exit (1) try: + bind_to = sys.argv [1] message_size = int (sys.argv [2]) message_count = int (sys.argv [3]) except (ValueError, OverflowError), e: print 'message-size and message-count must be integers' sys.exit (1) - print "message size:", message_size, "[B]" - print "message count:", message_count + ctx = libpyzmq.Context (1, 1); + s = libpyzmq.Socket (ctx, libpyzmq.P2P) + s.bind (bind_to) - z = libpyzmq.Zmq () + msg = s.recv () + assert len (msg) == message_size - context = z.context (1,1) - in_socket = z.socket (context, libpyzmq.ZMQ_SUB) - z.connect (in_socketaddr = sys.argv [1]) - - - list = z.receive (in_socket, True) - msg = list [1] - assert len(msg) == message_size start = datetime.now () + for i in range (1, message_count): - list = z.receive (in_socket, True) - msg = list [1] - assert len(msg) == message_size + msg = s.recv () + assert len (msg) == message_size + end = datetime.now() - delta = end - start - delta_us = delta.seconds * 1000000 + delta.microseconds - if delta_us == 0: - delta_us = 1 - message_thr = (1000000.0 * float (message_count)) / float (delta_us) - megabit_thr = (message_thr * float (message_size) * 8.0) / 1000000.0; + elapsed = (end - start).seconds * 1000000 + (end - start).microseconds + if elapsed == 0: + elapsed = 1 + throughput = (1000000.0 * float (message_count)) / float (elapsed) + megabits = float (throughput * message_size * 8) / 1000000 - print "Your average throughput is %.0f [msg/s]" % (message_thr, ) - print "Your average throughput is %.2f [Mb/s]" % (megabit_thr, ) + print "message size: %.0f [B]" % (message_size, ) + print "message count: %.0f" % (message_count, ) + print "mean throughput: %.0f [msg/s]" % (throughput, ) + print "mean throughput: %.3f [Mb/s]" % (megabits, ) if __name__ == "__main__": main () diff --git a/perf/python/remote_lat.py b/perf/python/remote_lat.py index ac73595..372f567 100644 --- a/perf/python/remote_lat.py +++ b/perf/python/remote_lat.py @@ -20,39 +20,40 @@ import sys from datetime import datetime import libpyzmq -import time - def main (): - if len(sys.argv) != 5: - print ('usage: py_remote_lat ' + - ' ') + if len(sys.argv) != 4: + print 'usage: remote_lat ' sys.exit (1) try: - message_size = int (sys.argv [3]) - roundtrip_count = int (sys.argv [4]) + connect_to = sys.argv [1] + message_size = int (sys.argv [2]) + roundtrip_count = int (sys.argv [3]) except (ValueError, OverflowError), e: print 'message-size and message-count must be integers' sys.exit (1) - z = libpyzmq.Zmq () + ctx = libpyzmq.Context (1, 1); + s = libpyzmq.Socket (ctx, libpyzmq.REQ) + s.connect (connect_to) + + msg = ''.join ([' ' for n in range (0, message_size)]) + + start = datetime.now () - context = z.context (1,1) - - in_socket = z.socket (context, libpyzmq.ZMQ_SUB) - out_socket = z.socket (context, libpyzmq.ZMQ_PUB) - - z.connect (in_socket, addr = in_interface) - z.connect (out_socket, addr = out_interface) - for i in range (0, roundtrip_count): - list = z.receive (in_socket, True) - message = list [1] - z.send (out_socket, message, True) - - time.sleep (2) + s.send (msg) + msg = s.recv () + assert len (msg) == message_size + + end = datetime.now () + delta = (end - start).microseconds + 1000000 * (end - start).seconds + latency = delta / roundtrip_count / 2 + print "message size: %.0f [B]" % (message_size, ) + print "roundtrip count: %.0f" % (roundtrip_count, ) + print "mean latency: %.3f [us]" % (latency, ) if __name__ == "__main__": main () diff --git a/perf/python/remote_thr.py b/perf/python/remote_thr.py index a4f2b66..a80adfd 100644 --- a/perf/python/remote_thr.py +++ b/perf/python/remote_thr.py @@ -18,33 +18,32 @@ # import sys -from datetime import datetime import libpyzmq import time def main (): if len (sys.argv) != 4: - print 'usage: py_remote_thr ' + print 'usage: remote_thr ' sys.exit (1) try: + connect_to = argv [1] message_size = int (sys.argv [2]) message_count = int (sys.argv [3]) except (ValueError, OverflowError), e: print 'message-size and message-count must be integers' sys.exit (1) - z = libpyzmq.Zmq () - context = z.context (1,1); - out_socket = z.socket (context, libpyzmq.ZMQ_PUB) - z.bind (out_socket, addr = sys.argv [1]) + ctx = libpyzmq.Context (1, 1); + s = libpyzmq.Socket (ctx, libpyzmq.P2P) + s.connect (connect_to) - msg = z.init_msg_data (string_msg, type) + msg = ''.join ([' ' for n in range (0, message_size)]) for i in range (0, message_count): - z.send (out_socket, msg, True) + s.send (msg) - time.sleep (2) + time.sleep (10) if __name__ == "__main__": main () -- cgit v1.2.3