From 622d5ab17846bc58c2e0cfd98b3a8b73ad341c0d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 26 Aug 2016 21:38:54 +0000 Subject: implement :connect_timeout option This can be useful for specifying a different timeout for establishing a connection. Some requests could be expensive and want a higher :timeout measured in seconds, while the time to establish a TCP connection on a healthy LAN could be less than a millisecond. This defaults to 3s to match the existing :timeout, but only affects the amount of time the client will wait for establishing a TCP connection to a tracker. --- lib/mogilefs/backend.rb | 3 ++- lib/mogilefs/client.rb | 4 +++- lib/mogilefs/mogilefs.rb | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/mogilefs/backend.rb b/lib/mogilefs/backend.rb index 632d6f1..4cf2526 100644 --- a/lib/mogilefs/backend.rb +++ b/lib/mogilefs/backend.rb @@ -79,6 +79,7 @@ class MogileFS::Backend @mutex = Mutex.new @timeout = args[:timeout] || 3 + @connect_timeout = args[:connect_timeout] || 3 @socket = nil @lasterr = nil @lasterrstr = nil @@ -347,7 +348,7 @@ class MogileFS::Backend begin addr, port = host.split(':'.freeze) - @socket = MogileFS::Socket.tcp(addr, port, @timeout) + @socket = MogileFS::Socket.tcp(addr, port, @connect_timeout) @active_host = host rescue SystemCallError, MogileFS::Timeout => err @dead[host] = [ MogileFS.now, err ] diff --git a/lib/mogilefs/client.rb b/lib/mogilefs/client.rb index 7a808f1..1e30874 100644 --- a/lib/mogilefs/client.rb +++ b/lib/mogilefs/client.rb @@ -27,6 +27,7 @@ class MogileFS::Client @readonly = args[:readonly] ? true : false @timeout = args[:timeout] @fail_timeout = args[:fail_timeout] + @connect_timeout = args[:connect_timeout] reload end @@ -37,7 +38,8 @@ class MogileFS::Client def reload @backend = MogileFS::Backend.new(:hosts => @hosts, :timeout => @timeout, - :fail_timeout => @fail_timeout) + :fail_timeout => @fail_timeout, + :connect_timeout => @connect_timeout) end ## diff --git a/lib/mogilefs/mogilefs.rb b/lib/mogilefs/mogilefs.rb index f454a0f..d17f0b8 100644 --- a/lib/mogilefs/mogilefs.rb +++ b/lib/mogilefs/mogilefs.rb @@ -64,6 +64,10 @@ class MogileFS::MogileFS < MogileFS::Client # Timeout for tracker backend responses. # Defaults to 3 seconds. # + # [:connect_timeout => Integer] + # + # Timeout for connecting to a tracker + # Defaults to 3 seconds def initialize(args = {}) @domain = args[:domain] -- cgit v1.2.3-24-ge0c7