@@ -200,6 +200,11 @@ class Net::HTTP::Persistent
200
200
201
201
HAVE_OPENSSL = defined? OpenSSL ::SSL # :nodoc:
202
202
203
+ ##
204
+ # The default connection pool size is 1/4 the allowed open files.
205
+
206
+ DEFAULT_POOL_SIZE = Process . getrlimit ( Process ::RLIMIT_NOFILE ) . first / 4
207
+
203
208
##
204
209
# The version of Net::HTTP::Persistent you are using
205
210
@@ -499,8 +504,12 @@ def self.detect_idle_timeout uri, max = 10
499
504
# proxy = URI 'http://proxy.example'
500
505
# proxy.user = 'AzureDiamond'
501
506
# proxy.password = 'hunter2'
507
+ #
508
+ # Set +pool_size+ to limit the maximum number of connections allowed.
509
+ # Defaults to 1/4 the number of allowed file handles. You can have no more
510
+ # than this many threads with active HTTP transactions.
502
511
503
- def initialize name = nil , proxy = nil
512
+ def initialize name : nil , proxy : nil , pool_size : DEFAULT_POOL_SIZE
504
513
@name = name
505
514
506
515
@debug_output = nil
@@ -525,8 +534,7 @@ def initialize name = nil, proxy = nil
525
534
@ssl_generation_key = [ key , 'ssl_generations' ] . join ( '_' ) . intern
526
535
@timeout_key = [ key , 'timeouts' ] . join ( '_' ) . intern
527
536
528
- pool_size = Process . getrlimit ( Process ::RLIMIT_NOFILE ) . first / 4
529
- @pool = Net ::HTTP ::Persistent ::Pool . new size : pool_size do |http_args |
537
+ @pool = Net ::HTTP ::Persistent ::Pool . new size : pool_size do |http_args |
530
538
Net ::HTTP ::Persistent ::Connection . new Net ::HTTP , http_args , @ssl_generation
531
539
end
532
540
0 commit comments