summaryrefslogtreecommitdiff
path: root/examples/bench
diff options
context:
space:
mode:
authorMicah Anderson <micah@riseup.net>2014-08-11 16:33:29 -0400
committerMicah Anderson <micah@riseup.net>2014-08-11 16:33:29 -0400
commitcce638a8adf4e045ca5505afea4bda57753c31dd (patch)
treeb5e139d3359ac5b8c7b1afa8acbb1b5b6051c626 /examples/bench
initial import of debian package
Diffstat (limited to 'examples/bench')
-rw-r--r--examples/bench/benchmark.py25
-rw-r--r--examples/bench/jsonrpc_client.py4
-rw-r--r--examples/bench/jsonrpc_server.py8
-rw-r--r--examples/bench/latency.pngbin0 -> 58452 bytes
-rw-r--r--examples/bench/msgs_sec.pngbin0 -> 56500 bytes
-rw-r--r--examples/bench/msgs_sec_log.pngbin0 -> 59966 bytes
-rw-r--r--examples/bench/msgs_sec_ratio.pngbin0 -> 39876 bytes
-rw-r--r--examples/bench/plot_latency.py84
-rw-r--r--examples/bench/pyro_client.py3
-rw-r--r--examples/bench/pyro_server.py14
-rw-r--r--examples/bench/pyzmq_client.py16
-rw-r--r--examples/bench/pyzmq_server.py10
-rw-r--r--examples/bench/xmlrpc_client.py6
-rw-r--r--examples/bench/xmlrpc_server.py8
14 files changed, 178 insertions, 0 deletions
diff --git a/examples/bench/benchmark.py b/examples/bench/benchmark.py
new file mode 100644
index 0000000..c379af9
--- /dev/null
+++ b/examples/bench/benchmark.py
@@ -0,0 +1,25 @@
+from timeit import default_timer as timer
+
+def benchmark(f, size, reps):
+ msg = size*'0'
+ t1 = timer()
+ for i in range(reps):
+ msg2 = f(msg)
+ assert msg == msg2
+ t2 = timer()
+ diff = (t2-t1)
+ latency = diff/reps
+ return latency*1000000
+
+kB = [1000*2**n for n in range(10)]
+MB = [1000000*2**n for n in range(8)]
+sizes = [1] + kB + MB
+
+def benchmark_set(f, sizes, reps):
+ latencies = []
+ for size, rep in zip(sizes, reps):
+ print "Running benchmark with %r reps of %r bytes" % (rep, size)
+ lat = benchmark(f, size, rep)
+ latencies.append(lat)
+ return sizes, latencies
+
diff --git a/examples/bench/jsonrpc_client.py b/examples/bench/jsonrpc_client.py
new file mode 100644
index 0000000..7fb6ef4
--- /dev/null
+++ b/examples/bench/jsonrpc_client.py
@@ -0,0 +1,4 @@
+from timeit import default_timer as timer
+from jsonrpclib import Server
+
+client = Server('http://localhost:10000')
diff --git a/examples/bench/jsonrpc_server.py b/examples/bench/jsonrpc_server.py
new file mode 100644
index 0000000..4500a02
--- /dev/null
+++ b/examples/bench/jsonrpc_server.py
@@ -0,0 +1,8 @@
+from jsonrpclib.SimpleJSONRPCServer import SimpleJSONRPCServer
+
+def echo(x):
+ return x
+
+server = SimpleJSONRPCServer(('localhost',10000))
+server.register_function(echo)
+server.serve_forever() \ No newline at end of file
diff --git a/examples/bench/latency.png b/examples/bench/latency.png
new file mode 100644
index 0000000..bb414b5
--- /dev/null
+++ b/examples/bench/latency.png
Binary files differ
diff --git a/examples/bench/msgs_sec.png b/examples/bench/msgs_sec.png
new file mode 100644
index 0000000..a7b294b
--- /dev/null
+++ b/examples/bench/msgs_sec.png
Binary files differ
diff --git a/examples/bench/msgs_sec_log.png b/examples/bench/msgs_sec_log.png
new file mode 100644
index 0000000..c3a361e
--- /dev/null
+++ b/examples/bench/msgs_sec_log.png
Binary files differ
diff --git a/examples/bench/msgs_sec_ratio.png b/examples/bench/msgs_sec_ratio.png
new file mode 100644
index 0000000..0a87331
--- /dev/null
+++ b/examples/bench/msgs_sec_ratio.png
Binary files differ
diff --git a/examples/bench/plot_latency.py b/examples/bench/plot_latency.py
new file mode 100644
index 0000000..f50ef29
--- /dev/null
+++ b/examples/bench/plot_latency.py
@@ -0,0 +1,84 @@
+"""Plot latency data from messaging benchmarks.
+
+To generate the data for each library, I started the server and then did
+the following for each client::
+
+ from xmlrpc_client import client
+ for i in range(9):
+ s = '0'*10**i
+ print s
+ %timeit client.echo(s)
+"""
+
+from matplotlib.pylab import *
+
+rawdata = """# Data in milliseconds
+Bytes JSONRPC PYRO XMLRPC pyzmq_copy pyzmq_nocopy
+1 2.15 0.186 2.07 0.111 0.136
+10 2.49 0.187 1.87 0.115 0.137
+100 2.5 0.189 1.9 0.126 0.138
+1000 2.54 0.196 1.91 0.129 0.141
+10000 2.91 0.271 2.77 0.204 0.197
+100000 6.65 1.44 9.17 0.961 0.546
+1000000 50.2 15.8 81.5 8.39 2.25
+10000000 491 159 816 91.7 25.2
+100000000 5010 1560 8300 893 248
+
+"""
+with open('latency.csv','w') as f:
+ f.writelines(rawdata)
+
+data = csv2rec('latency.csv',delimiter='\t')
+
+loglog(data.bytes, data.xmlrpc*1000, label='XMLRPC')
+loglog(data.bytes, data.jsonrpc*1000, label='JSONRPC')
+loglog(data.bytes, data.pyro*1000, label='Pyro')
+loglog(data.bytes, data.pyzmq_nocopy*1000, label='PyZMQ')
+loglog(data.bytes, len(data.bytes)*[60], label='Ping')
+legend(loc=2)
+title('Latency')
+xlabel('Number of bytes')
+ylabel('Round trip latency ($\mu s$)')
+grid(True)
+show()
+savefig('latency.png')
+
+clf()
+
+semilogx(data.bytes, 1000/data.xmlrpc, label='XMLRPC')
+semilogx(data.bytes, 1000/data.jsonrpc, label='JSONRPC')
+semilogx(data.bytes, 1000/data.pyro, label='Pyro')
+semilogx(data.bytes, 1000/data.pyzmq_nocopy, label='PyZMQ')
+legend(loc=1)
+xlabel('Number of bytes')
+ylabel('Message/s')
+title('Message Throughput')
+grid(True)
+show()
+savefig('msgs_sec.png')
+
+clf()
+
+loglog(data.bytes, 1000/data.xmlrpc, label='XMLRPC')
+loglog(data.bytes, 1000/data.jsonrpc, label='JSONRPC')
+loglog(data.bytes, 1000/data.pyro, label='Pyro')
+loglog(data.bytes, 1000/data.pyzmq_nocopy, label='PyZMQ')
+legend(loc=3)
+xlabel('Number of bytes')
+ylabel('Message/s')
+title('Message Throughput')
+grid(True)
+show()
+savefig('msgs_sec_log.png')
+
+clf()
+
+semilogx(data.bytes, data.pyro/data.pyzmq_nocopy, label="No-copy")
+semilogx(data.bytes, data.pyro/data.pyzmq_copy, label="Copy")
+xlabel('Number of bytes')
+ylabel('Ratio throughputs')
+title('PyZMQ Throughput/Pyro Throughput')
+grid(True)
+legend(loc=2)
+show()
+savefig('msgs_sec_ratio.png')
diff --git a/examples/bench/pyro_client.py b/examples/bench/pyro_client.py
new file mode 100644
index 0000000..5e25feb
--- /dev/null
+++ b/examples/bench/pyro_client.py
@@ -0,0 +1,3 @@
+import Pyro.core
+
+client = Pyro.core.getProxyForURI("PYROLOC://localhost:7766/echo") \ No newline at end of file
diff --git a/examples/bench/pyro_server.py b/examples/bench/pyro_server.py
new file mode 100644
index 0000000..a2a2446
--- /dev/null
+++ b/examples/bench/pyro_server.py
@@ -0,0 +1,14 @@
+import Pyro.core
+
+class Echo(Pyro.core.ObjBase):
+ def __init__(self):
+ Pyro.core.ObjBase.__init__(self)
+ def echo(self, x):
+ return x
+
+Pyro.core.initServer()
+daemon=Pyro.core.Daemon()
+uri=daemon.connect(Echo(),"echo")
+
+daemon.requestLoop()
+ \ No newline at end of file
diff --git a/examples/bench/pyzmq_client.py b/examples/bench/pyzmq_client.py
new file mode 100644
index 0000000..9afccec
--- /dev/null
+++ b/examples/bench/pyzmq_client.py
@@ -0,0 +1,16 @@
+import zmq
+
+c = zmq.Context()
+s = c.socket(zmq.REQ)
+s.connect('tcp://127.0.0.1:10001')
+
+def echo(msg):
+ s.send(msg, copy=False)
+ msg2 = s.recv(copy=False)
+ return msg2
+
+class Client(object):
+ pass
+
+client = Client()
+client.echo = echo
diff --git a/examples/bench/pyzmq_server.py b/examples/bench/pyzmq_server.py
new file mode 100644
index 0000000..cab0082
--- /dev/null
+++ b/examples/bench/pyzmq_server.py
@@ -0,0 +1,10 @@
+import zmq
+
+c = zmq.Context()
+s = c.socket(zmq.REP)
+s.bind('tcp://127.0.0.1:10001')
+
+while True:
+ msg = s.recv(copy=False)
+ s.send(msg)
+
diff --git a/examples/bench/xmlrpc_client.py b/examples/bench/xmlrpc_client.py
new file mode 100644
index 0000000..a73ddfd
--- /dev/null
+++ b/examples/bench/xmlrpc_client.py
@@ -0,0 +1,6 @@
+from timeit import default_timer as timer
+from xmlrpclib import ServerProxy
+
+client = ServerProxy('http://localhost:10002')
+
+ \ No newline at end of file
diff --git a/examples/bench/xmlrpc_server.py b/examples/bench/xmlrpc_server.py
new file mode 100644
index 0000000..24ab019
--- /dev/null
+++ b/examples/bench/xmlrpc_server.py
@@ -0,0 +1,8 @@
+from SimpleXMLRPCServer import SimpleXMLRPCServer
+
+def echo(x):
+ return x
+
+server = SimpleXMLRPCServer(('localhost',10002))
+server.register_function(echo)
+server.serve_forever() \ No newline at end of file