<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -32,22 +32,31 @@
 require &quot;rubygems&quot;
 require &quot;qpid&quot;
 require 'getoptlong'
+require 'math/statistics'
+
+class Array
+  include Math::Statistics
+end
+
 
 module BunnyPunisher
   
-  ITEMS_PER_ITERATION = 1000
-  MAX_ITERATIONS = 10
+  ITEMS_PER_ITERATION = 100
+  MAX_ITERATIONS = 1
   EMPTY_HEADER = {}
   
-  def self.connect
+  def self.get_timestamp
+	&quot;%.10f&quot; % Time.now.to_f
+  end
+  
+  def self.connect(host)
     spec  = &quot;#{Gem.loaded_specs['colinsurprenant-qpid'].full_gem_path}/specs/official-amqp0-8.xml&quot;
-    host  = '127.0.0.1'
     port  = 5672
     vhost = '/'
     user  = 'guest'
     pass  = 'guest'
             
-    puts(&quot;connecting to #{host}:#{port} on vhost #{vhost} with user=#{user}, pass=#{pass}&quot;)
+    #puts(&quot;connecting to #{host}:#{port} on vhost #{vhost} with user=#{user}, pass=#{pass}&quot;)
 
     client = Qpid::Client.new(host, port, Qpid::Spec::Loader.build(spec), vhost)
     client.start({ &quot;LOGIN&quot; =&gt; user, &quot;PASSWORD&quot; =&gt; pass })
@@ -58,25 +67,26 @@ module BunnyPunisher
   end
   
   def self.close(channel, client)
-    puts(&quot;closing channel and client&quot;)
+    #puts(&quot;closing channel and client&quot;)
 
     channel.channel_close
     client.close
   end
   
   def self.qpid_publish(channel, key, data)
-    c = Qpid::Content.new(EMPTY_HEADER, Marshal.dump(data))
+	timestamp  = get_timestamp
+    c = Qpid::Content.new(EMPTY_HEADER, Marshal.dump(timestamp+&quot;,&quot;+data))
     channel.basic_publish(:routing_key =&gt; key.to_s, :content =&gt; c, :exchange =&gt; 'amq.direct')    
   end
   
   def self.bench
     time_start = Time.now    
     yield
-    puts(&quot;sent #{ITEMS_PER_ITERATION} in #{(Time.now - time_start).to_s} sec&quot;)
+    #puts(&quot;sent #{ITEMS_PER_ITERATION} in #{(Time.now - time_start).to_s} sec&quot;)
   end
             
   def self.publish(channel, key, value)
-    puts(&quot;publishing on queue=#{key}, data=#{value.to_s}&quot;)
+    #puts(&quot;publishing on queue=#{key}, bytes=#{value.length + 22} &quot;)
 
     (1..MAX_ITERATIONS).each do
       self.bench do
@@ -84,15 +94,16 @@ module BunnyPunisher
         (1..ITEMS_PER_ITERATION).each { self.qpid_publish(channel, key, value) }
         self.qpid_publish(channel, key, &quot;end&quot;)
       end
-      sleep(2) # allow qpid queues to empty
+      sleep(1) # allow qpid queues to empty
     end
     
     self.qpid_publish(channel, key, &quot;stop&quot;)    
   end
   
   def self.consume(channel, client, key)
-    puts(&quot;consuming on queue=#{key}&quot;)
-    
+    #puts(&quot;consuming on queue=#{key}&quot;)
+    messages = Array.new
+	
     channel.queue_declare(:queue =&gt; key)
     channel.queue_bind(:queue_name =&gt; key, :exchange =&gt; 'amq.direct')
     bc = channel.basic_consume(:queue =&gt; key)
@@ -104,40 +115,62 @@ module BunnyPunisher
       message = queue.pop(non_block = false)
       channel.basic_ack(message.delivery_tag)
       value = Marshal.load(message.content.body) 
-#      puts(&quot;received value=#{value.inspect}&quot;)
+      #puts(&quot;received value=#{value.inspect}&quot;)
       
-      case value
-      when &quot;begin&quot;
-        i = 0
-        time_start = Time.now
-      when &quot;end&quot;
-        puts(&quot;received #{i - 1} in #{(Time.now - time_start).to_s} sec&quot;)
-      end
-    
-      i += 1
-      break if value == &quot;stop&quot;
+	  
+	  messages &lt;&lt;  value + &quot;,&quot; + get_timestamp	  
+      diff = Array.new
+      if value.include? &quot;stop&quot; then
+		messages.each {|m|  
+			t1 = Time.at(m.split(&quot;,&quot;)[0].to_f)
+			t2 = Time.at(m.split(&quot;,&quot;)[2].to_f)
+			diff &lt;&lt; (t2-t1).to_s.to_f
+		}
+		
+		puts(&quot;avg=#{diff.avg}, std=#{diff.std}&quot;)
+		break
+	  end
     end
   end
 
   def self.main
     opts = GetoptLong.new(
       [ '--consumer', '-c', GetoptLong::NO_ARGUMENT ],
-      [ '--publisher', '-p', GetoptLong::NO_ARGUMENT ]
+      [ '--publisher', '-p', GetoptLong::NO_ARGUMENT ],
+	  [ '--queuename', '-q', GetoptLong::REQUIRED_ARGUMENT],
+	  [ '--host', '-h', GetoptLong::REQUIRED_ARGUMENT],
+	  [ '--bytes', '-b', GetoptLong::REQUIRED_ARGUMENT]
     )
 
-    mode = :consumer # default
+	#new default options
+	host  = '192.168.1.1'
+    mode  = :consumer 
+	queue = &quot;test_queue&quot; 
+	bytes = 100
+	data  = &quot;&quot;
+	
+	
     opts.each do |opt, arg|
       case opt
         when '--consumer'
           mode = :consumer
         when '--publisher'
           mode = :publisher
+		when '--queuename'
+		  queue = arg.to_s
+		when '--host'
+		  host = arg.to_s
+		when '--bytes'
+		  if bytes &lt; get_timestamp.length + 1 then 
+			bytes = get_timestamp.length + 1
+		  end
+		  bytes = arg.to_i - get_timestamp.length + 1
       end
     end
-
-    channel, client = connect
-    key = &quot;test_queue&quot;
-    data = &quot;test data&quot;
+		
+    channel, client = connect(host)
+    key = queue
+    bytes.times do data.concat(&quot;a&quot;) end
     
     case mode
     when :consumer
@@ -150,6 +183,6 @@ module BunnyPunisher
   end
 end
 
-puts(&quot;starting Qpid Punisher&quot;)
+#puts(&quot;starting Qpid Punisher&quot;)
 BunnyPunisher::main
-puts(&quot;exiting Qpid Punisher&quot;)
\ No newline at end of file
+#puts(&quot;exiting Qpid Punisher&quot;)
\ No newline at end of file</diff>
      <filename>qpid_punisher.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>6bba970cd1b3cfa2e6ed7f969e8796b9cf0dc795</id>
    </parent>
  </parents>
  <author>
    <name>unknown</name>
    <email>sheheryar@.office</email>
  </author>
  <url>http://github.com/sheysrebellion/bunnypunisher/commit/6160b0d8e57f78bc6e0f361f6f52581b2afd6d6a</url>
  <id>6160b0d8e57f78bc6e0f361f6f52581b2afd6d6a</id>
  <committed-date>2009-06-24T04:38:06-07:00</committed-date>
  <authored-date>2009-06-24T04:38:06-07:00</authored-date>
  <message>initial commit</message>
  <tree>7d8cfa3d6e285f05f96eeb4d867a282574caccf3</tree>
  <committer>
    <name>unknown</name>
    <email>sheheryar@.office</email>
  </committer>
</commit>
