protobuf-nats 0.3.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +11 -5
- data/lib/protobuf/nats/server.rb +50 -15
- data/lib/protobuf/nats/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65e149ee1d61cda8f1984475564f0c38cf4b8947
|
4
|
+
data.tar.gz: 0dc0a8f81ca8b27c3e0d56ad13e2a743c20d945f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 888441cbebd59eb546e47a575bfb930a893f5749c17d41edcd9e3a47eb3a6c9f02d00638b3bd630bf9d21ce77f4cfeded33ec60bf4e7e7efc9822546a3efb298
|
7
|
+
data.tar.gz: 117a06f644f92cea8073fd53566f3274f797a391c316f68cd678eb84697134e0048bff05faebbb2100ef7291053e5d342abfcdba8c856f491410e4b8473db86d
|
data/README.md
CHANGED
@@ -25,15 +25,21 @@ Or install it yourself as:
|
|
25
25
|
|
26
26
|
You can also use the following environment variables to tune parameters:
|
27
27
|
|
28
|
-
`PB_NATS_SERVER_MAX_QUEUE_SIZE` - The size of the queue in front of your thread pool (default: thread count passed to CLI)
|
28
|
+
`PB_NATS_SERVER_MAX_QUEUE_SIZE` - The size of the queue in front of your thread pool (default: thread count passed to CLI).
|
29
29
|
|
30
|
-
`
|
30
|
+
`PB_NATS_SERVER_SLOW_START_DELAY` - Seconds to wait before adding another round of subscriptions (default 10).
|
31
31
|
|
32
|
-
`
|
32
|
+
`PB_NATS_SERVER_SUBSCRIPTIONS_PER_RPC_ENDPOINT` - Number of subscriptions to create for each rpc endpoint. This number is
|
33
|
+
used to allow JVM based servers to warm-up slowly to prevent jolts in runtime performance across your RPC network
|
34
|
+
(default: 10).
|
33
35
|
|
34
|
-
`
|
36
|
+
`PB_NATS_CLIENT_ACK_TIMEOUT` - Seconds to wait for an ACK from the rpc server (default: 5 seconds).
|
35
37
|
|
36
|
-
`
|
38
|
+
`PB_NATS_CLIENT_RESPONSE_TIMEOUT` - Seconds to wait for a non-ACK response from the rpc server (default: 60 seconds).
|
39
|
+
|
40
|
+
`PB_NATS_CLIENT_RECONNECT_DELAY` - If we detect a reconnect delay, we will wait this many seconds (default: the ACK timeout).
|
41
|
+
|
42
|
+
`PROTOBUF_NATS_CONFIG_PATH` - Custom path to the config yaml (default: "config/protobuf_nats.yml").
|
37
43
|
|
38
44
|
### YAML Config
|
39
45
|
|
data/lib/protobuf/nats/server.rb
CHANGED
@@ -26,11 +26,15 @@ module Protobuf
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def max_queue_size
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
::ENV.fetch("PB_NATS_SERVER_MAX_QUEUE_SIZE", @options[:threads]).to_i
|
30
|
+
end
|
31
|
+
|
32
|
+
def slow_start_delay
|
33
|
+
@slow_start_delay ||= ::ENV.fetch("PB_NATS_SERVER_SLOW_START_DELAY", 10).to_i
|
34
|
+
end
|
35
|
+
|
36
|
+
def subscriptions_per_rpc_endpoint
|
37
|
+
@subscriptions_per_rpc_endpoint ||= ::ENV.fetch("PB_NATS_SERVER_SUBSCRIPTIONS_PER_RPC_ENDPOINT", 10).to_i
|
34
38
|
end
|
35
39
|
|
36
40
|
def service_klasses
|
@@ -55,26 +59,56 @@ module Protobuf
|
|
55
59
|
was_enqueued
|
56
60
|
end
|
57
61
|
|
58
|
-
def
|
62
|
+
def print_subscription_keys
|
59
63
|
logger.info "Creating subscriptions:"
|
60
64
|
|
65
|
+
with_each_subscription_key do |subscription_key|
|
66
|
+
logger.info " - #{subscription_key}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def subscribe_to_services
|
71
|
+
with_each_subscription_key do |subscription_key_and_queue|
|
72
|
+
subscriptions << nats.subscribe(subscription_key_and_queue, :queue => subscription_key_and_queue) do |request_data, reply_id, _subject|
|
73
|
+
unless enqueue_request(request_data, reply_id)
|
74
|
+
logger.error { "Thread pool is full! Dropping message for: #{subscription_key_and_queue}" }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def with_each_subscription_key
|
81
|
+
fail ::ArgumentError unless block_given?
|
82
|
+
|
61
83
|
service_klasses.each do |service_klass|
|
62
84
|
service_klass.rpcs.each do |service_method, _|
|
63
85
|
# Skip services that are not implemented.
|
64
86
|
next unless service_klass.method_defined? service_method
|
65
87
|
|
66
|
-
|
67
|
-
logger.info " - #{subscription_key_and_queue}"
|
68
|
-
|
69
|
-
subscriptions << nats.subscribe(subscription_key_and_queue, :queue => subscription_key_and_queue) do |request_data, reply_id, _subject|
|
70
|
-
unless enqueue_request(request_data, reply_id)
|
71
|
-
logger.error { "Thread pool is full! Dropping message for: #{subscription_key_and_queue}" }
|
72
|
-
end
|
73
|
-
end
|
88
|
+
yield ::Protobuf::Nats.subscription_key(service_klass, service_method)
|
74
89
|
end
|
75
90
|
end
|
76
91
|
end
|
77
92
|
|
93
|
+
# Slow start subscriptions by adding X rounds of subz every
|
94
|
+
# Y seconds, where X is subscriptions_per_rpc_endpoint and Y is
|
95
|
+
# slow_start_delay.
|
96
|
+
def finish_slow_start
|
97
|
+
logger.info "Slow start has started..."
|
98
|
+
completed = 1
|
99
|
+
|
100
|
+
# We have (X - 1) here because we always subscribe at least once.
|
101
|
+
(subscriptions_per_rpc_endpoint - 1).times do
|
102
|
+
next unless @running
|
103
|
+
completed += 1
|
104
|
+
sleep slow_start_delay
|
105
|
+
subscribe_to_services
|
106
|
+
logger.info "Slow start adding another round of subscriptions (#{completed}/#{subscriptions_per_rpc_endpoint})..."
|
107
|
+
end
|
108
|
+
|
109
|
+
logger.info "Slow start finished."
|
110
|
+
end
|
111
|
+
|
78
112
|
def run
|
79
113
|
nats.on_reconnect do
|
80
114
|
logger.warn "Server NATS connection was reconnected"
|
@@ -92,9 +126,10 @@ module Protobuf
|
|
92
126
|
logger.warn "Server NATS connection was closed"
|
93
127
|
end
|
94
128
|
|
129
|
+
print_subscription_keys
|
95
130
|
subscribe_to_services
|
96
|
-
|
97
131
|
yield if block_given?
|
132
|
+
finish_slow_start
|
98
133
|
|
99
134
|
loop do
|
100
135
|
break unless @running
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protobuf-nats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Dewitt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: protobuf
|
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
171
|
version: '0'
|
172
172
|
requirements: []
|
173
173
|
rubyforge_project:
|
174
|
-
rubygems_version: 2.
|
174
|
+
rubygems_version: 2.5.2
|
175
175
|
signing_key:
|
176
176
|
specification_version: 4
|
177
177
|
summary: ruby-protobuf client/server for nats
|