-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source :rubygems | ||
|
||
gem 'em-couchbase', '~> 0.9.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
addressable (2.2.7) | ||
cookiejar (0.3.0) | ||
em-couchbase (0.9.0) | ||
em-http-request (~> 1.0.1) | ||
yajl-ruby (~> 1.1.0) | ||
em-http-request (1.0.2) | ||
addressable (>= 2.2.3) | ||
cookiejar | ||
em-socksify | ||
eventmachine (>= 1.0.0.beta.4) | ||
http_parser.rb (>= 0.5.3) | ||
em-socksify (0.1.0) | ||
eventmachine | ||
eventmachine (1.0.0.beta.4) | ||
http_parser.rb (0.5.3) | ||
yajl-ruby (1.1.0) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
em-couchbase (~> 0.9.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# em-couchbase-loader | ||
|
||
This script helps to measure performance of the [em-couchbase][1] gem. | ||
|
||
## Setup | ||
|
||
Clone repository: | ||
|
||
$ git clone git://github.com/avsej/em-couchbase-loader.git | ||
|
||
Install dependencies, using bundler: | ||
|
||
$ cd em-couchbase-loader | ||
$ bundle install | ||
|
||
|
||
## Usage | ||
|
||
To show available options run script with `-?` argument: | ||
|
||
$ ./run.rb --help | ||
Usage: ./run.rb [options] | ||
-c, --concurrency NUM Use NUM processes to run the test (default: 1) | ||
-n, --operations NUM Number of operations (default: 100) | ||
-r, --ratio RATIO The ratio if set/get operations (default: 0.5) | ||
-h, --hostname HOSTNAME Hostname to connect to (default: nil) | ||
-b, --bucket NAME Name of the bucket to connect to (default: "default") | ||
-u, --user USERNAME Username to log with (default: none) | ||
-p, --passwd PASSWORD Password to log with (default: none) | ||
-?, --help Show this message | ||
|
||
## License | ||
|
||
Author:: Couchbase <info@couchbase.com> | ||
Copyright:: 2012 Couchbase, Inc. | ||
License:: Apache License, Version 2.0 | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
|
||
[1]: https://github.com/avsej/couchbase-ruby-client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
#!/usr/bin/env ruby | ||
# Author:: Couchbase <info@couchbase.com> | ||
# Copyright:: 2012 Couchbase, Inc. | ||
# License:: Apache License, Version 2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
require 'rubygems' | ||
begin | ||
require 'bundler/setup' | ||
rescue LoadError | ||
# don't worry if bundler isn't available | ||
# the script could be installed somewhere in PATH | ||
end | ||
require 'em-couchbase' | ||
require 'optparse' | ||
require 'logger' | ||
|
||
options = { | ||
:host => "127.0.0.1:8091", | ||
:bucket => "default", | ||
:concurrency => 1, | ||
:ratio => 0.5, | ||
:operations => 10_000, | ||
:prefix => 'em-couchbase:', | ||
:size => 256, | ||
:slice => 1_000, | ||
:tick => 1 | ||
} | ||
|
||
LOGGER = Logger.new(STDOUT) | ||
|
||
trap("INT") do | ||
LOGGER.info("Caught SIGINT. Terminating...") | ||
exit | ||
end | ||
|
||
OptionParser.new do |opts| | ||
opts.banner = "Usage: #{__FILE__} [options]" | ||
opts.on("-t", "--tick SECONDS", "The interval for timer (default: #{options[:tick].inspect})") do |v| | ||
options[:tick] = v.to_i | ||
end | ||
opts.on("-S", "--slice NUM", "The number of operation scheduled each timer occurence (default: #{options[:slice].inspect})") do |v| | ||
options[:slice] = v.to_i | ||
end | ||
opts.on("-P", "--prefix PREFIX", "The prefix used for keys (default: #{options[:prefix].inspect})") do |v| | ||
options[:prefix] = v.to_i | ||
end | ||
opts.on("-c", "--concurrency NUM", "Use NUM processes to run the test (default: #{options[:concurrency].inspect})") do |v| | ||
options[:concurrency] = v.to_i | ||
end | ||
opts.on("-n", "--operations NUM", "Number of operations (default: #{options[:operations].inspect})") do |v| | ||
options[:operations] = v.to_i | ||
end | ||
opts.on("-r", "--ratio RATIO", "The percent of GETs from 1 (default: #{options[:ratio].inspect})") do |v| | ||
options[:ratio] = v.to_f | ||
end | ||
opts.on("-s", "--size SIZE", "Number of bytes for values (default: #{options[:size].inspect})") do |v| | ||
options[:size] = v.to_i | ||
end | ||
opts.on("-h", "--hostname HOSTNAME", "Hostname to connect to (default: #{options[:hostname].inspect})") do |v| | ||
host, port = v.split(':') | ||
options[:hostname] = host.empty? ? '127.0.0.1' : host | ||
options[:port] = port.to_i > 0 ? port.to_i : 8091 | ||
end | ||
opts.on("-b", "--bucket NAME", "Name of the bucket to connect to (default: #{options[:bucket].inspect})") do |v| | ||
options[:bucket] = v.empty? ? "default" : v | ||
end | ||
opts.on("-u", "--user USERNAME", "Username to log with (default: none)") do |v| | ||
options[:user] = v | ||
end | ||
opts.on("-p", "--passwd PASSWORD", "Password to log with (default: none)") do |v| | ||
options[:passwd] = v | ||
end | ||
opts.on_tail("-?", "--help", "Show this message") do | ||
puts opts | ||
exit | ||
end | ||
end.parse! | ||
|
||
ops_per_fork = (options[:operations] / options[:concurrency].to_f).ceil | ||
forks = [] | ||
|
||
options[:concurrency].times do |n| | ||
forks << fork do | ||
$0 = "#{__FILE__}: fork ##{n}" | ||
value = $0.dup | ||
value << ('.' * (options[:size] - value.size)) | ||
|
||
EM.run do | ||
cc = EM::Protocols::Couchbase.connect | ||
on_complete = lambda do |ret| | ||
ops_per_fork -= 1 | ||
# case ret.operation | ||
# when :set | ||
# STDERR.print("s") | ||
# when :get | ||
# STDERR.print("g") | ||
# end | ||
EM.stop if ops_per_fork < 0 | ||
end | ||
on_tick = lambda do | ||
# STDERR.print(".") | ||
options[:slice].times do | ||
if rand > options[:ratio] | ||
cc.set("#{options[:prefix]}fork-#{n}:#{n % 10}", value, &on_complete) | ||
else | ||
cc.get("#{options[:prefix]}fork-#{n}:#{n % 10}", &on_complete) | ||
end | ||
end | ||
end | ||
EM.add_periodic_timer(options[:tick], &on_tick) | ||
end | ||
end | ||
end | ||
|
||
forks.each do |pid| | ||
Process.wait(pid) | ||
end |