mqbench 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 826251928967d9031b8ea764630aa77d5769f6aa
4
+ data.tar.gz: fd37f71e8b877d912a88a3ba445507533d0be79d
5
+ SHA512:
6
+ metadata.gz: 7645e6aa88910a3587e868d728cf2f92b3cf875f059ad5bb5e5ade010528b60f0d5401d12aaf2e073b5b51ae1e4c5c2694b98fea3eb0eb8859602a4a4776c164
7
+ data.tar.gz: a1373c857a426792411fc48fc3d67681077f03cbff218f3f1b779c24a900dbeb6c213d7a827397b09ba3b00cd546f05644d1ae0210e66b508df63b4734382417
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *gem
11
+ *swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mqbench.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Hiroyasu OHYAMA
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,14 @@
1
+ ## What is this?
2
+ This is a benchmark script to measure trend of pub/sub processing throughput at AMQP and STOMP server environment.
3
+
4
+ ## Usage
5
+ ```
6
+ Usage: benchmark [options]
7
+ -m, --mode m specify benchmark mode ('amqp' or 'stomp')
8
+ -s, --size s specify message size
9
+ -c, --count c specify message counts
10
+ -u, --user p specify user-id to login broker
11
+ -w, --pass w specify password to login broker
12
+ -h, --host h specify host of server
13
+ -p, --port p specify TCP port-number which is listened
14
+ ```
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'mqbench'
4
+
5
+ opts = MQBench::Options.new(ARGV)
6
+ unless opts.is_valid?
7
+ opts.show_usage
8
+ puts "[warning] 'mandatory' options is required"
9
+ exit 1
10
+ end
11
+
12
+ MQBench.run(opts.conf)
@@ -0,0 +1,36 @@
1
+ require "mqbench/version"
2
+ require "mqbench/options"
3
+ require "mqbench/client"
4
+ require "mqbench/amqp"
5
+ require "mqbench/stomp"
6
+ require "mqbench/kafka"
7
+
8
+ module MQBench
9
+ def self.run(args)
10
+ obj = case args[:mode]
11
+ when 'amqp'
12
+ MQBench::AMQP.new(args)
13
+ when 'stomp'
14
+ MQBench::STOMP.new(args)
15
+ when 'kafka'
16
+ MQBench::Kafka.new(args)
17
+ else
18
+ puts "[warning] The specified mode '#{args[:mode]}' is invalid"
19
+ nil
20
+ end
21
+
22
+ if obj != nil
23
+ time_started = Time.now
24
+
25
+ obj.send_msg
26
+
27
+ time_enqueued = Time.now
28
+
29
+ obj.recv_msg
30
+
31
+ time_dequeued = Time.now
32
+
33
+ puts "results: #{time_dequeued - time_started} (enqueue:#{time_enqueued - time_started}, dequeue:#{time_dequeued - time_enqueued})"
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,43 @@
1
+ require 'bunny'
2
+
3
+ module MQBench
4
+ class AMQP < Client
5
+ def initialize(args)
6
+ @port = 5672
7
+ @user = 'guest'
8
+ @pass = 'guest'
9
+
10
+ super(args)
11
+
12
+ @broker = Bunny.new(:host => @host, :port => @port, :user => @user, :pass => @pass)
13
+ @broker.start
14
+ end
15
+
16
+ def send_msg
17
+ ch = @broker.create_channel
18
+ q = ch.queue(QNAME)
19
+
20
+ (1..@count).each do |_|
21
+ q.publish('a' * @size)
22
+ end
23
+
24
+ ch.close
25
+ end
26
+
27
+ def recv_msg
28
+ ch = @broker.create_channel
29
+ q = ch.queue(QNAME)
30
+
31
+ cnt = 0
32
+ q.subscribe(:block => true) do |delivery_info, _, _|
33
+ cnt += 1
34
+ if cnt >= @count
35
+ delivery_info.consumer.cancel
36
+ break
37
+ end
38
+ end
39
+
40
+ ch.close
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,14 @@
1
+ module MQBench
2
+ class Client
3
+ QNAME = "benchmark9-#{(rand * 10000).to_i}"
4
+
5
+ def initialize(args = {})
6
+ @size = args[:size] if args.key? :size
7
+ @host = args[:host] if args.key? :host
8
+ @port = args[:port] if args.key? :port
9
+ @user = args[:user] if args.key? :user
10
+ @pass = args[:pass] if args.key? :pass
11
+ @count = args[:count] if args.key? :count
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,44 @@
1
+ require 'kafka'
2
+
3
+ module MQBench
4
+ class Kafka < Client
5
+ def initialize(args)
6
+ @port = 9092
7
+ @host = 'localhost'
8
+
9
+ super(args)
10
+
11
+ @broker = ::Kafka.new(seed_brokers: ["#{@host}:#{@port}"])
12
+ end
13
+
14
+ def send_msg
15
+ producer = @broker.producer(:required_acks => 0,
16
+ :max_buffer_size => (@count * @size),
17
+ :max_buffer_bytesize => (@count * (@size + 100)))
18
+
19
+ (1..@count).each do |x|
20
+ producer.produce('a' * @size, topic: QNAME)
21
+ producer.deliver_messages
22
+ end
23
+
24
+ producer.shutdown
25
+ end
26
+
27
+ def recv_msg
28
+ consumer = @broker.consumer(group_id: 'test')
29
+
30
+ # It's possible to subscribe to multiple topics by calling `subscribe`
31
+ # repeatedly.
32
+ consumer.subscribe(QNAME)
33
+
34
+ # This will loop indefinitely, yielding each message in turn.
35
+ current = 1
36
+ consumer.each_message do |message|
37
+ current += 1
38
+ if(current >= @count)
39
+ break
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,37 @@
1
+ require 'optparse'
2
+
3
+ module MQBench
4
+ class Options
5
+ MANDATORY_OPTS = [:mode, :size, :count]
6
+
7
+ attr_reader :conf
8
+
9
+ def initialize(argv)
10
+ @opt = OptionParser.new
11
+ @conf = {}
12
+
13
+ @opt.on("-m m", "--mode m", "[mandatory] broker type {amqp|stomp|kafka}") {|v| @conf[:mode] = v}
14
+ @opt.on("-s s", "--size s", "[mandatory] message size (bytes)") {|v| @conf[:size] = v.to_i}
15
+ @opt.on("-c c", "--count c", "[mandatory] message counts") {|v| @conf[:count] = v.to_i}
16
+ @opt.on("-u u", "--user p", "specify user-id to login broker") {|v| @conf[:user] = v}
17
+ @opt.on("-w w", "--pass w", "specify password to login broker") {|v| @conf[:pass] = v}
18
+ @opt.on("-h h", "--host h", "specify host where broker is running") {|v| @conf[:host] = v}
19
+ @opt.on("-p p", "--port p", "specify TCP port-number which broker listens") {|v| @conf[:port] = v.to_i}
20
+
21
+ begin
22
+ @opt.parse!(argv)
23
+ rescue OptionParser::MissingArgument => e
24
+ puts @opt.help
25
+ exit 1
26
+ end
27
+ end
28
+
29
+ def is_valid?
30
+ not MANDATORY_OPTS.map {|x| @conf.key? x}.include?(false)
31
+ end
32
+
33
+ def show_usage
34
+ puts @opt.help
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,34 @@
1
+ require 'stomp'
2
+
3
+ module MQBench
4
+ class STOMP < Client
5
+ def initialize(args)
6
+ @port = 61613
7
+ @user = 'guest'
8
+ @pass = 'guest'
9
+
10
+ super(args)
11
+
12
+ @broker = Stomp::Connection.open(@user, @pass, @host, @port)
13
+ end
14
+
15
+ def send_msg
16
+ (1..@count).each do |x|
17
+ @broker.publish(QNAME, 'a' * @size)
18
+ end
19
+ end
20
+
21
+ def recv_msg
22
+ @broker.subscribe(QNAME, {:ack => 'client'})
23
+ cnt = 0
24
+ loop do
25
+ @broker.receive
26
+
27
+ cnt += 1
28
+ if cnt >= @count
29
+ break
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module Mqbench
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mqbench/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mqbench"
8
+ spec.version = Mqbench::VERSION
9
+ spec.authors = ["Hiroyasu OHYAMA"]
10
+ spec.email = ["user.localhost2000@gmail.com"]
11
+
12
+ spec.summary = %q{A benchmark client for MOM}
13
+ spec.description = %q{This aims to be a common benchmark tool for MOM}
14
+ spec.homepage = "https://github.com/userlocalhost2000/mqbench"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "bin"
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "stomp", "~> 1.3"
23
+ spec.add_runtime_dependency "bunny", "~> 2.3"
24
+ spec.add_runtime_dependency "ruby-kafka", "~> 0.3.6"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.10"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.4"
29
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mqbench
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Hiroyasu OHYAMA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: stomp
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bunny
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ruby-kafka
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.3.6
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.3.6
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.4'
97
+ description: This aims to be a common benchmark tool for MOM
98
+ email:
99
+ - user.localhost2000@gmail.com
100
+ executables:
101
+ - mqbench
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/mqbench
111
+ - lib/mqbench.rb
112
+ - lib/mqbench/amqp.rb
113
+ - lib/mqbench/client.rb
114
+ - lib/mqbench/kafka.rb
115
+ - lib/mqbench/options.rb
116
+ - lib/mqbench/stomp.rb
117
+ - lib/mqbench/version.rb
118
+ - mqbench.gemspec
119
+ homepage: https://github.com/userlocalhost2000/mqbench
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.4.5
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: A benchmark client for MOM
143
+ test_files: []
144
+ has_rdoc: