ffi-rzmq 0.8.2 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS.txt +1 -0
- data/History.txt +35 -0
- data/README.rdoc +48 -15
- data/Rakefile +7 -2
- data/examples/README.rdoc +21 -76
- data/examples/{local_lat.rb → v2api/local_lat.rb} +27 -12
- data/examples/v2api/local_lat_poll.rb +66 -0
- data/examples/{local_throughput.rb → v2api/local_throughput.rb} +24 -9
- data/examples/v2api/publish_subscribe.rb +82 -0
- data/examples/{remote_lat.rb → v2api/remote_lat.rb} +26 -8
- data/examples/v2api/remote_throughput.rb +39 -0
- data/examples/v2api/reqrep_poll.rb +62 -0
- data/examples/v2api/request_response.rb +40 -0
- data/examples/v2api/throughput_measurement.rb +138 -0
- data/examples/v3api/local_lat.rb +59 -0
- data/examples/v3api/local_lat_poll.rb +66 -0
- data/examples/v3api/local_throughput.rb +65 -0
- data/examples/v3api/publish_subscribe.rb +82 -0
- data/examples/v3api/remote_lat.rb +71 -0
- data/examples/v3api/remote_throughput.rb +47 -0
- data/examples/v3api/reqrep_poll.rb +62 -0
- data/examples/v3api/request_response.rb +40 -0
- data/examples/v3api/throughput_measurement.rb +166 -0
- data/ext/README +5 -0
- data/ffi-rzmq.gemspec +4 -4
- data/lib/ffi-rzmq.rb +4 -1
- data/lib/ffi-rzmq/constants.rb +178 -0
- data/lib/ffi-rzmq/context.rb +61 -45
- data/lib/ffi-rzmq/device.rb +22 -9
- data/lib/ffi-rzmq/exceptions.rb +0 -98
- data/lib/ffi-rzmq/libc.rb +19 -0
- data/lib/ffi-rzmq/libzmq.rb +188 -0
- data/lib/ffi-rzmq/message.rb +33 -40
- data/lib/ffi-rzmq/poll.rb +49 -52
- data/lib/ffi-rzmq/socket.rb +902 -392
- data/lib/ffi-rzmq/util.rb +101 -0
- data/spec/context_spec.rb +47 -21
- data/spec/device_spec.rb +78 -58
- data/spec/message_spec.rb +90 -12
- data/spec/multipart_spec.rb +162 -0
- data/spec/nonblocking_recv_spec.rb +325 -0
- data/spec/pushpull_spec.rb +95 -34
- data/spec/reqrep_spec.rb +55 -20
- data/spec/socket_spec.rb +353 -204
- data/spec/spec_helper.rb +46 -3
- data/version.txt +1 -1
- metadata +91 -66
- data/examples/local_lat_poll.rb +0 -54
- data/examples/local_lat_zerocopy.rb +0 -24
- data/examples/publish_subscribe.rb +0 -52
- data/examples/remote_lat_zerocopy.rb +0 -35
- data/examples/remote_throughput.rb +0 -27
- data/examples/reqrep_poll.rb +0 -49
- data/examples/request_response.rb +0 -23
- data/lib/ffi-rzmq/wrapper.rb +0 -121
- data/lib/ffi-rzmq/zmq.rb +0 -198
data/spec/spec_helper.rb
CHANGED
@@ -7,11 +7,24 @@ File.join(File.dirname(__FILE__), %w[.. lib ffi-rzmq]))
|
|
7
7
|
|
8
8
|
Thread.abort_on_exception = true
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
# define some version guards so we can turn on/off specs based upon
|
11
|
+
# the version of the 0mq library that is loaded
|
12
|
+
def version2?
|
13
|
+
LibZMQ.version2?
|
13
14
|
end
|
14
15
|
|
16
|
+
def version3?
|
17
|
+
LibZMQ.version3?
|
18
|
+
end
|
19
|
+
|
20
|
+
def version4?
|
21
|
+
LibZMQ.version4?
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
NonBlockingFlag = (LibZMQ.version2? ? ZMQ::NOBLOCK : ZMQ::DONTWAIT) unless defined?(NonBlockingFlag)
|
26
|
+
|
27
|
+
|
15
28
|
module APIHelper
|
16
29
|
def stub_libzmq
|
17
30
|
@err_str_mock = mock("error string")
|
@@ -27,4 +40,34 @@ module APIHelper
|
|
27
40
|
def random_port
|
28
41
|
rand(55534) + 10_000
|
29
42
|
end
|
43
|
+
|
44
|
+
def bind_to_random_tcp_port socket, max_tries = 500
|
45
|
+
tries = 0
|
46
|
+
rc = -1
|
47
|
+
|
48
|
+
while !ZMQ::Util.resultcode_ok?(rc) && tries < max_tries
|
49
|
+
tries += 1
|
50
|
+
random = random_port
|
51
|
+
rc = socket.bind "tcp://127.0.0.1:#{random}"
|
52
|
+
end
|
53
|
+
|
54
|
+
random
|
55
|
+
end
|
56
|
+
|
57
|
+
def connect_to_random_tcp_port socket, max_tries = 500
|
58
|
+
tries = 0
|
59
|
+
rc = -1
|
60
|
+
|
61
|
+
while !ZMQ::Util.resultcode_ok?(rc) && tries < max_tries
|
62
|
+
tries += 1
|
63
|
+
random = random_port
|
64
|
+
rc = socket.connect "tcp://127.0.0.1:#{random}"
|
65
|
+
end
|
66
|
+
|
67
|
+
random
|
68
|
+
end
|
69
|
+
|
70
|
+
def assert_ok(rc)
|
71
|
+
raise "Failed with rc [#{rc}] and errno [#{ZMQ::Util.errno}], msg [#{ZMQ::Util.error_string}]! #{caller(0)}" unless rc >= 0
|
72
|
+
end
|
30
73
|
end
|
data/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.9.0
|
metadata
CHANGED
@@ -1,29 +1,37 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffi-rzmq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 9
|
8
|
+
- 0
|
9
|
+
version: 0.9.0
|
6
10
|
platform: ruby
|
7
11
|
authors:
|
8
|
-
|
12
|
+
- Chuck Remes
|
9
13
|
autorequire:
|
10
14
|
bindir: bin
|
11
15
|
cert_chain: []
|
12
16
|
|
13
|
-
date: 2011-
|
17
|
+
date: 2011-09-14 00:00:00 -05:00
|
14
18
|
default_executable:
|
15
19
|
dependencies:
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: bones
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 3
|
30
|
+
- 5
|
31
|
+
- 4
|
32
|
+
version: 3.5.4
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
27
35
|
description: |-
|
28
36
|
This gem wraps the ZeroMQ networking library using the ruby FFI (foreign
|
29
37
|
function interface). It's a pure ruby wrapper so this gem can be loaded
|
@@ -35,75 +43,92 @@ executables: []
|
|
35
43
|
extensions: []
|
36
44
|
|
37
45
|
extra_rdoc_files:
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
46
|
+
- AUTHORS.txt
|
47
|
+
- History.txt
|
48
|
+
- README.rdoc
|
49
|
+
- examples/README.rdoc
|
50
|
+
- version.txt
|
43
51
|
files:
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
52
|
+
- .bnsignore
|
53
|
+
- History.txt
|
54
|
+
- README.rdoc
|
55
|
+
- Rakefile
|
56
|
+
- examples/README.rdoc
|
57
|
+
- examples/v2api/local_lat.rb
|
58
|
+
- examples/v2api/local_lat_poll.rb
|
59
|
+
- examples/v2api/local_throughput.rb
|
60
|
+
- examples/v2api/publish_subscribe.rb
|
61
|
+
- examples/v2api/remote_lat.rb
|
62
|
+
- examples/v2api/remote_throughput.rb
|
63
|
+
- examples/v2api/reqrep_poll.rb
|
64
|
+
- examples/v2api/request_response.rb
|
65
|
+
- examples/v2api/throughput_measurement.rb
|
66
|
+
- examples/v3api/local_lat.rb
|
67
|
+
- examples/v3api/local_lat_poll.rb
|
68
|
+
- examples/v3api/local_throughput.rb
|
69
|
+
- examples/v3api/publish_subscribe.rb
|
70
|
+
- examples/v3api/remote_lat.rb
|
71
|
+
- examples/v3api/remote_throughput.rb
|
72
|
+
- examples/v3api/reqrep_poll.rb
|
73
|
+
- examples/v3api/request_response.rb
|
74
|
+
- examples/v3api/throughput_measurement.rb
|
75
|
+
- ext/README
|
76
|
+
- ffi-rzmq.gemspec
|
77
|
+
- lib/ffi-rzmq.rb
|
78
|
+
- lib/ffi-rzmq/constants.rb
|
79
|
+
- lib/ffi-rzmq/context.rb
|
80
|
+
- lib/ffi-rzmq/device.rb
|
81
|
+
- lib/ffi-rzmq/exceptions.rb
|
82
|
+
- lib/ffi-rzmq/libc.rb
|
83
|
+
- lib/ffi-rzmq/libzmq.rb
|
84
|
+
- lib/ffi-rzmq/message.rb
|
85
|
+
- lib/ffi-rzmq/poll.rb
|
86
|
+
- lib/ffi-rzmq/poll_items.rb
|
87
|
+
- lib/ffi-rzmq/socket.rb
|
88
|
+
- lib/ffi-rzmq/util.rb
|
89
|
+
- spec/context_spec.rb
|
90
|
+
- spec/device_spec.rb
|
91
|
+
- spec/message_spec.rb
|
92
|
+
- spec/multipart_spec.rb
|
93
|
+
- spec/nonblocking_recv_spec.rb
|
94
|
+
- spec/pushpull_spec.rb
|
95
|
+
- spec/reqrep_spec.rb
|
96
|
+
- spec/socket_spec.rb
|
97
|
+
- spec/spec_helper.rb
|
98
|
+
- version.txt
|
99
|
+
- AUTHORS.txt
|
79
100
|
has_rdoc: true
|
80
101
|
homepage: http://github.com/chuckremes/ffi-rzmq
|
81
102
|
licenses: []
|
82
103
|
|
83
104
|
post_install_message:
|
84
105
|
rdoc_options:
|
85
|
-
|
86
|
-
|
106
|
+
- --main
|
107
|
+
- README.rdoc
|
87
108
|
require_paths:
|
88
|
-
|
109
|
+
- lib
|
89
110
|
required_ruby_version: !ruby/object:Gem::Requirement
|
90
111
|
none: false
|
91
112
|
requirements:
|
92
|
-
|
93
|
-
|
94
|
-
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
version: "0"
|
95
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
119
|
none: false
|
97
120
|
requirements:
|
98
|
-
|
99
|
-
|
100
|
-
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
segments:
|
124
|
+
- 0
|
125
|
+
version: "0"
|
101
126
|
requirements: []
|
102
127
|
|
103
128
|
rubyforge_project: ffi-rzmq
|
104
|
-
rubygems_version: 1.
|
129
|
+
rubygems_version: 1.3.7
|
105
130
|
signing_key:
|
106
131
|
specification_version: 3
|
107
|
-
summary: This gem wraps the ZeroMQ networking library using
|
132
|
+
summary: This gem wraps the ZeroMQ (0mq) networking library using Ruby FFI (foreign function interface).
|
108
133
|
test_files: []
|
109
134
|
|
data/examples/local_lat_poll.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'ffi-rzmq'
|
3
|
-
|
4
|
-
if ARGV.length < 3
|
5
|
-
puts "usage: local_lat <connect-to> <message-size> <roundtrip-count>"
|
6
|
-
exit
|
7
|
-
end
|
8
|
-
|
9
|
-
link = ARGV[0]
|
10
|
-
message_size = ARGV[1].to_i
|
11
|
-
roundtrip_count = ARGV[2].to_i
|
12
|
-
|
13
|
-
#link = "tcp://127.0.0.1:5555"
|
14
|
-
|
15
|
-
ctx = ZMQ::Context.new
|
16
|
-
s1 = ctx.socket ZMQ::REQ
|
17
|
-
s2 = ctx.socket ZMQ::REP
|
18
|
-
|
19
|
-
s1.connect link
|
20
|
-
s2.bind link
|
21
|
-
|
22
|
-
poller = ZMQ::Poller.new
|
23
|
-
poller.register_readable s2
|
24
|
-
poller.register_readable s1
|
25
|
-
|
26
|
-
|
27
|
-
start_time = Time.now
|
28
|
-
|
29
|
-
# kick it off
|
30
|
-
message = ZMQ::Message.new("a" * message_size)
|
31
|
-
s1.send message, ZMQ::NOBLOCK
|
32
|
-
i = roundtrip_count
|
33
|
-
|
34
|
-
until i.zero?
|
35
|
-
i -= 1
|
36
|
-
|
37
|
-
begin
|
38
|
-
poller.poll_nonblock
|
39
|
-
rescue ZMQ::PollError => e
|
40
|
-
puts "efault? [#{e.efault?}]"
|
41
|
-
raise
|
42
|
-
end
|
43
|
-
|
44
|
-
poller.readables.each do |socket|
|
45
|
-
received_message = socket.recv_string ZMQ::NOBLOCK
|
46
|
-
socket.send ZMQ::Message.new(received_message), ZMQ::NOBLOCK
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
elapsed_usecs = (Time.now.to_f - start_time.to_f) * 1_000_000
|
51
|
-
latency = elapsed_usecs / roundtrip_count / 2
|
52
|
-
|
53
|
-
puts "mean latency: %.3f [us]" % latency
|
54
|
-
puts "received all messages in %.3f seconds" % (elapsed_usecs / 1_000_000)
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'ffi-rzmq'
|
3
|
-
|
4
|
-
if ARGV.length < 3
|
5
|
-
puts "usage: local_lat <connect-to> <message-size> <roundtrip-count>"
|
6
|
-
exit
|
7
|
-
end
|
8
|
-
|
9
|
-
bind_to = ARGV[0]
|
10
|
-
message_size = ARGV[1].to_i
|
11
|
-
roundtrip_count = ARGV[2].to_i
|
12
|
-
|
13
|
-
ctx = ZMQ::Context.new 1
|
14
|
-
s = ZMQ::Socket.new ctx.context, ZMQ::REP
|
15
|
-
s.setsockopt ZMQ::HWM, 100
|
16
|
-
s.bind bind_to
|
17
|
-
|
18
|
-
msg = ZMQ::Message.new
|
19
|
-
|
20
|
-
roundtrip_count.times do
|
21
|
-
result = s.recv msg, 0
|
22
|
-
raise "Message size doesn't match, expected [#{message_size}] but received [#{msg.size}]" if message_size != msg.size
|
23
|
-
s.send msg, 0
|
24
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'ffi-rzmq'
|
3
|
-
|
4
|
-
|
5
|
-
link = "tcp://127.0.0.1:5555"
|
6
|
-
|
7
|
-
ctx = ZMQ::Context.new 1
|
8
|
-
s1 = ctx.socket ZMQ::PUB
|
9
|
-
s2 = ctx.socket ZMQ::SUB
|
10
|
-
s3 = ctx.socket ZMQ::SUB
|
11
|
-
s4 = ctx.socket ZMQ::SUB
|
12
|
-
s5 = ctx.socket ZMQ::SUB
|
13
|
-
|
14
|
-
s2.setsockopt ZMQ::SUBSCRIBE, '' # receive all
|
15
|
-
s3.setsockopt ZMQ::SUBSCRIBE, 'animals' # receive any starting with this string
|
16
|
-
s4.setsockopt ZMQ::SUBSCRIBE, 'animals.dog'
|
17
|
-
s5.setsockopt ZMQ::SUBSCRIBE, 'animals.cat'
|
18
|
-
|
19
|
-
s1.bind link
|
20
|
-
s2.connect link
|
21
|
-
s3.connect link
|
22
|
-
s4.connect link
|
23
|
-
s5.connect link
|
24
|
-
|
25
|
-
sleep 1
|
26
|
-
|
27
|
-
topic = "animals.dog"
|
28
|
-
payload = "Animal crackers!"
|
29
|
-
|
30
|
-
s1.identity = "publisher-A"
|
31
|
-
puts "sending"
|
32
|
-
# use the new multi-part messaging support to
|
33
|
-
# automatically separate the topic from the body
|
34
|
-
s1.send_string topic, ZMQ::SNDMORE
|
35
|
-
s1.send_string payload, ZMQ::SNDMORE
|
36
|
-
s1.send_string s1.identity
|
37
|
-
|
38
|
-
topic = s2.recv_string
|
39
|
-
body = s2.recv_string if s2.more_parts?
|
40
|
-
identity = s2.recv_string if s2.more_parts?
|
41
|
-
puts "s2 received topic [#{topic}], body [#{body}], identity [#{identity}]"
|
42
|
-
|
43
|
-
topic = s3.recv_string
|
44
|
-
body = s3.recv_string if s3.more_parts?
|
45
|
-
puts "s3 received topic [#{topic}], body [#{body}]"
|
46
|
-
|
47
|
-
topic = s4.recv_string
|
48
|
-
body = s4.recv_string if s4.more_parts?
|
49
|
-
puts "s4 received topic [#{topic}], body [#{body}]"
|
50
|
-
|
51
|
-
s5_string = s5.recv_string ZMQ::NOBLOCK
|
52
|
-
puts(s5_string.nil? ? "s5 received no messages" : "s5 FAILED")
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'ffi-rzmq'
|
3
|
-
|
4
|
-
if ARGV.length < 3
|
5
|
-
puts "usage: remote_lat <connect-to> <message-size> <roundtrip-count>"
|
6
|
-
exit
|
7
|
-
end
|
8
|
-
|
9
|
-
connect_to = ARGV[0]
|
10
|
-
message_size = ARGV[1].to_i
|
11
|
-
roundtrip_count = ARGV[2].to_i
|
12
|
-
|
13
|
-
ctx = ZMQ::Context.new 1
|
14
|
-
s = ctx.socket ZMQ::REQ
|
15
|
-
s.connect connect_to
|
16
|
-
|
17
|
-
msg = ZMQ::Message.new "#{'3'*message_size}"
|
18
|
-
|
19
|
-
start_time = Time.now
|
20
|
-
|
21
|
-
roundtrip_count.times do
|
22
|
-
s.send msg, 0
|
23
|
-
result = s.recv msg, 0
|
24
|
-
raise "Message size doesn't match, expected [#{message_size}] but received [#{msg.size}]" if message_size != msg.size
|
25
|
-
end
|
26
|
-
|
27
|
-
end_time = Time.now
|
28
|
-
elapsed_secs = (end_time.to_f - start_time.to_f)
|
29
|
-
elapsed_usecs = elapsed_secs * 1000000
|
30
|
-
latency = elapsed_usecs / roundtrip_count / 2
|
31
|
-
|
32
|
-
puts "message size: %i [B]" % message_size
|
33
|
-
puts "roundtrip count: %i" % roundtrip_count
|
34
|
-
puts "throughput (msgs/s): %i" % (roundtrip_count / elapsed_secs)
|
35
|
-
puts "mean latency: %.3f [us]" % latency
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'ffi-rzmq'
|
3
|
-
|
4
|
-
if ARGV.length != 3
|
5
|
-
puts "usage: remote_thr <connect-to> <message-size> <message-count>"
|
6
|
-
Process.exit
|
7
|
-
end
|
8
|
-
|
9
|
-
connect_to = ARGV[0]
|
10
|
-
message_size = ARGV[1].to_i
|
11
|
-
message_count = ARGV[2].to_i
|
12
|
-
|
13
|
-
ctx = ZMQ::Context.new
|
14
|
-
s = ZMQ::Socket.new ctx.pointer, ZMQ::PUB
|
15
|
-
|
16
|
-
s.connect connect_to
|
17
|
-
|
18
|
-
contents = "#{'0'*message_size}"
|
19
|
-
|
20
|
-
i = 0
|
21
|
-
while i < message_count
|
22
|
-
msg = ZMQ::Message.new contents
|
23
|
-
s.send msg
|
24
|
-
i += 1
|
25
|
-
end
|
26
|
-
|
27
|
-
sleep 10
|