Permalink
Browse files

Add rabbitmq bandwidth rate test

Change-Id: I5e2f6e1260fdc5ba263a5233bf3ae81cc0056cc7
  • Loading branch information...
1 parent 9d6eb68 commit b21d9f66111366a2a721b3f677190ddde51fdbb6 @andyzh andyzh committed Nov 20, 2012
Showing with 26 additions and 1 deletion.
  1. +26 −1 sinatra/app_sinatra_service_quota/main.rb
@@ -537,6 +537,31 @@
end
end
+# publish to rabbit service to test the bandwidth rate
+post '/service/rabbitmq/bandwidth/:megabytes' do
+ e1 = nil
+ number = params[:megabytes].to_f
+ begin
+ client = load_rabbitmq
+ client.start
+ q = client.queue("test1")
+ e = client.exchange("")
+ data = prepare_data(number)
+ start = Time.now
+ ret = e.publish(data, :key => 'test1')
+ client.stop
+ cost = (Time.now - start).to_i
+ rescue => e
+ e1 = e
+ end
+
+ if e1
+ "#{e1}"
+ else
+ "ok-#{cost}"
+ end
+end
+
post '/service/vblob/:bucket' do
e1 = nil
begin
@@ -667,7 +692,7 @@ def db_name
end
def prepare_data(size)
- b = size * 1024 * 1024
+ b = (size * 1024 * 1024).to_i
c = [('a'..'z'),('A'..'Z')].map{|i| Array(i)}.flatten
(0..b).map{ c[rand(c.size)] }.join
end

0 comments on commit b21d9f6

Please sign in to comment.