protobuf 2.6.6 → 2.7.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/rpc_server +0 -1
- data/lib/protobuf/rpc/connectors/socket.rb +0 -2
- data/lib/protobuf/rpc/servers/zmq/broker.rb +44 -19
- data/lib/protobuf/rpc/servers/zmq/util.rb +2 -0
- data/lib/protobuf/rpc/servers/zmq/worker.rb +17 -4
- data/lib/protobuf/version.rb +1 -1
- data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +7 -16
- metadata +31 -34
data/bin/rpc_server
CHANGED
@@ -6,29 +6,38 @@ module Protobuf
|
|
6
6
|
module Zmq
|
7
7
|
class Broker
|
8
8
|
include ::Protobuf::Rpc::Zmq::Util
|
9
|
-
attr_reader :frontend, :backend, :poller, :context
|
9
|
+
attr_reader :frontend, :backend, :poller, :context, :available_workers
|
10
10
|
|
11
11
|
##
|
12
12
|
# Constructor
|
13
13
|
#
|
14
14
|
def initialize(options = {})
|
15
|
+
@available_workers = []
|
15
16
|
@context = ::ZMQ::Context.new
|
16
17
|
@frontend = setup_frontend(options)
|
17
18
|
@backend = setup_backend(options)
|
18
|
-
@poller =
|
19
|
+
@poller = ::ZMQ::Poller.new
|
20
|
+
@poller.register(frontend, ::ZMQ::POLLIN)
|
21
|
+
@poller.register(backend, ::ZMQ::POLLIN)
|
19
22
|
end
|
20
23
|
|
21
24
|
##
|
22
25
|
# Instance Methods
|
23
26
|
#
|
24
27
|
def poll
|
28
|
+
if available_workers.size > 0
|
29
|
+
poller.register(frontend, ::ZMQ::POLLIN) if poller.size < 2
|
30
|
+
else
|
31
|
+
poller.delete(frontend)
|
32
|
+
end
|
33
|
+
|
25
34
|
poller.poll(1000)
|
26
35
|
poller.readables.each do |socket|
|
27
36
|
case socket
|
28
37
|
when frontend then
|
29
|
-
|
38
|
+
move_to_backend(socket)
|
30
39
|
when backend then
|
31
|
-
|
40
|
+
move_to_frontend(socket)
|
32
41
|
end
|
33
42
|
end
|
34
43
|
end
|
@@ -41,14 +50,37 @@ module Protobuf
|
|
41
50
|
|
42
51
|
private
|
43
52
|
|
44
|
-
def
|
45
|
-
|
53
|
+
def move_to_backend(socket)
|
54
|
+
message_array = []
|
55
|
+
zmq_error_check(socket.recv_strings(message_array))
|
56
|
+
|
57
|
+
backend_message_set = [
|
58
|
+
available_workers.shift, # Worker UUID for router
|
59
|
+
"",
|
60
|
+
message_array[0], # Client UUID for return value
|
61
|
+
"",
|
62
|
+
message_array[2] # Client Message payload (request)
|
63
|
+
]
|
64
|
+
|
65
|
+
zmq_error_check(backend.send_strings(backend_message_set))
|
66
|
+
end
|
67
|
+
|
68
|
+
def move_to_frontend(socket)
|
69
|
+
message_array = []
|
70
|
+
zmq_error_check(socket.recv_strings(message_array))
|
71
|
+
|
72
|
+
# Push UUID of socket on the available workers queue
|
73
|
+
available_workers << message_array[0]
|
74
|
+
|
75
|
+
# messages should be [ "uuid of socket", "", "READY_MESSAGE || uuid of client socket"]
|
76
|
+
unless message_array[2] == ::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE
|
77
|
+
frontend_message_set = [
|
78
|
+
message_array[2], # client UUID
|
79
|
+
"",
|
80
|
+
message_array[4] # Reply payload
|
81
|
+
]
|
46
82
|
|
47
|
-
|
48
|
-
socket.recv_string(data = "")
|
49
|
-
more_data = socket.more_parts?
|
50
|
-
more_data_flag = (more_data ? ::ZMQ::SNDMORE : 0)
|
51
|
-
frontend_or_backend.send_string(data, more_data_flag)
|
83
|
+
zmq_error_check(frontend.send_strings(frontend_message_set))
|
52
84
|
end
|
53
85
|
end
|
54
86
|
|
@@ -57,7 +89,7 @@ module Protobuf
|
|
57
89
|
host = dealer_options[:host]
|
58
90
|
port = dealer_options[:port]
|
59
91
|
|
60
|
-
zmq_backend = context.socket(::ZMQ::
|
92
|
+
zmq_backend = context.socket(::ZMQ::ROUTER)
|
61
93
|
zmq_error_check(zmq_backend.bind(bind_address(host, port)))
|
62
94
|
zmq_backend
|
63
95
|
end
|
@@ -74,13 +106,6 @@ module Protobuf
|
|
74
106
|
def bind_address(host, port)
|
75
107
|
"tcp://#{resolve_ip(host)}:#{port}"
|
76
108
|
end
|
77
|
-
|
78
|
-
def setup_poller
|
79
|
-
zmq_poller = ::ZMQ::Poller.new
|
80
|
-
zmq_poller.register(frontend, ::ZMQ::POLLIN)
|
81
|
-
zmq_poller.register(backend, ::ZMQ::POLLIN)
|
82
|
-
zmq_poller
|
83
|
-
end
|
84
109
|
end
|
85
110
|
end
|
86
111
|
end
|
@@ -16,19 +16,25 @@ module Protobuf
|
|
16
16
|
port = options[:port]
|
17
17
|
|
18
18
|
@zmq_context = ::ZMQ::Context.new
|
19
|
-
@socket = @zmq_context.socket(::ZMQ::
|
19
|
+
@socket = @zmq_context.socket(::ZMQ::REQ)
|
20
20
|
zmq_error_check(@socket.connect("tcp://#{resolve_ip(host)}:#{port}"))
|
21
21
|
|
22
22
|
@poller = ::ZMQ::Poller.new
|
23
23
|
@poller.register(@socket, ::ZMQ::POLLIN)
|
24
|
+
|
25
|
+
# Send request to broker telling it we are ready
|
26
|
+
zmq_error_check(@socket.send_string(::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE))
|
24
27
|
end
|
25
28
|
|
26
29
|
##
|
27
30
|
# Instance Methods
|
28
31
|
#
|
29
32
|
def handle_request(socket)
|
30
|
-
|
31
|
-
zmq_error_check(socket.
|
33
|
+
message_array = []
|
34
|
+
zmq_error_check(socket.recv_strings(message_array))
|
35
|
+
|
36
|
+
@request_data = message_array[2]
|
37
|
+
@client_address = message_array[0]
|
32
38
|
log_debug { sign_message("handling request") } unless @request_data.nil?
|
33
39
|
end
|
34
40
|
|
@@ -50,8 +56,15 @@ module Protobuf
|
|
50
56
|
|
51
57
|
def send_data
|
52
58
|
response_data = @response.to_s # to_s is aliases as serialize_to_string in Message
|
59
|
+
|
60
|
+
response_message_set = [
|
61
|
+
@client_address, # client uuid address
|
62
|
+
"",
|
63
|
+
response_data
|
64
|
+
]
|
65
|
+
|
53
66
|
@stats.response_size = response_data.size
|
54
|
-
zmq_error_check(@socket.
|
67
|
+
zmq_error_check(@socket.send_strings(response_message_set))
|
55
68
|
end
|
56
69
|
end
|
57
70
|
|
data/lib/protobuf/version.rb
CHANGED
@@ -3,29 +3,20 @@ require 'spec_helper'
|
|
3
3
|
describe ::Protobuf::Rpc::Zmq::Worker do
|
4
4
|
before(:each) do
|
5
5
|
load 'protobuf/zmq.rb'
|
6
|
-
end
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
fake_socket = double
|
8
|
+
fake_socket.should_receive(:connect).and_return(0)
|
9
|
+
fake_socket.should_receive(:send_string).and_return(0)
|
10
|
+
|
11
|
+
fake_context = double
|
12
|
+
fake_context.should_receive(:socket).and_return( fake_socket )
|
13
|
+
::ZMQ::Context.should_receive(:new).and_return( fake_context )
|
11
14
|
end
|
12
15
|
|
13
16
|
subject do
|
14
17
|
described_class.new({ :host => '127.0.0.1', :port => 9400 })
|
15
18
|
end
|
16
19
|
|
17
|
-
it 'sets the context' do
|
18
|
-
subject.instance_variable_get(:@zmq_context).should be_a(::ZMQ::Context)
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'sets the poller' do
|
22
|
-
subject.instance_variable_get(:@socket).should be_a(::ZMQ::Socket)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'sets the socket' do
|
26
|
-
subject.instance_variable_get(:@poller).should be_a(::ZMQ::Poller)
|
27
|
-
end
|
28
|
-
|
29
20
|
describe '#run' do
|
30
21
|
# not tested via unit tests
|
31
22
|
end
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protobuf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
5
|
-
prerelease:
|
4
|
+
version: 2.7.0.rc1
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- BJ Neilsen
|
@@ -14,7 +14,7 @@ date: 2013-02-18 00:00:00.000000000Z
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
17
|
-
requirement: &
|
17
|
+
requirement: &2152109900 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2152109900
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: ffi
|
28
|
-
requirement: &
|
28
|
+
requirement: &2152108140 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2152108140
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: multi_json
|
39
|
-
requirement: &
|
39
|
+
requirement: &2152105160 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2152105160
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: thor
|
50
|
-
requirement: &
|
50
|
+
requirement: &2152103640 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :runtime
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *2152103640
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: eventmachine
|
61
|
-
requirement: &
|
61
|
+
requirement: &2152102200 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *2152102200
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: ffi-rzmq
|
72
|
-
requirement: &
|
72
|
+
requirement: &2152100700 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,10 +77,10 @@ dependencies:
|
|
77
77
|
version: '0'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *2152100700
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: pry
|
83
|
-
requirement: &
|
83
|
+
requirement: &2152098560 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - ! '>='
|
@@ -88,10 +88,10 @@ dependencies:
|
|
88
88
|
version: '0'
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *2152098560
|
92
92
|
- !ruby/object:Gem::Dependency
|
93
93
|
name: pry-nav
|
94
|
-
requirement: &
|
94
|
+
requirement: &2152096300 !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|
97
97
|
- - ! '>='
|
@@ -99,10 +99,10 @@ dependencies:
|
|
99
99
|
version: '0'
|
100
100
|
type: :development
|
101
101
|
prerelease: false
|
102
|
-
version_requirements: *
|
102
|
+
version_requirements: *2152096300
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: rake
|
105
|
-
requirement: &
|
105
|
+
requirement: &2152094600 !ruby/object:Gem::Requirement
|
106
106
|
none: false
|
107
107
|
requirements:
|
108
108
|
- - ! '>='
|
@@ -110,10 +110,10 @@ dependencies:
|
|
110
110
|
version: '0'
|
111
111
|
type: :development
|
112
112
|
prerelease: false
|
113
|
-
version_requirements: *
|
113
|
+
version_requirements: *2152094600
|
114
114
|
- !ruby/object:Gem::Dependency
|
115
115
|
name: rake-compiler
|
116
|
-
requirement: &
|
116
|
+
requirement: &2152092960 !ruby/object:Gem::Requirement
|
117
117
|
none: false
|
118
118
|
requirements:
|
119
119
|
- - ! '>='
|
@@ -121,10 +121,10 @@ dependencies:
|
|
121
121
|
version: '0'
|
122
122
|
type: :development
|
123
123
|
prerelease: false
|
124
|
-
version_requirements: *
|
124
|
+
version_requirements: *2152092960
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: rspec
|
127
|
-
requirement: &
|
127
|
+
requirement: &2152091080 !ruby/object:Gem::Requirement
|
128
128
|
none: false
|
129
129
|
requirements:
|
130
130
|
- - ! '>='
|
@@ -132,10 +132,10 @@ dependencies:
|
|
132
132
|
version: '0'
|
133
133
|
type: :development
|
134
134
|
prerelease: false
|
135
|
-
version_requirements: *
|
135
|
+
version_requirements: *2152091080
|
136
136
|
- !ruby/object:Gem::Dependency
|
137
137
|
name: simplecov
|
138
|
-
requirement: &
|
138
|
+
requirement: &2152089300 !ruby/object:Gem::Requirement
|
139
139
|
none: false
|
140
140
|
requirements:
|
141
141
|
- - ! '>='
|
@@ -143,10 +143,10 @@ dependencies:
|
|
143
143
|
version: '0'
|
144
144
|
type: :development
|
145
145
|
prerelease: false
|
146
|
-
version_requirements: *
|
146
|
+
version_requirements: *2152089300
|
147
147
|
- !ruby/object:Gem::Dependency
|
148
148
|
name: yard
|
149
|
-
requirement: &
|
149
|
+
requirement: &2152086200 !ruby/object:Gem::Requirement
|
150
150
|
none: false
|
151
151
|
requirements:
|
152
152
|
- - ! '>='
|
@@ -154,7 +154,7 @@ dependencies:
|
|
154
154
|
version: '0'
|
155
155
|
type: :development
|
156
156
|
prerelease: false
|
157
|
-
version_requirements: *
|
157
|
+
version_requirements: *2152086200
|
158
158
|
description: Google Protocol Buffers v2.4.1 Serialization and RPC implementation for
|
159
159
|
Ruby.
|
160
160
|
email:
|
@@ -434,16 +434,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
434
434
|
version: '0'
|
435
435
|
segments:
|
436
436
|
- 0
|
437
|
-
hash: -
|
437
|
+
hash: -4047099563380009379
|
438
438
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
439
439
|
none: false
|
440
440
|
requirements:
|
441
|
-
- - ! '
|
441
|
+
- - ! '>'
|
442
442
|
- !ruby/object:Gem::Version
|
443
|
-
version:
|
444
|
-
segments:
|
445
|
-
- 0
|
446
|
-
hash: -4295653225771517786
|
443
|
+
version: 1.3.1
|
447
444
|
requirements: []
|
448
445
|
rubyforge_project:
|
449
446
|
rubygems_version: 1.8.15
|