griffin 0.1.6 → 0.1.7
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/LICENSE.txt +1 -1
- data/README.md +0 -3
- data/griffin.gemspec +1 -2
- data/lib/griffin/version.rb +1 -1
- metadata +3 -19
- data/lib/griffin/connection_pool/multi_timed_stack.rb +0 -78
- data/lib/griffin/connection_pool/pool.rb +0 -56
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c652877e17adc1c4fa9b80a57e3221b82f96d293e91b651ec353ff50def5e9e
|
4
|
+
data.tar.gz: e18fdedd34dee63f6baa9b9ec27624e063441e9797667672f522ac24fe422651
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f68f68011a3f44ab51c1df9023c886be6557c6df2c08880eea898d2ebde45a113a1b6b15d61a09d9e230553e7f081c606a8d0497c85db525c8bceeed3e7d4429
|
7
|
+
data.tar.gz: 3cf82bf6088dcba222d83bdde1466f24d3a7e79dea41c9557774dfc626c0daebbebea87415fe418133a8dd69e6a884162b8f5dec2177d95a92097d7f9f2cf8f3
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
data/griffin.gemspec
CHANGED
@@ -7,7 +7,7 @@ require 'griffin/version'
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
8
|
spec.name = 'griffin'
|
9
9
|
spec.version = Griffin::VERSION
|
10
|
-
spec.authors = ['
|
10
|
+
spec.authors = ['Yuta Iwama']
|
11
11
|
spec.email = ['ganmacs@gmail.com']
|
12
12
|
|
13
13
|
spec.summary = 'gRPC server and client for Ruby'
|
@@ -28,7 +28,6 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency 'rspec'
|
29
29
|
spec.add_development_dependency 'rubocop'
|
30
30
|
|
31
|
-
spec.add_dependency 'connection_pool', '~> 2.2.2'
|
32
31
|
spec.add_dependency 'grpc_kit', '>= 0.2.0'
|
33
32
|
spec.add_dependency 'serverengine', '~> 2.0.7'
|
34
33
|
end
|
data/lib/griffin/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: griffin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Yuta Iwama
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: connection_pool
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 2.2.2
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 2.2.2
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: grpc_kit
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,8 +142,6 @@ files:
|
|
156
142
|
- examples/routeguide_server.rb
|
157
143
|
- griffin.gemspec
|
158
144
|
- lib/griffin.rb
|
159
|
-
- lib/griffin/connection_pool/multi_timed_stack.rb
|
160
|
-
- lib/griffin/connection_pool/pool.rb
|
161
145
|
- lib/griffin/counting_semaphore.rb
|
162
146
|
- lib/griffin/engine.rb
|
163
147
|
- lib/griffin/engine/server.rb
|
@@ -1,78 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'connection_pool'
|
4
|
-
|
5
|
-
module Griffin
|
6
|
-
module ConnectionPool
|
7
|
-
# This code is based on https://github.com/drbrain/net-http-persistent/blob/0e5a8fb8a27deff37247ddb3bc5e6c9e390face5/lib/net/http/persistent/timed_stack_multi.rb
|
8
|
-
class MultiTimedStack < ::ConnectionPool::TimedStack
|
9
|
-
def initialize(size = 0, &block)
|
10
|
-
super
|
11
|
-
|
12
|
-
@enqueued = 0
|
13
|
-
@ques = Hash.new { |h, k| h[k] = [] }
|
14
|
-
@lru = []
|
15
|
-
end
|
16
|
-
|
17
|
-
def empty?
|
18
|
-
length <= 0
|
19
|
-
end
|
20
|
-
|
21
|
-
def length
|
22
|
-
@max - @created + @enqueued
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def connection_stored?(options = {})
|
28
|
-
!@ques[options[:connection_args]].empty?
|
29
|
-
end
|
30
|
-
|
31
|
-
def fetch_connection(options = {})
|
32
|
-
connection_args = options[:connection_args]
|
33
|
-
|
34
|
-
@enqueued -= 1
|
35
|
-
lru_update(connection_args)
|
36
|
-
@ques[connection_args].pop
|
37
|
-
end
|
38
|
-
|
39
|
-
def shutdown_connections
|
40
|
-
@ques.each_key do |key|
|
41
|
-
super(connection_args: key)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def store_connection(obj, options = {})
|
46
|
-
@ques[options[:connection_args]].push(obj)
|
47
|
-
@enqueued += 1
|
48
|
-
end
|
49
|
-
|
50
|
-
def try_create(options = {})
|
51
|
-
connection_args = options[:connection_args]
|
52
|
-
|
53
|
-
if @created >= @max && @enqueued >= 1
|
54
|
-
oldest = lru_delete
|
55
|
-
@ques[oldest].pop
|
56
|
-
|
57
|
-
@created -= 1
|
58
|
-
end
|
59
|
-
|
60
|
-
if @created < @max
|
61
|
-
obj = @create_block.call(connection_args)
|
62
|
-
@created += 1
|
63
|
-
lru_update(connection_args)
|
64
|
-
obj
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def lru_update(key)
|
69
|
-
@lru.delete(key)
|
70
|
-
@lru.push(key)
|
71
|
-
end
|
72
|
-
|
73
|
-
def lru_delete
|
74
|
-
@lru.shift
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'connection_pool'
|
4
|
-
|
5
|
-
require 'griffin/connection_pool/multi_timed_stack'
|
6
|
-
|
7
|
-
module Griffin
|
8
|
-
module ConnectionPool
|
9
|
-
class Pool
|
10
|
-
DEFAULTS = { size: 5, timeout: 5 }.freeze
|
11
|
-
|
12
|
-
def initialize(options = {}, &block)
|
13
|
-
raise ArgumentError, 'Connection pool requires a block' unless block
|
14
|
-
|
15
|
-
options = DEFAULTS.merge(options)
|
16
|
-
|
17
|
-
@size = Integer(options.fetch(:size))
|
18
|
-
@timeout = Integer(options.fetch(:timeout))
|
19
|
-
|
20
|
-
@available = Griffin::ConnectionPool::MultiTimedStack.new(@size, &block)
|
21
|
-
@key = :"current-#{@available.object_id}"
|
22
|
-
Thread.current[@key] = Hash.new { |h, k| h[k] = [] }
|
23
|
-
end
|
24
|
-
|
25
|
-
def checkin(key)
|
26
|
-
stack = Thread.current[@key][key]
|
27
|
-
raise 'no connections are checked out' if stack.empty?
|
28
|
-
|
29
|
-
conn = stack.pop
|
30
|
-
if stack.empty?
|
31
|
-
@available.push(conn, connection_args: key)
|
32
|
-
end
|
33
|
-
nil
|
34
|
-
end
|
35
|
-
|
36
|
-
def checkout(key)
|
37
|
-
stack = Thread.current[@key][key]
|
38
|
-
|
39
|
-
conn =
|
40
|
-
if stack.empty?
|
41
|
-
@available.pop(connection_args: key)
|
42
|
-
else
|
43
|
-
stack.last
|
44
|
-
end
|
45
|
-
|
46
|
-
stack.push(conn)
|
47
|
-
|
48
|
-
conn
|
49
|
-
end
|
50
|
-
|
51
|
-
def shutdown(&block)
|
52
|
-
@available.shutdown(&block)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|