From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id B2D122042F for ; Wed, 31 Aug 2016 02:50:47 +0000 (UTC) From: Eric Wong To: mogilefs-client-public@bogomips.org Subject: [PATCH 4/6] implement :connect_timeout option Date: Wed, 31 Aug 2016 02:50:44 +0000 Message-Id: <20160831025046.24153-5-e@80x24.org> In-Reply-To: <20160831025046.24153-1-e@80x24.org> References: <20160831025046.24153-1-e@80x24.org> List-Id: 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 @@ def initialize(args) @mutex = Mutex.new @timeout = args[:timeout] || 3 + @connect_timeout = args[:connect_timeout] || 3 @socket = nil @lasterr = nil @lasterrstr = nil @@ -347,7 +348,7 @@ def socket 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 @@ def initialize(args) @readonly = args[:readonly] ? true : false @timeout = args[:timeout] @fail_timeout = args[:fail_timeout] + @connect_timeout = args[:connect_timeout] reload end @@ -37,7 +38,8 @@ def initialize(args) 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] -- EW