pinot-client 1.8.0 → 1.12.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/lib/pinot/transport.rb +46 -2
- data/lib/pinot/version.rb +1 -1
- data/lib/pinot.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ff1b333b02ecef88a907d5ad1194d7e5a6a320bbd03337a6214d38af0b0995b3
|
|
4
|
+
data.tar.gz: f547e9d59b9c0ce692ad17d0b15f398b81df605acdb79078510a1987bd15ad8b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ec32bb234ba6ed82303b6d3d3ebd6d33b441f6bc489cef38e7a7adbe21d7f5d025003c3f55d5bab371c14c8a8267f0835be9757e04817249f4274bfc2d7249f0
|
|
7
|
+
data.tar.gz: 9e133f3c42967560bf7570da11cec1503451542b8bb58acfea33985b94b393bc77ae352a03f8c644870a0e923ed40f20d75685ff1b1e51e539f81a1d188f7484
|
data/lib/pinot/transport.rb
CHANGED
|
@@ -9,11 +9,14 @@ module Pinot
|
|
|
9
9
|
MAX_POOL_SIZE = 5
|
|
10
10
|
KEEP_ALIVE_TIMEOUT = 30
|
|
11
11
|
|
|
12
|
+
PoolEntry = Struct.new(:http, :checked_in_at)
|
|
13
|
+
|
|
12
14
|
def initialize(timeout: nil, tls_config: nil)
|
|
13
15
|
@timeout = timeout
|
|
14
16
|
@tls_config = tls_config
|
|
15
17
|
@pool = {}
|
|
16
18
|
@pool_mutex = Mutex.new
|
|
19
|
+
@reaper = start_reaper
|
|
17
20
|
end
|
|
18
21
|
|
|
19
22
|
def post(url, body:, headers: {})
|
|
@@ -52,20 +55,61 @@ module Pinot
|
|
|
52
55
|
end
|
|
53
56
|
|
|
54
57
|
def checkout(key, uri)
|
|
55
|
-
|
|
58
|
+
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
59
|
+
http = @pool_mutex.synchronize do
|
|
60
|
+
entries = @pool[key] ||= []
|
|
61
|
+
fresh = nil
|
|
62
|
+
while (entry = entries.pop)
|
|
63
|
+
if now - entry.checked_in_at < KEEP_ALIVE_TIMEOUT
|
|
64
|
+
fresh = entry.http
|
|
65
|
+
break
|
|
66
|
+
else
|
|
67
|
+
entry.http.finish rescue nil
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
fresh
|
|
71
|
+
end
|
|
72
|
+
http || new_connection(uri)
|
|
56
73
|
end
|
|
57
74
|
|
|
58
75
|
def checkin(key, http)
|
|
59
76
|
@pool_mutex.synchronize do
|
|
60
77
|
pool_for_key = @pool[key] ||= []
|
|
61
78
|
if pool_for_key.size < MAX_POOL_SIZE
|
|
62
|
-
pool_for_key.push(http)
|
|
79
|
+
pool_for_key.push(PoolEntry.new(http, Process.clock_gettime(Process::CLOCK_MONOTONIC)))
|
|
63
80
|
else
|
|
64
81
|
http.finish rescue nil
|
|
65
82
|
end
|
|
66
83
|
end
|
|
67
84
|
end
|
|
68
85
|
|
|
86
|
+
def start_reaper
|
|
87
|
+
t = Thread.new do
|
|
88
|
+
loop do
|
|
89
|
+
sleep KEEP_ALIVE_TIMEOUT / 2.0
|
|
90
|
+
reap_stale_connections
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
t.abort_on_exception = false
|
|
94
|
+
t
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def reap_stale_connections
|
|
98
|
+
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
99
|
+
@pool_mutex.synchronize do
|
|
100
|
+
@pool.each_value do |entries|
|
|
101
|
+
entries.reject! do |entry|
|
|
102
|
+
if now - entry.checked_in_at >= KEEP_ALIVE_TIMEOUT
|
|
103
|
+
entry.http.finish rescue nil
|
|
104
|
+
true
|
|
105
|
+
else
|
|
106
|
+
false
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
69
113
|
def new_connection(uri)
|
|
70
114
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
71
115
|
configure_ssl(http, uri)
|
data/lib/pinot/version.rb
CHANGED
data/lib/pinot.rb
CHANGED
|
@@ -22,9 +22,9 @@ require_relative "pinot/connection"
|
|
|
22
22
|
require_relative "pinot/prepared_statement"
|
|
23
23
|
require_relative "pinot/connection_factory"
|
|
24
24
|
|
|
25
|
+
require_relative "pinot/grpc_config"
|
|
25
26
|
begin
|
|
26
27
|
require_relative "pinot/grpc_transport"
|
|
27
|
-
require_relative "pinot/grpc_config"
|
|
28
28
|
rescue LoadError
|
|
29
29
|
# grpc gem not available; GrpcTransport disabled
|
|
30
30
|
end
|