Hello all, The following change to Mongrel::HttpRequest: def read_socket(len) if !@socket.closed? data = @socket.recv(len) # <--- formerly @socket.read(len) if !data raise "Socket read return nil" elsif data.length != len raise "Socket read returned insufficient data: #{data.length}" else data end else raise "Socket already closed when reading." end end seems to work for me, and vastly improves the speed of the body processing (quick tests reveal that using IO#read takes about 1 min 40 secs. and using Socket#recv takes about 9 secs on an 8.5 mb file). I have been having trouble discovering the difference between read & recv (I am not a socket developer by any means). Can anybody tell me what sort of safety one loses by doing this with recv instead of read? Thanks. best, Erik Hetzner -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://rubyforge.org/pipermail/mongrel-users/attachments/20070205/29ccc59c/attachment.bin
At Mon, 05 Feb 2007 14:16:44 -0800, Erik Hetzner wrote:> Hello all, > > The following change to Mongrel::HttpRequest:[?]> seems to work for me, and vastly improves the speed of the body > processing (quick tests reveal that using IO#read takes about 1 min 40 > secs. and using Socket#recv takes about 9 secs on an 8.5 mb file). I > have been having trouble discovering the difference between read & > recv (I am not a socket developer by any means). Can anybody tell me > what sort of safety one loses by doing this with recv instead of read? > Thanks.As a followup, in case it wasn?t obvious, I was far off base here. I should have realized that something was wrong with such horrible transfer speeds. While it still seems using recv instead of read, and, conversely, send instead of write gives you a very slight speedup, most of my problem here was a runaway while loop in another thread (while true do; end seems to take up a lot of time). best, Erik Hetzner -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://rubyforge.org/pipermail/mongrel-users/attachments/20070228/72da5664/attachment.bin
On Wed, 28 Feb 2007 14:47:49 -0800 Erik Hetzner <erik.hetzner at ucop.edu> wrote:> At Mon, 05 Feb 2007 14:16:44 -0800, > Erik Hetzner wrote: > > Hello all, > > > > The following change to Mongrel::HttpRequest: > > [?] > > > seems to work for me, and vastly improves the speed of the body > > processing (quick tests reveal that using IO#read takes about 1 min 40 > > secs. and using Socket#recv takes about 9 secs on an 8.5 mb file). I > > have been having trouble discovering the difference between read & > > recv (I am not a socket developer by any means). Can anybody tell me > > what sort of safety one loses by doing this with recv instead of read? > > Thanks. > > As a followup, in case it wasn?t obvious, I was far off base here. I > should have realized that something was wrong with such horrible > transfer speeds. While it still seems using recv instead of read, and, > conversely, send instead of write gives you a very slight speedup, > most of my problem here was a runaway while loop in another thread > (while true do; end seems to take up a lot of time).It is interesting, but I believe that I originally used recv and it had some problems when it came time to actually cooperate with other threads doing read. Could be totally bogus fantasy memory though, but I also know there''s only a few places where recv is faster, as you found. -- Zed A. Shaw, MUDCRAP-CE Master Black Belt Sifu http://www.zedshaw.com/ http://www.awprofessional.com/title/0321483502 -- The Mongrel Book http://mongrel.rubyforge.org/ http://www.lingr.com/room/3yXhqKbfPy8 -- Come get help.