Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 276 lines (193 sloc) 6.567 kB
#!/usr/bin/env ruby
if ARGV.length < 4
print("runtest TEST_NAME MONGO RAM_QUOTA REPLICA_COUNT" \
" NUM_ITEMS NUM_VBUCKETS VAL_SIZE CONCURRENCY [SHARDS] [key=val, ...]\n")
exit(-1)
end
# ------------------------------------
$test_name = ARGV[0]
$top_user = "root"
$top_patt = "mongod|mongos"
load 'util.rb'
# ------------------------------------
# Might be a url (http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-1.8.3.tgz)
# or part of a url, like: mongodb-linux-x86_64-1.8.3
#
$mongo = ARGV[1]
$mongo_base = $mongo.split('/')[-1].sub('.tgz', '') # Ex: 'mongodb-linux-x86_64-1.8.3'
$ram_quota = ARGV[2]
$replica_count = ARGV[3]
$num_items = (ARGV[4] || "1000").to_i
$num_vbuckets = ARGV[5]
$val_size = (ARGV[6] || "1000").to_i
$concurrency = (ARGV[7] || "10").to_i
$shards = (ARGV[8] || "").split(',').select {|x| x != 'none' }
$opts = {}
(ARGV[9] || "").split(',').each {|x|
key, val = x.split('=')
$opts[key] = val
}
$extra_sleep = $opts['extra_sleep']
# ------------------------------------
# sudo gem install mongo
# sudo gem install bson
# sudo gem install bson_ext
# sudo gem install SystemTimer
require 'rubygems'
require 'mongo'
OH = BSON::OrderedHash
$sharded = true
$host = "localhost"
$dbName = "test"
$collName = "test"
$safe = true
# ------------------------------------
def start_mongo()
if $sharded
run("nohup #{$mongo_base}/bin/mongod --dbpath #{$db_path}" +
" --port 20000 --rest &", true)
connect(20000, 100)
run("nohup #{$mongo_base}/bin/mongos --configdb localhost:20000 &", true)
else
run("nohup #{$mongo_base}/bin/mongod --dbpath #{$db_path} &", true)
end
sleep(2)
end
def connect(port = 27017, max_tries = 10)
i = 0
while i < max_tries
begin
print "connecting #{port}... (attempt #{i})\n"
conn = Mongo::Connection.new($host, port, :safe => $safe)
print "connecting #{port}... (attempt #{i}) done.\n"
return conn
rescue
end
i = i + 1
sleep([5, i].min)
end
return nil
end
# ------------------------------------
step("preparing... #{$test_name}")
run "killall -9 mongod || true"
run "killall -9 mongos || true"
run "rm -rf #{$mongo_base}" # Ex: mongodb-linux-x86_64-1.8.3
unless File.exists?("#{$mongo_base}.tgz")
if $mongo.start_with?('http://')
run "wget -O #{$mongo_base}.tgz #{$mongo}"
else
run "wget -O #{$mongo_base}.tgz http://fastdl.mongodb.org/linux/#{$mongo_base}.tgz"
end
end
# ------------------------------------
step("installing...")
run "tar -xzvf #{$mongo_base}.tgz"
$db_path = $du_path = "#{$mongo_base}/data-#{$test_name}"
# ------------------------------------
step("configuring...")
run "mkdir -p #{$db_path}"
start_mongo()
if $sharded
db = connect().db("admin")
db.command(OH["addshard", "localhost:20000", "allowLocal", true])
$shards.each do |shard|
db.command(OH["addshard", shard, "allowLocal", true])
end
db.command(OH["enablesharding", $dbName])
db.command(OH["shardcollection", "#{$dbName}.#{$collName}", "key", {"_id" => 1}])
end
# Pre-create collection data files.
#
coll = connect().db($dbName).collection($collName)
# ------------------------------------
step("loading-docs...",
"./rampup-client mongo 127.0.0.1:27017" \
" ratio_sets=1.0 ratio_creates=1.0" \
" min_value_size=#{$val_size}" \
" max_creates=#{$num_items} exit_after_creates=1",
nil, $num_items)
# ------------------------------------
step("loading-persisted...",
"#{$mongo_base}/bin/mongo 127.0.0.1:27017/admin mongo-fsync.js")
# ------------------------------------
step("reading-docs...",
"./rampup-client mongo 127.0.0.1:27017" \
" ratio_sets=0.0" \
" min_value_size=#{$val_size}" \
" num_items=#{$num_items}" \
" max_ops=10000",
nil, 10000)
# ------------------------------------
step("non-index-accessing...",
"./do-mongo-view 127.0.0.1 200 >> #{$out_file}",
nil, 200)
# ------------------------------------
step("index-building...",
"#{$mongo_base}/bin/mongo 127.0.0.1:27017/test index/ensureIndex-last.js")
# ------------------------------------
step("fsyncing...",
"#{$mongo_base}/bin/mongo 127.0.0.1:27017/admin mongo-fsync.js")
# ------------------------------------
step("index-accessing...",
"./do-mongo-view 127.0.0.1 10000 last >> #{$out_file}",
nil, 10000)
step("index-accessing2...",
"./do-mongo-view 127.0.0.1 10000 last >> #{$out_file}",
nil, 10000)
step("index-eq-accessing...",
"./do-mongo-view 127.0.0.1 10000 last equal >> #{$out_file}",
nil, 10000)
step("index-eq-accessing2...",
"./do-mongo-view 127.0.0.1 10000 last equal >> #{$out_file}",
nil, 10000)
# ------------------------------------
step("index-mid-building...",
"#{$mongo_base}/bin/mongo 127.0.0.1:27017/test index/ensureIndex-mid.js")
# ------------------------------------
step("index-mid-accessing...",
"./do-mongo-view 127.0.0.1 10000 mid >> #{$out_file}",
nil, 10000)
step("index-mid-accessing2...",
"./do-mongo-view 127.0.0.1 10000 mid >> #{$out_file}",
nil, 10000)
step("index-mid-eq-accessing...",
"./do-mongo-view 127.0.0.1 10000 mid equal >> #{$out_file}",
nil, 10000)
step("index-mid-eq-accessing2...",
"./do-mongo-view 127.0.0.1 10000 mid equal >> #{$out_file}",
nil, 10000)
# ------------------------------------
ops_per_concurrent_client = 10000
step("concurrent-usage...",
nil, nil, $concurrency * ops_per_concurrent_client)
proc_stats_start()
pids = (1..$concurrency).map do |x|
fork do
run("./rampup-client mongo 127.0.0.1:27017" \
" min_value_size=#{$val_size}" \
" num_items=#{$num_items}" \
" max_ops=#{ops_per_concurrent_client}")
exit
end
end
pids.map {|pid| [pid, Process.wait2(pid)] }
print pids
proc_stats_end()
# ------------------------------------
step("stopping...",
"killall -9 mongos && killall -SIGINT mongod")
# ------------------------------------
step("restarting...")
start_mongo()
# ------------------------------------
step("warming...")
coll = connect(27017, 100).db($dbName).collection($collName)
coll.find({"last" => 0}).limit(10).each {|doc| doc }
# ------------------------------------
step("index-rebuilding...",
"#{$mongo_base}/bin/mongo 127.0.0.1:27017/test index/reIndex-last.js")
coll.find({"last" => 0}).limit(10).each {|doc| doc }
# ------------------------------------
step("done...",
"killall -9 mongos && killall -SIGINT mongod")
Jump to Line
Something went wrong with that request. Please try again.