From 6a1164a0ededd7f80ac3b493c78c0fa1b9b8b91b Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 21 Nov 2011 20:39:59 +0000 Subject: [PATCH] http_file: timeout scaling for "write" method 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. --- lib/mogilefs/http_file.rb | 18 +++++++++++++++++- lib/mogilefs/socket/kgio.rb | 2 -- lib/mogilefs/socket/pure_ruby.rb | 2 -- 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 -- 2.11.4.GIT