zeromem-ws 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +11 -11
- data/.rspec +3 -3
- data/.travis.yml +5 -5
- data/Gemfile +7 -7
- data/Gemfile.lock +54 -53
- data/LICENSE.txt +21 -21
- data/README.md +49 -49
- data/Rakefile +6 -6
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/lib/zeromem/ws.rb +85 -85
- data/lib/zeromem/ws/version.rb +5 -5
- data/ws_test.rb +0 -0
- data/zeromem-ws.gemspec +30 -30
- metadata +9 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8897043c0dd25c5c914da20de4635b21a4d83aedba92ad6fe266077de16070cd
|
4
|
+
data.tar.gz: ff4c231a094fdbdf15539212b54eca394d87fdbff5b02c9e47c35ac344793bcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7eb63a9c62dff9b5a61c9d074824ff2874b831117b0cbaf73caf6600566e09c7d9dbd6f652a67c9980eab344b0510d9f71d80c07624bb5928a04aea48ad8ff3
|
7
|
+
data.tar.gz: 25c27d8699df8373c3a72df949016de6ee857b73e00bb9281eec31259b0936464d29d0a1f3e07ee5d3aba674a8f90a8dd401b0dc963ac21029e5b32a2aacafe9
|
data/.gitignore
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/_yardoc/
|
4
|
-
/coverage/
|
5
|
-
/doc/
|
6
|
-
/pkg/
|
7
|
-
/spec/reports/
|
8
|
-
/tmp/
|
9
|
-
|
10
|
-
# rspec failure tracking
|
11
|
-
.rspec_status
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/_yardoc/
|
4
|
+
/coverage/
|
5
|
+
/doc/
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/tmp/
|
9
|
+
|
10
|
+
# rspec failure tracking
|
11
|
+
.rspec_status
|
data/.rspec
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
--format documentation
|
2
|
-
--color
|
3
|
-
--require spec_helper
|
1
|
+
--format documentation
|
2
|
+
--color
|
3
|
+
--require spec_helper
|
data/.travis.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
sudo: false
|
2
|
-
language: ruby
|
3
|
-
rvm:
|
4
|
-
- 2.4.1
|
5
|
-
before_install: gem install bundler -v 1.16.0
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
rvm:
|
4
|
+
- 2.4.1
|
5
|
+
before_install: gem install bundler -v 1.16.0
|
data/Gemfile
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
4
|
-
|
5
|
-
# Specify your gem's dependencies in zeromem-ws.gemspec
|
6
|
-
gemspec
|
7
|
-
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in zeromem-ws.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
8
|
gem "eventmachine", ">= 1.2.5"
|
data/Gemfile.lock
CHANGED
@@ -1,53 +1,54 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
zeromem-ws (0.1.
|
5
|
-
em-websocket (~> 0.5.1)
|
6
|
-
em-websocket-client (~> 0.1.2)
|
7
|
-
rjr (>= 0.19.3)
|
8
|
-
|
9
|
-
GEM
|
10
|
-
remote: https://rubygems.org/
|
11
|
-
specs:
|
12
|
-
diff-lcs (1.3)
|
13
|
-
em-websocket (0.5.
|
14
|
-
eventmachine (>= 0.12.9)
|
15
|
-
http_parser.rb (~> 0.6.0)
|
16
|
-
em-websocket-client (0.1.2)
|
17
|
-
eventmachine
|
18
|
-
websocket
|
19
|
-
eventmachine (1.2.5)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
rspec-
|
29
|
-
rspec-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
zeromem-ws (0.1.2)
|
5
|
+
em-websocket (~> 0.5.1)
|
6
|
+
em-websocket-client (~> 0.1.2)
|
7
|
+
rjr (>= 0.19.3)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
diff-lcs (1.3)
|
13
|
+
em-websocket (0.5.2)
|
14
|
+
eventmachine (>= 0.12.9)
|
15
|
+
http_parser.rb (~> 0.6.0)
|
16
|
+
em-websocket-client (0.1.2)
|
17
|
+
eventmachine
|
18
|
+
websocket
|
19
|
+
eventmachine (1.2.5)
|
20
|
+
eventmachine (1.2.5-x86-mingw32)
|
21
|
+
http_parser.rb (0.6.0)
|
22
|
+
json (2.5.1)
|
23
|
+
rake (13.0.1)
|
24
|
+
rjr (0.19.3)
|
25
|
+
eventmachine
|
26
|
+
json (>= 1.7.6)
|
27
|
+
rspec (3.7.0)
|
28
|
+
rspec-core (~> 3.7.0)
|
29
|
+
rspec-expectations (~> 3.7.0)
|
30
|
+
rspec-mocks (~> 3.7.0)
|
31
|
+
rspec-core (3.7.0)
|
32
|
+
rspec-support (~> 3.7.0)
|
33
|
+
rspec-expectations (3.7.0)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.7.0)
|
36
|
+
rspec-mocks (3.7.0)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.7.0)
|
39
|
+
rspec-support (3.7.0)
|
40
|
+
websocket (1.2.9)
|
41
|
+
|
42
|
+
PLATFORMS
|
43
|
+
ruby
|
44
|
+
x86-mingw32
|
45
|
+
|
46
|
+
DEPENDENCIES
|
47
|
+
bundler (>= 2.2.10)
|
48
|
+
eventmachine (>= 1.2.5)
|
49
|
+
rake (~> 13.0)
|
50
|
+
rspec (~> 3.0)
|
51
|
+
zeromem-ws!
|
52
|
+
|
53
|
+
BUNDLED WITH
|
54
|
+
2.2.19
|
data/LICENSE.txt
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2017 zeromem
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 zeromem
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,49 +1,49 @@
|
|
1
|
-
# Zeromem::Ws
|
2
|
-
|
3
|
-
This is implementation for movitto/rjr websocket Node for JSON-RPC to eliminate
|
4
|
-
performance degradation under heavy load (1000s queries per minute).
|
5
|
-
|
6
|
-
Current implementation has memory leak which cause CPU overhead accumulation.
|
7
|
-
|
8
|
-
|
9
|
-
## Installation
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
```ruby
|
14
|
-
gem 'zeromem-ws'
|
15
|
-
```
|
16
|
-
|
17
|
-
And then execute:
|
18
|
-
|
19
|
-
$ bundle
|
20
|
-
|
21
|
-
Or install it yourself as:
|
22
|
-
|
23
|
-
$ gem install zeromem-ws
|
24
|
-
|
25
|
-
## Usage
|
26
|
-
```ruby
|
27
|
-
require 'zeromem/ws'
|
28
|
-
|
29
|
-
server = Zeromem::Ws::WsHeavy.new :host => 'localhost', :port => 9789, :node_id => "server"
|
30
|
-
server.dispatcher.handle('method') { |i|
|
31
|
-
puts "server: #{i}"
|
32
|
-
"#{i}".upcase
|
33
|
-
}
|
34
|
-
server.listen
|
35
|
-
|
36
|
-
client = Zeromem::Ws::WsHeavy.new :node_id => "client", :timeout => 8000
|
37
|
-
|
38
|
-
0.upto(50000) { |i|
|
39
|
-
puts "#{i}"
|
40
|
-
puts client.invoke "ws://localhost:9789", "method", "Hello World"
|
41
|
-
}
|
42
|
-
```
|
43
|
-
|
44
|
-
|
45
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/zeromem88/ruby-zeromem-ws.
|
46
|
-
|
47
|
-
## License
|
48
|
-
|
49
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
1
|
+
# Zeromem::Ws
|
2
|
+
|
3
|
+
This is implementation for movitto/rjr websocket Node for JSON-RPC to eliminate
|
4
|
+
performance degradation under heavy load (1000s queries per minute).
|
5
|
+
|
6
|
+
Current implementation has memory leak which cause CPU overhead accumulation.
|
7
|
+
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'zeromem-ws'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install zeromem-ws
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
```ruby
|
27
|
+
require 'zeromem/ws'
|
28
|
+
|
29
|
+
server = Zeromem::Ws::WsHeavy.new :host => 'localhost', :port => 9789, :node_id => "server"
|
30
|
+
server.dispatcher.handle('method') { |i|
|
31
|
+
puts "server: #{i}"
|
32
|
+
"#{i}".upcase
|
33
|
+
}
|
34
|
+
server.listen
|
35
|
+
|
36
|
+
client = Zeromem::Ws::WsHeavy.new :node_id => "client", :timeout => 8000
|
37
|
+
|
38
|
+
0.upto(50000) { |i|
|
39
|
+
puts "#{i}"
|
40
|
+
puts client.invoke "ws://localhost:9789", "method", "Hello World"
|
41
|
+
}
|
42
|
+
```
|
43
|
+
|
44
|
+
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/zeromem88/ruby-zeromem-ws.
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
require "rspec/core/rake_task"
|
3
|
-
|
4
|
-
RSpec::Core::RakeTask.new(:spec)
|
5
|
-
|
6
|
-
task :default => :spec
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
|
6
|
+
task :default => :spec
|
data/bin/console
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "zeromem/ws"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "zeromem/ws"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
set -euo pipefail
|
3
|
-
IFS=$'\n\t'
|
4
|
-
set -vx
|
5
|
-
|
6
|
-
bundle install
|
7
|
-
|
8
|
-
# Do any other automated setup that you need to do here
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
set -euo pipefail
|
3
|
+
IFS=$'\n\t'
|
4
|
+
set -vx
|
5
|
+
|
6
|
+
bundle install
|
7
|
+
|
8
|
+
# Do any other automated setup that you need to do here
|
data/lib/zeromem/ws.rb
CHANGED
@@ -1,85 +1,85 @@
|
|
1
|
-
require "zeromem/ws/version"
|
2
|
-
require 'rjr/core_ext'
|
3
|
-
require 'rjr/nodes/ws'
|
4
|
-
|
5
|
-
module Zeromem
|
6
|
-
module Ws
|
7
|
-
class WsHeavy < RJR::Nodes::WS
|
8
|
-
# WS initializer
|
9
|
-
# @param [Hash] args the options to create the web socket node with
|
10
|
-
# @option args [String] :host the hostname/ip which to listen on
|
11
|
-
# @option args [Integer] :port the port which to listen on
|
12
|
-
def initialize(args = {})
|
13
|
-
super(args)
|
14
|
-
end
|
15
|
-
|
16
|
-
# Instructs node to send rpc request, and wait for / return response
|
17
|
-
#
|
18
|
-
# Implementation of Zeromem::Ws::WsHeavy#invoke
|
19
|
-
# This is custom implementation of RJR::Node#invoke
|
20
|
-
# to make things work perfectly under heavy load (thousands of ws queries per min)
|
21
|
-
#
|
22
|
-
# Do not invoke directly from em event loop or callback as will block the message
|
23
|
-
# subscription used to receive responses
|
24
|
-
#
|
25
|
-
# @param [String] uri location of node to send request to, should be
|
26
|
-
# in format of ws://hostname:port
|
27
|
-
# @param [String] rpc_method json-rpc method to invoke on destination
|
28
|
-
# @param [Array] args array of arguments to convert to json and invoke remote method wtih
|
29
|
-
def invoke(uri, rpc_method, *args)
|
30
|
-
message = RJR::Messages::Request.new :method => rpc_method,
|
31
|
-
:args => args,
|
32
|
-
:headers => @message_headers
|
33
|
-
|
34
|
-
@@em.schedule {
|
35
|
-
init_client(uri) do |c|
|
36
|
-
c.stream { |msg| handle_message(msg.data, c) }
|
37
|
-
|
38
|
-
c.send_msg message.to_s
|
39
|
-
end
|
40
|
-
}
|
41
|
-
|
42
|
-
# TODO optional timeout for response ?
|
43
|
-
# this cause resource leak
|
44
|
-
#result = wait_for_result(message)
|
45
|
-
|
46
|
-
result = wait_for_result_custom(message)
|
47
|
-
|
48
|
-
if result.size > 2
|
49
|
-
fail result[2]
|
50
|
-
end
|
51
|
-
return result[1]
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
def wait_for_result_custom(message)
|
56
|
-
res = nil
|
57
|
-
message_id = message.msg_id
|
58
|
-
@pending[message_id] = Time.now
|
59
|
-
while res.nil?
|
60
|
-
@response_lock.synchronize{
|
61
|
-
# Prune messages that timed out
|
62
|
-
if @timeout
|
63
|
-
now = Time.now
|
64
|
-
@pending.delete_if { |_, start_time| (now - start_time) > @timeout }
|
65
|
-
end
|
66
|
-
pending_ids = @pending.keys
|
67
|
-
fail 'Timed out' unless pending_ids.include? message_id
|
68
|
-
|
69
|
-
# Prune invalid responses
|
70
|
-
@responses.keep_if { |response| @pending.has_key? response.first }
|
71
|
-
res = @responses.find { |response| message.msg_id == response.first }
|
72
|
-
if !res.nil?
|
73
|
-
@responses.delete(res)
|
74
|
-
@pending.delete(message_id)
|
75
|
-
else
|
76
|
-
@response_cv.wait @response_lock, @wait_interval
|
77
|
-
end
|
78
|
-
}
|
79
|
-
end
|
80
|
-
return res
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
1
|
+
require "zeromem/ws/version"
|
2
|
+
require 'rjr/core_ext'
|
3
|
+
require 'rjr/nodes/ws'
|
4
|
+
|
5
|
+
module Zeromem
|
6
|
+
module Ws
|
7
|
+
class WsHeavy < RJR::Nodes::WS
|
8
|
+
# WS initializer
|
9
|
+
# @param [Hash] args the options to create the web socket node with
|
10
|
+
# @option args [String] :host the hostname/ip which to listen on
|
11
|
+
# @option args [Integer] :port the port which to listen on
|
12
|
+
def initialize(args = {})
|
13
|
+
super(args)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Instructs node to send rpc request, and wait for / return response
|
17
|
+
#
|
18
|
+
# Implementation of Zeromem::Ws::WsHeavy#invoke
|
19
|
+
# This is custom implementation of RJR::Node#invoke
|
20
|
+
# to make things work perfectly under heavy load (thousands of ws queries per min)
|
21
|
+
#
|
22
|
+
# Do not invoke directly from em event loop or callback as will block the message
|
23
|
+
# subscription used to receive responses
|
24
|
+
#
|
25
|
+
# @param [String] uri location of node to send request to, should be
|
26
|
+
# in format of ws://hostname:port
|
27
|
+
# @param [String] rpc_method json-rpc method to invoke on destination
|
28
|
+
# @param [Array] args array of arguments to convert to json and invoke remote method wtih
|
29
|
+
def invoke(uri, rpc_method, *args)
|
30
|
+
message = RJR::Messages::Request.new :method => rpc_method,
|
31
|
+
:args => args,
|
32
|
+
:headers => @message_headers
|
33
|
+
|
34
|
+
@@em.schedule {
|
35
|
+
init_client(uri) do |c|
|
36
|
+
c.stream { |msg| handle_message(msg.data, c) }
|
37
|
+
|
38
|
+
c.send_msg message.to_s
|
39
|
+
end
|
40
|
+
}
|
41
|
+
|
42
|
+
# TODO optional timeout for response ?
|
43
|
+
# this cause resource leak
|
44
|
+
#result = wait_for_result(message)
|
45
|
+
|
46
|
+
result = wait_for_result_custom(message)
|
47
|
+
|
48
|
+
if result.size > 2
|
49
|
+
fail result[2]
|
50
|
+
end
|
51
|
+
return result[1]
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
def wait_for_result_custom(message)
|
56
|
+
res = nil
|
57
|
+
message_id = message.msg_id
|
58
|
+
@pending[message_id] = Time.now
|
59
|
+
while res.nil?
|
60
|
+
@response_lock.synchronize{
|
61
|
+
# Prune messages that timed out
|
62
|
+
if @timeout
|
63
|
+
now = Time.now
|
64
|
+
@pending.delete_if { |_, start_time| (now - start_time) > @timeout }
|
65
|
+
end
|
66
|
+
pending_ids = @pending.keys
|
67
|
+
fail 'Timed out' unless pending_ids.include? message_id
|
68
|
+
|
69
|
+
# Prune invalid responses
|
70
|
+
@responses.keep_if { |response| @pending.has_key? response.first }
|
71
|
+
res = @responses.find { |response| message.msg_id == response.first }
|
72
|
+
if !res.nil?
|
73
|
+
@responses.delete(res)
|
74
|
+
@pending.delete(message_id)
|
75
|
+
else
|
76
|
+
@response_cv.wait @response_lock, @wait_interval
|
77
|
+
end
|
78
|
+
}
|
79
|
+
end
|
80
|
+
return res
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
data/lib/zeromem/ws/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
module Zeromem
|
2
|
-
module Ws
|
3
|
-
VERSION = "0.1.
|
4
|
-
end
|
5
|
-
end
|
1
|
+
module Zeromem
|
2
|
+
module Ws
|
3
|
+
VERSION = "0.1.3"
|
4
|
+
end
|
5
|
+
end
|
data/ws_test.rb
CHANGED
File without changes
|
data/zeromem-ws.gemspec
CHANGED
@@ -1,30 +1,30 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "zeromem/ws/version"
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "zeromem-ws"
|
8
|
-
spec.version = Zeromem::Ws::VERSION
|
9
|
-
spec.authors = ["zeromem88"]
|
10
|
-
spec.email = ["zeromem2@gmail.com"]
|
11
|
-
|
12
|
-
spec.summary = %q{Extended websocket client based on Movitto/rjr package}
|
13
|
-
spec.description = %q{Eliminates performance degradation of Movitto/rjr websocket json-rpc client under heavy load}
|
14
|
-
spec.homepage = "https://github.com/zeromem88/ruby-zeromem-ws"
|
15
|
-
spec.license = "MIT"
|
16
|
-
|
17
|
-
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
-
f.match(%r{^(test|spec|features)/})
|
19
|
-
end
|
20
|
-
spec.bindir = "exe"
|
21
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
-
spec.require_paths = ["lib"]
|
23
|
-
|
24
|
-
spec.add_development_dependency "bundler", "
|
25
|
-
spec.add_development_dependency "rake", "~>
|
26
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
-
spec.add_dependency "em-websocket", "~> 0.5.1"
|
28
|
-
spec.add_dependency "em-websocket-client", "~> 0.1.2"
|
29
|
-
spec.add_dependency "rjr", ">= 0.19.3"
|
30
|
-
end
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "zeromem/ws/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "zeromem-ws"
|
8
|
+
spec.version = Zeromem::Ws::VERSION
|
9
|
+
spec.authors = ["zeromem88"]
|
10
|
+
spec.email = ["zeromem2@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Extended websocket client based on Movitto/rjr package}
|
13
|
+
spec.description = %q{Eliminates performance degradation of Movitto/rjr websocket json-rpc client under heavy load}
|
14
|
+
spec.homepage = "https://github.com/zeromem88/ruby-zeromem-ws"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", ">= 2.2.10"
|
25
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
spec.add_dependency "em-websocket", "~> 0.5.1"
|
28
|
+
spec.add_dependency "em-websocket-client", "~> 0.1.2"
|
29
|
+
spec.add_dependency "rjr", ">= 0.19.3"
|
30
|
+
end
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zeromem-ws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zeromem88
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.2.10
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.2.10
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '13.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '13.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -135,8 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
135
|
- !ruby/object:Gem::Version
|
136
136
|
version: '0'
|
137
137
|
requirements: []
|
138
|
-
|
139
|
-
rubygems_version: 2.6.11
|
138
|
+
rubygems_version: 3.1.2
|
140
139
|
signing_key:
|
141
140
|
specification_version: 4
|
142
141
|
summary: Extended websocket client based on Movitto/rjr package
|