From: nobu@... Date: 2015-04-11T01:48:19+00:00 Subject: [ruby-core:68835] [Ruby trunk - Feature #11024] [PATCH] connect_nonblock supports "exception: false" Issue #11024 has been updated by Nobuyoshi Nakada. Description updated Seems working fine, but my results don't look better, on Ubuntu 14.10 on VirtualBox on OS X. nr = 5000 | user | system | total | real -----------------|----------:|----------:|----------:|-----------: default | 0.000000 | 0.290000 | 0.290000 |( 0.291610) exception: false | 0.000000 | 0.210000 | 0.210000 |( 0.218066) nr = 50000 | user | system | total | real -----------------|----------:|----------:|----------:|-----------: default | 0.010000 | 2.840000 | 2.850000 |( 4.859450) exception: false | 0.020000 | 2.340000 | 2.360000 |( 7.369629) ---------------------------------------- Feature #11024: [PATCH] connect_nonblock supports "exception: false" https://bugs.ruby-lang.org/issues/11024#change-52099 * Author: Eric Wong * Status: Open * Priority: Normal * Assignee: Nobuyoshi Nakada ---------------------------------------- This is for consistency with accept_nonblock arguments and gives a minor speedup from avoiding exceptions: Results: | user | system | total | real -----------------|----------:|----------:|----------:|-----------: default | 0.050000 | 0.100000 | 0.150000 |( 0.151307) exception: false | 0.030000 | 0.080000 | 0.110000 |( 0.108840) --------------------------------------------------- ~~~ruby require 'socket' require 'benchmark' require 'io/wait' require 'tmpdir' host = "127.#{rand 255}.#{rand 255}.#{rand(254) + 1}" serv = TCPServer.new(host, 0) nr = 5000 addr = serv.getsockname pid = fork do begin serv.accept.close rescue => e warn "#$$: #{e.message} (#{e.class})" end while true end at_exit { Process.kill(:TERM, pid) } serv.close Benchmark.bmbm do |x| x.report("default") do nr.times do s = Socket.new(:INET, :STREAM) s.setsockopt(:SOL_SOCKET, :SO_REUSEADDR, 1) begin s.connect_nonblock(addr) rescue IO::WaitWritable s.wait_writable end s.close end end x.report("exception: false") do nr.times do s = Socket.new(:INET, :STREAM) s.setsockopt(:SOL_SOCKET, :SO_REUSEADDR, 1) case s.connect_nonblock(addr, exception: false) when :wait_writable s.wait_writable end s.close end end end ~~~ ---Files-------------------------------- 0001-connect_nonblock-supports-exception-false.patch (9.14 KB) -- https://bugs.ruby-lang.org/