net-http-persistent-retry 3.0.1
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 +7 -0
- data/History.txt +360 -0
- data/lib/net/http/persistent.rb +1051 -0
- data/lib/net/http/persistent/connection.rb +40 -0
- data/lib/net/http/persistent/pool.rb +50 -0
- data/lib/net/http/persistent/timed_stack_multi.rb +69 -0
- metadata +67 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
##
|
2
|
+
# A Net::HTTP connection wrapper that holds extra information for managing the
|
3
|
+
# connection's lifetime.
|
4
|
+
|
5
|
+
class Net::HTTP::Persistent::Connection # :nodoc:
|
6
|
+
|
7
|
+
attr_accessor :http
|
8
|
+
|
9
|
+
attr_accessor :last_use
|
10
|
+
|
11
|
+
attr_accessor :requests
|
12
|
+
|
13
|
+
attr_accessor :ssl_generation
|
14
|
+
|
15
|
+
def initialize http_class, http_args, ssl_generation
|
16
|
+
@http = http_class.new(*http_args)
|
17
|
+
@ssl_generation = ssl_generation
|
18
|
+
|
19
|
+
reset
|
20
|
+
end
|
21
|
+
|
22
|
+
def finish
|
23
|
+
@http.finish
|
24
|
+
rescue IOError
|
25
|
+
ensure
|
26
|
+
reset
|
27
|
+
end
|
28
|
+
|
29
|
+
def reset
|
30
|
+
@last_use = Net::HTTP::Persistent::EPOCH
|
31
|
+
@requests = 0
|
32
|
+
end
|
33
|
+
|
34
|
+
def ressl ssl_generation
|
35
|
+
@ssl_generation = ssl_generation
|
36
|
+
|
37
|
+
finish
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
class Net::HTTP::Persistent::Pool < ConnectionPool # :nodoc:
|
2
|
+
|
3
|
+
attr_reader :available # :nodoc:
|
4
|
+
attr_reader :key # :nodoc:
|
5
|
+
|
6
|
+
def initialize(options = {}, &block)
|
7
|
+
super
|
8
|
+
|
9
|
+
@available = Net::HTTP::Persistent::TimedStackMulti.new(@size, &block)
|
10
|
+
@key = "current-#{@available.object_id}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def checkin net_http_args
|
14
|
+
stack = Thread.current[@key][net_http_args] ||= []
|
15
|
+
|
16
|
+
raise ConnectionPool::Error, 'no connections are checked out' if
|
17
|
+
stack.empty?
|
18
|
+
|
19
|
+
conn = stack.pop
|
20
|
+
|
21
|
+
if stack.empty?
|
22
|
+
@available.push conn, connection_args: net_http_args
|
23
|
+
end
|
24
|
+
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def checkout net_http_args
|
29
|
+
stacks = Thread.current[@key] ||= {}
|
30
|
+
stack = stacks[net_http_args] ||= []
|
31
|
+
|
32
|
+
if stack.empty? then
|
33
|
+
conn = @available.pop connection_args: net_http_args
|
34
|
+
else
|
35
|
+
conn = stack.last
|
36
|
+
end
|
37
|
+
|
38
|
+
stack.push conn
|
39
|
+
|
40
|
+
conn
|
41
|
+
end
|
42
|
+
|
43
|
+
def shutdown
|
44
|
+
Thread.current[@key] = nil
|
45
|
+
super
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
require 'net/http/persistent/timed_stack_multi'
|
50
|
+
|
@@ -0,0 +1,69 @@
|
|
1
|
+
class Net::HTTP::Persistent::TimedStackMulti < ConnectionPool::TimedStack # :nodoc:
|
2
|
+
|
3
|
+
def initialize(size = 0, &block)
|
4
|
+
super
|
5
|
+
|
6
|
+
@enqueued = 0
|
7
|
+
@ques = Hash.new { |h, k| h[k] = [] }
|
8
|
+
@lru = {}
|
9
|
+
@key = :"connection_args-#{object_id}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def empty?
|
13
|
+
(@created - @enqueued) >= @max
|
14
|
+
end
|
15
|
+
|
16
|
+
def length
|
17
|
+
@max - @created + @enqueued
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def connection_stored? options = {} # :nodoc:
|
23
|
+
!@ques[options[:connection_args]].empty?
|
24
|
+
end
|
25
|
+
|
26
|
+
def fetch_connection options = {} # :nodoc:
|
27
|
+
connection_args = options[:connection_args]
|
28
|
+
|
29
|
+
@enqueued -= 1
|
30
|
+
lru_update connection_args
|
31
|
+
@ques[connection_args].pop
|
32
|
+
end
|
33
|
+
|
34
|
+
def lru_update connection_args # :nodoc:
|
35
|
+
@lru.delete connection_args
|
36
|
+
@lru[connection_args] = true
|
37
|
+
end
|
38
|
+
|
39
|
+
def shutdown_connections # :nodoc:
|
40
|
+
@ques.each_key do |key|
|
41
|
+
super connection_args: key
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def store_connection obj, options = {} # :nodoc:
|
46
|
+
@ques[options[:connection_args]].push obj
|
47
|
+
@enqueued += 1
|
48
|
+
end
|
49
|
+
|
50
|
+
def try_create options = {} # :nodoc:
|
51
|
+
connection_args = options[:connection_args]
|
52
|
+
|
53
|
+
if @created >= @max && @enqueued >= 1
|
54
|
+
oldest, = @lru.first
|
55
|
+
@lru.delete oldest
|
56
|
+
@ques[oldest].pop
|
57
|
+
|
58
|
+
@created -= 1
|
59
|
+
end
|
60
|
+
|
61
|
+
if @created < @max
|
62
|
+
@created += 1
|
63
|
+
lru_update connection_args
|
64
|
+
return @create_block.call(connection_args)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: net-http-persistent-retry
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 3.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eric Hodel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: connection_pool
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.2'
|
27
|
+
description: Manages persistent connections using Net::HTTP. It's thread-safe too!
|
28
|
+
Using persistent HTTP connections can dramatically increase the speed of HTTP. Creating
|
29
|
+
a new HTTP connection for every request involves an extra TCP round-trip and causes
|
30
|
+
TCP congestion avoidance negotiation to start over. Net::HTTP supports persistent
|
31
|
+
connections with some API methods but does not handle reconnection gracefully. Net::HTTP::Persistent
|
32
|
+
supports reconnection and retry according to RFC 2616.
|
33
|
+
email: drbrain@segment7.net
|
34
|
+
executables: []
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- History.txt
|
39
|
+
- lib/net/http/persistent.rb
|
40
|
+
- lib/net/http/persistent/connection.rb
|
41
|
+
- lib/net/http/persistent/pool.rb
|
42
|
+
- lib/net/http/persistent/timed_stack_multi.rb
|
43
|
+
homepage: https://github.com/grosser/net-http-persistent
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '2.1'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 2.7.6
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: Manages persistent connections using Net::HTTP ... without retries
|
67
|
+
test_files: []
|