Permalink
Browse files

Remove idle connections

  • Loading branch information...
1 parent 9ac6c28 commit d44ddce3e473e93d8aa8c1f0d569642f3845fa17 @bpardee committed Feb 23, 2012
Showing with 33 additions and 11 deletions.
  1. +5 −1 Gemfile
  2. +6 −1 History.md
  3. +1 −1 README.rdoc
  4. +19 −6 lib/persistent_http.rb
  5. +2 −2 persistent_http.gemspec
View
@@ -1,9 +1,13 @@
source "http://rubygems.org"
-gem 'gene_pool', '>= 1.0.1'
+gem 'gene_pool', '>= 1.2.1'
group :development do
gem 'rack'
gem 'rake'
gem 'rdoc'
end
+
+group :test do
+ gem 'shoulda'
+end
View
@@ -1,5 +1,10 @@
PersistentHttp Changelog
-=====================
+========================
+
+1.0.3
+
+ - Allow option idle_timeout which will renew connection that haven't been used in this amount of time.
+ - Implement shutdown which will close connections as they are checked in.
1.0.2
View
@@ -55,4 +55,4 @@ returned.
== Copyright
-Copyright (c) 2010 Eric Hodel, Aaron Patterson, Brad Pardee. See LICENSE for details.
+Copyright (c) 2010-2012 Eric Hodel, Aaron Patterson, Brad Pardee. See LICENSE for details.
View
@@ -83,6 +83,10 @@ class Error < StandardError; end
attr_reader :http_version
##
+ # Connection will be renewed if it hasn't been used in this amount of time. Defaults to 10 seconds.
+ attr_reader :idle_timeout
+
+ ##
# The value sent in the Keep-Alive header. Defaults to 30. Not needed for
# HTTP/1.1 servers.
#
@@ -143,7 +147,7 @@ class Error < StandardError; end
##
# The threshold in seconds for checking out a connection at which a warning
# will be logged via the logger
- attr_accessor :warn_timeout
+ attr_reader :warn_timeout
##
# Creates a new PersistentHTTP.
@@ -171,6 +175,7 @@ def initialize(options={})
@force_retry = options[:force_retry]
@headers = options[:header] || {}
@host = options[:host]
+ @idle_timeout = options[:idle_timeout] || 10
@keep_alive = options[:keep_alive] || 30
@logger = options[:logger]
@open_timeout = options[:open_timeout]
@@ -227,6 +232,7 @@ def initialize(options={})
@pool = GenePool.new(:name => name + '-' + connection_id,
:pool_size => @pool_size,
:warn_timeout => @warn_timeout,
+ :idle_timeout => @idle_timeout,
:logger => @logger) do
begin
connection = Net::HTTP.new(*net_http_args)
@@ -246,6 +252,16 @@ def initialize(options={})
end
end
+ # Reset the size of the connection pool
+ def pool_size=(pool_size)
+ @gene_pool.pool_size = pool_size
+ end
+
+ # Return the size of the connection pool
+ def pool_size
+ @gene_pool.pool_size
+ end
+
##
# Makes a request per +req+. If +req+ is nil a Net::HTTP::Get is performed
# against +default_path+.
@@ -320,11 +336,8 @@ def request(req = nil, options = {}, &block)
##
# Shuts down all connections.
-
- def shutdown
- raise 'Shutdown not implemented'
- # TBD - need to think about this one
- @count_hash = nil
+ def shutdown(timeout=10)
+ @gene_pool.close(timeout)
end
#######
View
@@ -6,6 +6,6 @@ Gem::Specification.new do |s|
s.email = ['bradpardee@gmail.com']
s.homepage = 'http://github.com/bpardee/persistent_http'
s.files = Dir["{examples,lib}/**/*"] + %w(LICENSE Rakefile History.md README.rdoc)
- s.version = '1.0.2'
- s.add_dependency 'gene_pool', '>= 1.0.1'
+ s.version = '1.0.3'
+ s.add_dependency 'gene_pool', '>= 1.2.1'
end

0 comments on commit d44ddce

Please sign in to comment.