Ruby mogilefs-client dev/users discussion/patches/bugs/help/...
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: mogilefs-client-public@bogomips.org
Subject: [PATCH 4/6] implement :connect_timeout option
Date: Wed, 31 Aug 2016 02:50:44 +0000	[thread overview]
Message-ID: <20160831025046.24153-5-e@80x24.org> (raw)
In-Reply-To: <20160831025046.24153-1-e@80x24.org>

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


  parent reply	other threads:[~2016-08-31  2:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-31  2:50 [PATCH 0/6] misc fixes and features Eric Wong
2016-08-31  2:50 ` [PATCH 1/6] test_fresh: do not delete non-existent domain Eric Wong
2016-08-31  2:50 ` [PATCH 2/6] admin: map unset reject_bad_md5 field to nil Eric Wong
2016-08-31  2:50 ` [PATCH 3/6] socket/pure_ruby: connect with "exception:false" on Ruby 2.3+ Eric Wong
2016-08-31  2:50 ` Eric Wong [this message]
2016-08-31  7:09   ` [7/6 PATCH] connect_timeout: match :timeout if unset Eric Wong
2016-08-31  2:50 ` [PATCH 5/6] add .gitattributes for Ruby method detection Eric Wong
2016-08-31  2:50 ` [PATCH 6/6] README: stop mentioning cgit Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/mogilefs-client/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160831025046.24153-5-e@80x24.org \
    --to=e@80x24.org \
    --cc=mogilefs-client-public@bogomips.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/mogilefs-client.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).