Skip to content

Instantly share code, notes, and snippets.

@dubek
Created November 24, 2010 17:49
Show Gist options
  • Save dubek/714077 to your computer and use it in GitHub Desktop.
Save dubek/714077 to your computer and use it in GitHub Desktop.
require 'eventmachine'
CONNECTIONS = 250
done = 0
failed = 0
puts "Starting"
EM.run {
CONNECTIONS.times { |i|
begin
EM.connect('www.google.com',80) { |c|
p ['SUCCESS', i,c]
done += 1
EM.stop if (done+failed) >= CONNECTIONS
}
rescue => e
p ['FAIL', i, e]
failed += 1
EM.stop if (done+failed) >= CONNECTIONS
end
}
}
puts "Finished! done=#{done} failed=#{failed}"
$ uname -a
Linux sevenup 2.6.18-128.el5 #1 SMP Wed Jan 21 10:41:14 EST 2009 x86_64 x86_64 x86_64 GNU/Linux
$ ruby --version
ruby 1.9.1p378 (2010-01-10 revision 26273) [x86_64-linux]
$ ulimit -n
1024
$ ruby em_test.rb # with CONNECTIONS = 1200 inside em_test.rb
Starting
["SUCCESS", 0, #<EventMachine::Connection:0x0000000eebb2e8 @signature=2>]
["SUCCESS", 1, #<EventMachine::Connection:0x0000000eebad00 @signature=3>]
["SUCCESS", 2, #<EventMachine::Connection:0x0000000eeba7f8 @signature=4>]
["SUCCESS", 3, #<EventMachine::Connection:0x0000000eeba210 @signature=5>]
["SUCCESS", 4, #<EventMachine::Connection:0x0000000eeb9d08 @signature=6>]
["SUCCESS", 5, #<EventMachine::Connection:0x0000000eeb9800 @signature=7>]
["SUCCESS", 6, #<EventMachine::Connection:0x0000000eeb9330 @signature=8>]
["SUCCESS", 7, #<EventMachine::Connection:0x0000000eeb8f08 @signature=9>]
["SUCCESS", 8, #<EventMachine::Connection:0x0000000eeb8a38 @signature=10>]
["SUCCESS", 9, #<EventMachine::Connection:0x0000000eeb8530 @signature=11>]
["SUCCESS", 10, #<EventMachine::Connection:0x0000000eeb7fb8 @signature=12>]
["SUCCESS", 11, #<EventMachine::Connection:0x0000000eeb7a40 @signature=13>]
["SUCCESS", 12, #<EventMachine::Connection:0x0000000eeb7570 @signature=14>]
...
...
...
["SUCCESS", 1013, #<EventMachine::Connection:0x0000000f1569d8 @signature=1015>]
["SUCCESS", 1014, #<EventMachine::Connection:0x0000000f1565b0 @signature=1016>]
["SUCCESS", 1015, #<EventMachine::Connection:0x0000000f156188 @signature=1017>]
["SUCCESS", 1016, #<EventMachine::Connection:0x0000000f155d60 @signature=1018>]
["SUCCESS", 1017, #<EventMachine::Connection:0x0000000f155938 @signature=1019>]
["SUCCESS", 1018, #<EventMachine::Connection:0x0000000f155510 @signature=1020>]
["FAIL", 1019, #<EventMachine::ConnectionError: unable to resolve server address>]
["FAIL", 1020, #<EventMachine::ConnectionError: unable to resolve server address>]
["FAIL", 1021, #<EventMachine::ConnectionError: unable to resolve server address>]
["FAIL", 1022, #<EventMachine::ConnectionError: unable to resolve server address>]
["FAIL", 1023, #<EventMachine::ConnectionError: unable to resolve server address>]
["FAIL", 1024, #<EventMachine::ConnectionError: unable to resolve server address>]
["FAIL", 1025, #<EventMachine::ConnectionError: unable to resolve server address>]
["FAIL", 1026, #<EventMachine::ConnectionError: unable to resolve server address>]
...
...
...
["FAIL", 1195, #<EventMachine::ConnectionError: unable to resolve server address>]
["FAIL", 1196, #<EventMachine::ConnectionError: unable to resolve server address>]
["FAIL", 1197, #<EventMachine::ConnectionError: unable to resolve server address>]
["FAIL", 1198, #<EventMachine::ConnectionError: unable to resolve server address>]
["FAIL", 1199, #<EventMachine::ConnectionError: unable to resolve server address>]
Finished! done=1019 failed=181
$ uname -a
Darwin singha 10.4.1 Darwin Kernel Version 10.4.1: Wed May 12 21:36:54 PDT 2010; root:xnu-1504.7.50~2/RELEASE_I386 i386
$ ruby --version
ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-darwin10.4.1]
$ ulimit -n
256
$ ruby em_test.rb
Starting
["SUCCESS", 0, #<EventMachine::Connection:0x00000100903030 @signature=2>]
["SUCCESS", 1, #<EventMachine::Connection:0x00000100902bd0 @signature=3>]
["SUCCESS", 2, #<EventMachine::Connection:0x000001009027a8 @signature=4>]
["SUCCESS", 3, #<EventMachine::Connection:0x00000100902380 @signature=5>]
["SUCCESS", 4, #<EventMachine::Connection:0x00000100901f20 @signature=6>]
["SUCCESS", 5, #<EventMachine::Connection:0x00000100901af8 @signature=7>]
["SUCCESS", 6, #<EventMachine::Connection:0x00000100901660 @signature=8>]
["SUCCESS", 7, #<EventMachine::Connection:0x000001008f4230 @signature=9>]
["SUCCESS", 8, #<EventMachine::Connection:0x000001008f2f28 @signature=10>]
["SUCCESS", 9, #<EventMachine::Connection:0x000001008eae50 @signature=11>]
["SUCCESS", 10, #<EventMachine::Connection:0x000001008e9f70 @signature=12>]
["SUCCESS", 11, #<EventMachine::Connection:0x000001008e8ae0 @signature=13>]
["SUCCESS", 12, #<EventMachine::Connection:0x000001008e7d50 @signature=14>]
["SUCCESS", 13, #<EventMachine::Connection:0x000001008e7378 @signature=15>]
...
...
...
["SUCCESS", 238, #<EventMachine::Connection:0x0000010104df98 @signature=240>]
["SUCCESS", 239, #<EventMachine::Connection:0x0000010104d9b0 @signature=241>]
["SUCCESS", 240, #<EventMachine::Connection:0x0000010104d4e0 @signature=242>]
["SUCCESS", 241, #<EventMachine::Connection:0x0000010104cde0 @signature=243>]
["SUCCESS", 242, #<EventMachine::Connection:0x0000010104c2f0 @signature=244>]
["SUCCESS", 243, #<EventMachine::Connection:0x0000010104be90 @signature=245>]
["SUCCESS", 244, #<EventMachine::Connection:0x0000010104b9f8 @signature=246>]
["SUCCESS", 245, #<EventMachine::Connection:0x0000010104b5d0 @signature=247>]
["SUCCESS", 246, #<EventMachine::Connection:0x0000010104b138 @signature=248>]
["SUCCESS", 247, #<EventMachine::Connection:0x0000010104abc0 @signature=249>]
here the process hangs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment