adhearsion/blather

I want to do some stress test using blather

paulhsu opened this issue · 2 comments

Hi,
I want to do some stress test using blather.

The following code I used.
My XMPP server is ejabberd.

require 'blather/client'
class Blather::Client
    def id
        @id 
    end 

    def id=(id)
        @id=id
    end 
end


client_number =2  

clients = Array.new
for i in 0..client_number
    client = Blather::Client.setup 'alice@paulhsu-desktop', 'test12345'
    client.id = i 
    client.register_handler(:ready) do
        puts "[#{client.id}]Connected!"
        puts "#{client.jid}" + client.object_id.to_s
    end 
    clients << client
end


EM.run do
    for i in 0..client_number
        puts clients[i].id.to_s + ' ' + clients[i].object_id.to_s
        clients[i].run
    end 
end

The following result seems strange.

0 11675800
1 11789420
2 11863280
[2]Connected!
alice@paulhsu-desktop/979870179133536002672969011863280
[2]Connected!
[2]Connected!alice@paulhsu-desktop/979870179133536002672969011863280

alice@paulhsu-desktop/979870179133536002672969011863280

why the client.id is 2?

Anything wrong in my code?

My test purpose is to establish a lot of login connection to sever in a short time.

Give this a try:

require 'blather/client/client'

class Blather::Client
  attr_accessor :id
end

NUM_CLIENTS = ENV.has_key?('NUM_CLIENTS') ? ENV['NUM_CLIENTS'].to_i : 2
JID = ENV['JID']
PW = ENV['PW']

clients = Array.new

puts "Creating #{NUM_CLIENTS} clients, connecting to #{JID}"

NUM_CLIENTS.times do |i|
  client = Blather::Client.setup JID, PW
  client.id = i
  client.register_handler :ready do
    puts "Client ID #{client.id} connected with JID #{client.jid}!"
  end
  clients << client
end

puts "Connecting clients"

EM.run do
  clients.each do |client|
    puts "Running client #{client.id}"
    client.run
  end
end
{14:51}[ruby-1.9.3]~/Desktop ben% NUM_CLIENTS=5 JID=benlangfeld@jabber.org PW=***** ruby blather_stress.rb
Creating 5 clients, connecting to benlangfeld@jabber.org
Connecting clients
Running client 0
Running client 1
Running client 2
Running client 3
Running client 4
Client ID 1 connected with JID benlangfeld@jabber.org/c37a29e85e14fefd!
Client ID 0 connected with JID benlangfeld@jabber.org/475df859ef698d1e!
Client ID 2 connected with JID benlangfeld@jabber.org/2a035a01d9ee1197!
Client ID 3 connected with JID benlangfeld@jabber.org/49b7e9d9889d4781!
Client ID 4 connected with JID benlangfeld@jabber.org/051930d33dd1b162!
^C/Users/ben/Developer/.rvm/gems/ruby-1.9.3-p0/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine': Interrupt
    from /Users/ben/Developer/.rvm/gems/ruby-1.9.3-p0/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
    from blather_stress.rb:26:in `<main>'