From: "normalperson (Eric Wong)" Date: 2013-11-07T12:33:11+09:00 Subject: [ruby-core:58211] [ruby-trunk - Bug #9091][Open] [PATCH] accept_nonblock supports "exception: false" Issue #9091 has been reported by normalperson (Eric Wong). ---------------------------------------- Bug #9091: [PATCH] accept_nonblock supports "exception: false" https://bugs.ruby-lang.org/issues/9091 Author: normalperson (Eric Wong) Status: Open Priority: Low Assignee: akr (Akira Tanaka) Category: ext Target version: current: 2.1.0 ruby -v: ruby 2.1.0dev (2013-11-07 trunk 43560) [x86_64-linux] Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN 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 -- http://bugs.ruby-lang.org/