From: "Jesús Gabriel y Galán" Date: 2010-04-07T23:54:08+09:00 Subject: Re: Maximum number of sockets On Wed, Apr 7, 2010 at 1:34 PM, Brian Candler wrote: > Jesús Gabriel y Galán wrote: >> Oh, ok. So this means that a ruby program cannot (or shouldn't be able >> to) open more than 1024 sockets? > > Yes, unless they are handled outside of the ruby core, e.g. by > eventmachine or Rev. But if you're going to that trouble you might as > well use a language better suited to the job, e.g. erlang, so your idea > of forking multiple processes makes sense. I did this: #!/bin/bash for i in {1..25} do ruby ./nginx_client.rb $i & done read pkill -f "ruby ./nginx_client.rb" #nginx_client.rb require 'socket' include Socket::Constants id = ARGV[0] || "N/A" sockets = [] 1000.times do |i| socket = Socket.new(AF_INET, SOCK_STREAM, 0) sockaddr = Socket.pack_sockaddr_in(80, '127.0.0.1') socket.connect(sockaddr) sockets << socket end puts "[#{id}] All sockets connected (#{sockets.size})" sleep and I sucessfully managed to open 25000 sockets to the server, which handled this really nicely taking nearly 0 cpu and only 23 MB of memory. Thanks, Jesus.