Project

General

Profile

Actions

Bug #806

closed

Net::Protocol#rbuf_fill is slow

Added by tenderlovemaking (Aaron Patterson) about 16 years ago. Updated over 13 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
Backport:
[ruby-core:20191]

Description

=begin
Net::Protocol#rbuf_fill is slow. We can take advantage of io.read_nonblock and IO.select to deal with timeouts.

I've attached a patch.
=end


Files

protocol.patch (629 Bytes) protocol.patch Patch to make Net::Protocol faster tenderlovemaking (Aaron Patterson), 12/02/2008 03:27 AM
Actions #1

Updated by matz (Yukihiro Matsumoto) about 16 years ago

=begin
merged. report if any problem caused by this patch.
=end

Actions #2

Updated by matz (Yukihiro Matsumoto) about 16 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
Applied in changeset r20443.
=end

Actions #3

Updated by bitsweat (Jeremy Daer) almost 16 years ago

=begin
Breaks if the IO doesn't respond to read_nonblock. StringIO, for example. Fall back to sysread in that case:

Index: lib/net/protocol.rb

--- lib/net/protocol.rb (revision 22024)
+++ lib/net/protocol.rb (working copy)
@@ -131,14 +131,20 @@
BUFSIZE = 1024 * 16

  def rbuf_fill
  •  begin
    
  •    @rbuf << @io.read_nonblock(BUFSIZE)
    
  •  rescue Errno::EWOULDBLOCK
    
  •    if IO.select([@io], nil, nil, @read_timeout)
    
  •      retry
    
  •    else
    
  •      raise Timeout::TimeoutError
    
  •  if @io.respond_to?(:read_nonblock)
    
  •    begin
    
  •      @rbuf << @io.read_nonblock(BUFSIZE)
    
  •    rescue Errno::EWOULDBLOCK
    
  •      if IO.select([@io], nil, nil, @read_timeout)
    
  •        retry
    
  •      else
    
  •        raise Timeout::TimeoutError
    
  •      end
       end
    
  •  else
    
  •    timeout(@read_timeout) do
    
  •      @rbuf << @io.sysread(BUFSIZE)
    
  •    end
     end
    
    end

=end

Actions #4

Updated by matthewford (Matthew Ford) almost 16 years ago

=begin
I can confirm that Jeremy Kemper's patch works for me and that the patch that was applied breaks IO that doesn't respond to read_nonblock.
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0