From: Brian Candler Date: 2008-12-24T18:47:49+09:00 Subject: Re: Net::HTTPResponse#read_body usable for timing? Denis Haskin wrote: > Does anyone know if read_body is synchronous wrt to the network reads? The source will be installed somewhere like /usr/lib/ruby/1.8/net/http.rb - it's all in Ruby and fairly easy to understand. Look for read_body and read_body_0. However, you can see it relies on some Ruby internals, such as Socket#read calling << on the dest buffer object; see ReadAdapter in net/protocol.rb (*) Basically, you'll get a separate Socket#read call for each chunk if you're getting HTTP/1.1 chunked encoding for your result body, and a single Socket#read call for non-chunked with Content-Length. tcpdump should show what you're actually getting. What I don't know is, if you do Socket#read(1_000_000, dest) is whether Ruby breaks the read up into smaller ones and calls << onto dest for each chunk, and if so, what buffer size it's using. That would involve looking at the C source code. HTH, Brian. (*) In fact Net::HTTP violates Ruby's own documentation, which says explicitly that the result buffer may only be a String object. ---------------------------------------------------------------- IO#read ios.read([length [, buffer]]) => string, buffer, or nil ------------------------------------------------------------------------ Reads at most _length_ bytes from the I/O stream, or to the end of file if _length_ is omitted or is +nil+. _length_ must be a non-negative integer or nil. If the optional _buffer_ argument is present, it must reference a String, which will receive the data. -- Posted via http://www.ruby-forum.com/.