From 4cd5bd27cf9f3d2f2a2214ca2bec7139ec2ca13c Mon Sep 17 00:00:00 2001 From: "Robert G. Jakabosky" Date: Sat, 26 Feb 2011 03:21:32 -0800 Subject: [PATCH] Update link to 0MQ docs. Add benchmarks that use send()/recv() instead of send_msg()/recv_msg() interface. --- README.md | 2 +- perf/no_msg/local_lat.lua | 50 ++++++++++++++++++++++++ perf/no_msg/local_thr.lua | 69 ++++++++++++++++++++++++++++++++ perf/no_msg/remote_lat.lua | 64 ++++++++++++++++++++++++++++++ perf/no_msg/remote_thr.lua | 50 ++++++++++++++++++++++++ zmq.nobj.lua | 80 +++++++++++++++++++------------------- 6 files changed, 274 insertions(+), 41 deletions(-) create mode 100644 perf/no_msg/local_lat.lua create mode 100644 perf/no_msg/local_thr.lua create mode 100644 perf/no_msg/remote_lat.lua create mode 100644 perf/no_msg/remote_thr.lua diff --git a/README.md b/README.md index 00fecb9..750f204 100644 --- a/README.md +++ b/README.md @@ -65,4 +65,4 @@ API === See [API.md](http://github.com/iamaleksey/lua-zmq/blob/master/API.md) and -[ØMQ docs](http://www.zeromq.org/area:docs-v20). +[ØMQ docs](http://api.zero.mq/2-1-1:_start). diff --git a/perf/no_msg/local_lat.lua b/perf/no_msg/local_lat.lua new file mode 100644 index 0000000..adac027 --- /dev/null +++ b/perf/no_msg/local_lat.lua @@ -0,0 +1,50 @@ +-- Copyright (c) 2010 Aleksey Yeschenko +-- +-- Permission is hereby granted, free of charge, to any person obtaining a copy +-- of this software and associated documentation files (the "Software"), to deal +-- in the Software without restriction, including without limitation the rights +-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +-- copies of the Software, and to permit persons to whom the Software is +-- furnished to do so, subject to the following conditions: +-- +-- The above copyright notice and this permission notice shall be included in +-- all copies or substantial portions of the Software. +-- +-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +-- THE SOFTWARE. + +if not arg[3] then + print("usage: lua local_lat.lua []") + os.exit() +end + +local bind_to = arg[1] +local message_size = tonumber(arg[2]) +local roundtrip_count = tonumber(arg[3]) +local mod = arg[4] or "zmq" +if mod == 'disable_ffi' then + disable_ffi = true + mod = 'zmq' +end + +local zmq = require(mod) + +local ctx = zmq.init(1) +local s = ctx:socket(zmq.REP) +s:bind(bind_to) + +local msg + +for i = 1, roundtrip_count do + msg = s:recv() + assert(#msg == message_size, "Invalid message size") + s:send(msg) +end + +s:close() +ctx:term() diff --git a/perf/no_msg/local_thr.lua b/perf/no_msg/local_thr.lua new file mode 100644 index 0000000..6e845e5 --- /dev/null +++ b/perf/no_msg/local_thr.lua @@ -0,0 +1,69 @@ +-- Copyright (c) 2010 Aleksey Yeschenko +-- +-- Permission is hereby granted, free of charge, to any person obtaining a copy +-- of this software and associated documentation files (the "Software"), to deal +-- in the Software without restriction, including without limitation the rights +-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +-- copies of the Software, and to permit persons to whom the Software is +-- furnished to do so, subject to the following conditions: +-- +-- The above copyright notice and this permission notice shall be included in +-- all copies or substantial portions of the Software. +-- +-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +-- THE SOFTWARE. + +if not arg[3] then + print("usage: lua local_thr.lua []") + os.exit() +end + +local bind_to = arg[1] +local message_size = tonumber(arg[2]) +local message_count = tonumber(arg[3]) +local mod = arg[4] or "zmq" +if mod == 'disable_ffi' then + disable_ffi = true + mod = 'zmq' +end + +local zmq = require(mod) + +local socket = require"socket" +local time = socket.gettime + +local ctx = zmq.init(1) +local s = ctx:socket(zmq.SUB) +s:setopt(zmq.SUBSCRIBE, ""); +s:bind(bind_to) + +local msg +msg = s:recv() + +local start_time = time() + +for i = 1, message_count - 1 do + msg = s:recv() + assert(#msg == message_size, "Invalid message size") +end + +local end_time = time() + +s:close() +ctx:term() + +local elapsed = end_time - start_time +if elapsed == 0 then elapsed = 1 end + +local throughput = message_count / elapsed +local megabits = throughput * message_size * 8 / 1000000 + +print(string.format("message size: %i [B]", message_size)) +print(string.format("message count: %i", message_count)) +print(string.format("mean throughput: %i [msg/s]", throughput)) +print(string.format("mean throughput: %.3f [Mb/s]", megabits)) diff --git a/perf/no_msg/remote_lat.lua b/perf/no_msg/remote_lat.lua new file mode 100644 index 0000000..76a4e96 --- /dev/null +++ b/perf/no_msg/remote_lat.lua @@ -0,0 +1,64 @@ +-- Copyright (c) 2010 Aleksey Yeschenko +-- +-- Permission is hereby granted, free of charge, to any person obtaining a copy +-- of this software and associated documentation files (the "Software"), to deal +-- in the Software without restriction, including without limitation the rights +-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +-- copies of the Software, and to permit persons to whom the Software is +-- furnished to do so, subject to the following conditions: +-- +-- The above copyright notice and this permission notice shall be included in +-- all copies or substantial portions of the Software. +-- +-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +-- THE SOFTWARE. + +if not arg[3] then + print("usage: lua remote_lat.lua []") + os.exit() +end + +local connect_to = arg[1] +local message_size = tonumber(arg[2]) +local roundtrip_count = tonumber(arg[3]) +local mod = arg[4] or "zmq" +if mod == 'disable_ffi' then + disable_ffi = true + mod = 'zmq' +end + +local zmq = require(mod) + +local socket = require"socket" +local time = socket.gettime + +local ctx = zmq.init(1) +local s = ctx:socket(zmq.REQ) +s:connect(connect_to) + +local msg = ("0"):rep(message_size) + +local start_time = time() + +for i = 1, roundtrip_count do + s:send(msg) + msg = s:recv() + assert(#msg == message_size, "Invalid message size") +end + +local end_time = time() + +s:close() +ctx:term() + +local elapsed = end_time - start_time +local latency = elapsed * 1000000 / roundtrip_count / 2 + +print(string.format("message size: %i [B]", message_size)) +print(string.format("roundtrip count: %i", roundtrip_count)) +print(string.format("mean latency: %.3f [us]", latency)) diff --git a/perf/no_msg/remote_thr.lua b/perf/no_msg/remote_thr.lua new file mode 100644 index 0000000..97fbd1f --- /dev/null +++ b/perf/no_msg/remote_thr.lua @@ -0,0 +1,50 @@ +-- Copyright (c) 2010 Aleksey Yeschenko +-- +-- Permission is hereby granted, free of charge, to any person obtaining a copy +-- of this software and associated documentation files (the "Software"), to deal +-- in the Software without restriction, including without limitation the rights +-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +-- copies of the Software, and to permit persons to whom the Software is +-- furnished to do so, subject to the following conditions: +-- +-- The above copyright notice and this permission notice shall be included in +-- all copies or substantial portions of the Software. +-- +-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +-- THE SOFTWARE. + +if not arg[3] then + print("usage: lua remote_thr.lua []") + os.exit() +end + +local connect_to = arg[1] +local message_size = tonumber(arg[2]) +local message_count = tonumber(arg[3]) +local mod = arg[4] or "zmq" +if mod == 'disable_ffi' then + disable_ffi = true + mod = 'zmq' +end + +local zmq = require(mod) + +local ctx = zmq.init(1) +local s = ctx:socket(zmq.PUB) +s:connect(connect_to) + +local msg = ("0"):rep(message_size) + +for i = 1, message_count do + s:send(msg) +end + +--os.execute("sleep " .. 10) + +s:close() +ctx:term() diff --git a/zmq.nobj.lua b/zmq.nobj.lua index 575a52f..c5923ae 100644 --- a/zmq.nobj.lua +++ b/zmq.nobj.lua @@ -56,60 +56,60 @@ end -- Module constants -- constants { -MAX_VSM_SIZE = 30, +MAX_VSM_SIZE = 30, -- message types -DELIMITER = 31, -VSM = 32, +DELIMITER = 31, +VSM = 32, -- message flags -MSG_MORE = 1, -MSG_SHARED = 128, +MSG_MORE = 1, +MSG_SHARED = 128, -- socket types -PAIR = 0, -PUB = 1, -SUB = 2, -REQ = 3, -REP = 4, -XREQ = 5, -XREP = 6, -PULL = 7, -PUSH = 8, +PAIR = 0, +PUB = 1, +SUB = 2, +REQ = 3, +REP = 4, +XREQ = 5, +XREP = 6, +PULL = 7, +PUSH = 8, -- socket options -HWM = 1, -SWAP = 3, -AFFINITY = 4, -IDENTITY = 5, -SUBSCRIBE = 6, -UNSUBSCRIBE = 7, -RATE = 8, -RECOVERY_IVL = 9, -MCAST_LOOP = 10, -SNDBUF = 11, -RCVBUF = 12, -RCVMORE = 13, -FD = 14, -EVENTS = 15, -TYPE = 16, -LINGER = 17, -RECONNECT_IVL = 18, -BACKLOG = 19, +HWM = 1, +SWAP = 3, +AFFINITY = 4, +IDENTITY = 5, +SUBSCRIBE = 6, +UNSUBSCRIBE = 7, +RATE = 8, +RECOVERY_IVL = 9, +MCAST_LOOP = 10, +SNDBUF = 11, +RCVBUF = 12, +RCVMORE = 13, +FD = 14, +EVENTS = 15, +TYPE = 16, +LINGER = 17, +RECONNECT_IVL = 18, +BACKLOG = 19, -- send/recv flags -NOBLOCK = 1, -SNDMORE = 2, +NOBLOCK = 1, +SNDMORE = 2, -- poll events -POLLIN = 1, -POLLOUT = 2, -POLLERR = 4, +POLLIN = 1, +POLLOUT = 2, +POLLERR = 4, -- devices -STREAMER = 1, -FORWARDER = 2, -QUEUE = 3, +STREAMER = 1, +FORWARDER = 2, +QUEUE = 3, },