Project

General

Profile

Actions

Feature #9091

closed

[PATCH] accept_nonblock supports "exception: false"

Added by normalperson (Eric Wong) over 10 years ago. Updated almost 5 years ago.

Status:
Closed
Target version:
-
[ruby-core:58211]

Description

git pull git://bogomips.org/ruby.git accept_nonblock-noraise

This is analogous to functionality found in IO#read_nonblock and
IO#wait_nonblock. Raising exceptions for common failures on
non-blocking servers is expensive and makes $DEBUG too noisy.

Benchmark results:
user system total real
default 2.530000 0.970000 3.500000 ( 3.492550)
exception: false 0.820000 0.910000 1.730000 ( 1.741821)
exception: false (cached arg) 0.670000 0.910000 1.580000 ( 1.583128)

--------------------- benchmark script ------------------------
require 'socket'
require 'benchmark'
s = TCPServer.new("localhost", 0)
nr = 1000000
Benchmark.bmbm do |x|
x.report("default") do
nr.times do
begin
s.accept_nonblock
rescue IO::WaitReadable
end
end
end
x.report("exception: false") do
nr.times do
begin
s.accept_nonblock(exception: false)
rescue IO::WaitReadable
abort "should not raise"
end
end
end
x.report("exception: false (cached arg)") do
arg = { exception: false }
nr.times do
begin
s.accept_nonblock(arg)
rescue IO::WaitReadable
abort "should not raise"
end
end
end
end

I also plan on doing others like recv,send,connect, too


Files

Updated by hsbt (Hiroshi SHIBATA) about 10 years ago

  • Target version changed from 2.1.0 to 2.2.0
Actions #2

Updated by naruse (Yui NARUSE) over 6 years ago

  • Target version deleted (2.2.0)

Updated by jeremyevans0 (Jeremy Evans) almost 5 years ago

  • Tracker changed from Bug to Feature
  • Status changed from Open to Closed
  • ruby -v deleted (ruby 2.1.0dev (2013-11-07 trunk 43560) [x86_64-linux])
  • Backport deleted (1.9.3: UNKNOWN, 2.0.0: UNKNOWN)

accept_nonblock started support exception: false in Ruby 2.3:

$ ruby22 -r socket -e 'p TCPServer.new(10001).accept_nonblock(exception: false)'
-e:1:in `accept_nonblock': wrong number of arguments (1 for 0) (ArgumentError)
        from -e:1:in `<main>'
$ ruby23 -r socket -e 'p TCPServer.new(10001).accept_nonblock(exception: false)'
:wait_readable

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0