Testing Threads with connections

Hello there,

I've been trying to make a stress test generator in ruby for a New IO
echo server initially.

Mainly, the idea is try to generate as many connections as possible to
the echo server, and from time to time, send a string to the server and
receive it back.

I don't really have much experience in threads programming, and that's
the main reason to try it out.

For this script, I thought to open <N> threads, and in each thread, do a
loop and open <X> connections for each thread. I tried to use 100
threads and in each thread, open 100 connections. It runs fine, no
errors reported to me at all, but the echo server shows only ~1200
connections.

I've set up the OS settings with ulimit already (open files).

What do you guys think ? Any suggestions?

Here it goes:

-- code

#!/usr/bin/ruby
require 'socket'

if ARGV.length < 3
   puts "Use: $0 <Nr Threads> <Nr Conex> <timeout>"
   exit 1
else
   thrds=ARGV[0].to_i
   conec=ARGV[1].to_i
   tmout=ARGV[2].to_i
end

DEBUG=1
teststring="denao."
host="192.168.0.100"
port=50000
threads=[]

for num in (1 .. thrds)
    threads << Thread.new(num) { |loT|
      printf "Thread (%.0f) opening %.0f connections\n", loT.to_s,
conec.to_s
      sock = []
      conec.times do |i|
         if DEBUG==1
            printf "%.0f) Opening socket %.0f... ",loT.to_s,i
         end
         sock[i] = TCPsocket::open(host,port)
         if DEBUG==1
            print "done\n"
         end
      end

      while (1)
         conec.times do |j|
            if DEBUG==1
               printf "%.0f) Sending string on socket
%.0f...",loT.to_s,j
            end

            sock[j].send teststring, 128

            if DEBUG==1
               printf "done.\n%.0f) Waiting answer on socket
%.0f...",loT.to_s,j
            end

            tmp=sock[j].recv(128)

            if DEBUG==1
              if teststring == tmp
                  print "matched!\n"
              else
                  print "error!\n"
              end
            end

            if DEBUG==2
               printf "%.0f) Sleeping %.0fs\n",loT.to_s,tmout.to_s
            end
            sleep(tmout)
         end
      end
    }
end

threads.each { |aThread| aThread.join }

-- /code

···

--
Posted via http://www.ruby-forum.com/.

Insert this at the top of your script to see whether there are exceptions during connection creation:

Thread.abort_on_exception = true

Alternatively, wrap each thread's main processing body in a begin rescue end to print out exceptions. (Thinking about it I'd prefer the second approach anyway as it makes up for more robust software.) HTH

Kind regards

  robert

···

On 01.09.2006 02:16, Denis Vieira wrote:

Hello there,

I've been trying to make a stress test generator in ruby for a New IO echo server initially.

Mainly, the idea is try to generate as many connections as possible to the echo server, and from time to time, send a string to the server and receive it back.

I don't really have much experience in threads programming, and that's the main reason to try it out.

For this script, I thought to open <N> threads, and in each thread, do a loop and open <X> connections for each thread. I tried to use 100 threads and in each thread, open 100 connections. It runs fine, no errors reported to me at all, but the echo server shows only ~1200 connections.

I've set up the OS settings with ulimit already (open files).

What do you guys think ? Any suggestions?