pinot-client 1.8.0 → 1.10.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 819824203883477127807cc1a86d8535f7721883dfaec85423c5b333dd453b6e
4
- data.tar.gz: dff26b09b035ad4d217a63b2b661677d4b47922760f2f140a6cda942d9383a20
3
+ metadata.gz: ddb501e91483838437691807ff09f98be16584f5b5e9e25c32982581db9fc226
4
+ data.tar.gz: 69f4df0c9fae29d42388b5fa6e1f55a1c722f70673c91b5ad43339762ad052fe
5
5
  SHA512:
6
- metadata.gz: 606903f919bd310a8b1c208206db2c4ac25b5522ee26079435966f95f171573b0800266970ca3643c29528f506cf2a2c392b7161f7f2c3a174c313732a53721e
7
- data.tar.gz: bc99e8c6ba493de6a534009e557915f9e72a57298129837750c49d8e1026dc8785822b079c63d05c42842a5b800930c44ac415bdf487e622fe1518f5cbbbf867
6
+ metadata.gz: 974f22a9db31c53e6a0534400347df98b419a1f6fffc351594bc6ea06456d211cda4ede80390fdf7c9b67a0f0559a6772a8225cc552b2844fb28e33ea11220b6
7
+ data.tar.gz: 711718da0cb66cd42457c657f58fc29450049094a1f6bf9012557a3b484dc59ca2d66f45bbf9c2c716597779a084fc59ab7fb15730fbac4648ac47823291d9c4
@@ -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
- @pool_mutex.synchronize { @pool[key]&.pop } || new_connection(uri)
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
@@ -1,3 +1,3 @@
1
1
  module Pinot
2
- VERSION = "1.8.0"
2
+ VERSION = "1.10.0"
3
3
  end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pinot-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xiang Fu