about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-11-21 20:39:59 +0000
committerEric Wong <normalperson@yhbt.net>2011-11-21 20:39:59 +0000
commit6a1164a0ededd7f80ac3b493c78c0fa1b9b8b91b (patch)
treef21e4ebdbc6c1304c5d6ba069d1804dbef4efb09
parent64b3335c8b41ca77395f7eb7bbd7d9b0a62bc8c7 (diff)
downloadmogilefs-client-6a1164a0ededd7f80ac3b493c78c0fa1b9b8b91b.tar.gz
Increase write timeouts as we become more vested in uploading to
a socket.  The remote server may take longer and longer to
respond due to accumulated I/O delays if it is writing out
to disk.

We also don't need/want a "write" method in MogileFS::Socket,
it's only for use with IO.copy_stream in HTTPFile.
-rw-r--r--lib/mogilefs/http_file.rb18
-rw-r--r--lib/mogilefs/socket/kgio.rb2
-rw-r--r--lib/mogilefs/socket/pure_ruby.rb2
3 files changed, 17 insertions, 5 deletions
diff --git a/lib/mogilefs/http_file.rb b/lib/mogilefs/http_file.rb
index b08abaa..4d4a850 100644
--- a/lib/mogilefs/http_file.rb
+++ b/lib/mogilefs/http_file.rb
@@ -20,12 +20,27 @@ class MogileFS::HTTPFile < StringIO
   end
   class NonRetryableError < MogileFS::Error; end
 
+  class HTTPSock < MogileFS::Socket
+    attr_accessor :start
+
+    # Increase timeout as we become more invested in uploading with
+    # this socket.  The server could be experiencing I/O delays
+    # from large uploads because the sysadmin forgot to tune the
+    # VM sysctls for handling large files.
+    def write(buf)
+      timed_write(buf, Time.now - @start + 5.0)
+    end
+  end
+
   # :stopdoc:
   MD5_TRAILER_NODES = {} # :nodoc: # EXPERIMENTAL
   class << self
     attr_accessor :response_timeout_cb
   end
 
+  # temporary directories (nginx) may not be configured on the
+  # same device, necessitating a time-consuming full file copy
+  # instead of a quick rename(2)/link(2) operation
   @response_timeout_cb = lambda do |elapsed_time, bytes_uploaded|
     mbytes_uploaded = bytes_uploaded / (1024.0 * 1024.0)
     # assumes worst case is 10M/s on the remote storage disk
@@ -107,7 +122,8 @@ class MogileFS::HTTPFile < StringIO
   # returns file size if the socket finished writing
   def upload(devid, uri) # :nodoc:
     start = Time.now
-    sock = MogileFS::Socket.tcp(uri.host, uri.port)
+    sock = HTTPSock.tcp(uri.host, uri.port)
+    sock.start = start
     file_size = length
 
     if @streaming_io
diff --git a/lib/mogilefs/socket/kgio.rb b/lib/mogilefs/socket/kgio.rb
index 63f9c0b..111384a 100644
--- a/lib/mogilefs/socket/kgio.rb
+++ b/lib/mogilefs/socket/kgio.rb
@@ -50,6 +50,4 @@ class MogileFS::Socket < Kgio::Socket
       return expect
     end while true
   end
-
-  alias write timed_write
 end
diff --git a/lib/mogilefs/socket/pure_ruby.rb b/lib/mogilefs/socket/pure_ruby.rb
index fa386cd..b820b20 100644
--- a/lib/mogilefs/socket/pure_ruby.rb
+++ b/lib/mogilefs/socket/pure_ruby.rb
@@ -65,6 +65,4 @@ class MogileFS::Socket < Socket
         request_truncated!(written, expect)
     end while true
   end
-
-  alias write timed_write
 end