Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Submit basic CRU benchmark.

  • Loading branch information...
commit e9847d04efa22601540d91850bd3b5be3874ec69 0 parents
@JeffreyZhao authored
21 mdb-get-by-key.rb
@@ -0,0 +1,21 @@
+require 'rubygems'
+require 'mongo'
+
+db = Mongo::Connection.new.db("test")
+things = db["news"]
+
+time_to_get = 100 * 100 * 100
+start_time = Time.now.to_i
+gets_count = 0
+
+time_to_get.times do
+
+ id = rand(110 * 10000) + 1
+ things.find_one({ "_id" => id })
+
+ gets_count = gets_count + 1
+ if (gets_count % 100000 == 0)
+ end_time = Time.now.to_i
+ puts "#{gets_count} gets: #{end_time - start_time} seconds"
+ end
+end
78 mdb-insert.rb
@@ -0,0 +1,78 @@
+require 'rubygems'
+require 'mongo'
+
+db = Mongo::Connection.new.db("test")
+
+things = db["news"]
+things.drop()
+
+things.create_index([["CreateTime", Mongo::DESCENDING]]);
+["CategoryID", "UserID", "Tags"].each { |c|
+ things.create_index(c)
+}
+
+all_tags = [];
+chars = ('a' .. 'z')
+chars.each { |x|
+ chars.each { |y|
+ chars.each { |z|
+ all_tags << x + y + z
+ }
+ }
+}
+
+tag_index = 0;
+id = 1
+user_count = 10000
+begin_seconds = Time.mktime(2010, 1, 1).to_i # (1 Jan 2001)
+
+start_time = Time.now.to_i
+
+(1 .. 20000).each do |cat_id| # 20000 × 55 = 1,100,000
+ count = (cat_id % 10 + 1) * 10
+ count.times do
+ title = "This is title of news #{id}"
+ create_time = Time.at(begin_seconds + id)
+ user_id = cat_id % user_count
+ source = "source of news #{id}"
+ source_url = "http://www.cnblogs.com/JeffreyZhao/"
+ status = 1
+
+ tags = ["Tag_#{cat_id % 3}_#{id % 5}"];
+ tag_count = id % 5 + 1
+ tag_count.times do
+ tags << all_tags[tag_index % all_tags.size]
+ tag_index = tag_index + 1
+ end
+
+ things.save({
+ "_id" => id,
+ "Title" => title,
+ "CategoryID" => cat_id,
+ "CreateTime" => create_time.to_i,
+ "UserID" => user_id,
+ "Tags" => tags,
+ "Source" => source,
+ "SourceUrl" => source_url,
+ "Status" => status
+ })
+
+=begin
+ puts "=== #{id} ==="
+ puts "Title: #{title}"
+ puts "CategoryID: #{cat_id}"
+ puts "UserID: #{user_id}"
+ puts "CreateTime #{create_time}"
+ puts "Tags: #{tags.join(',')}"
+ puts "Source: #{source}"
+ puts "SourceUrl: #{source_url}"
+=end
+
+ if (id % (100 * 1000) == 0)
+ end_time = Time.now.to_i
+ puts "#{id} records: #{end_time - start_time} seconds"
+ end
+ id = id + 1
+ end
+end
+
35 mdb-update-by-key.rb
@@ -0,0 +1,35 @@
+require 'rubygems'
+require 'mongo'
+
+db = Mongo::Connection.new.db("test")
+things = db["news"]
+
+time_to_update = 100 * 100 * 100
+start_time = Time.now.to_i
+update_count = 0
+
+time_to_update.times do
+
+ id = rand(110 * 10000) + 1
+ create_time = Time.now
+ title = "This is title of news #{id} - updated at #{create_time}"
+ source = "source of news #{id} - updated at #{create_time}"
+ source_url = "http://www.cnblogs.com/JeffreyZhao/ - updated at #{create_time}"
+ status = rand(5)
+
+ things.update(
+ { "_id" => id },
+ {
+ "CreateTime" => create_time.to_i,
+ "Title" => title,
+ "Source" => source,
+ "SourceUrl" => source_url,
+ "Status" => status
+ })
+
+ update_count = update_count + 1
+ if (update_count % 100000 == 0)
+ end_time = Time.now.to_i
+ puts "#{update_count} updates: #{end_time - start_time} seconds"
+ end
+end
27 tt-get-by-key.rb
@@ -0,0 +1,27 @@
+require 'tokyotyrant'
+include TokyoTyrant
+
+# create the object
+db = RDBTBL::new
+
+# connect to the server
+if !db.open("127.0.0.1", 1978)
+ ecode = db.ecode
+ STDERR.printf("open error: %s\n", db.errmsg(ecode))
+end
+
+time_to_get = 100 * 100 * 100
+start_time = Time.now.to_i
+gets_count = 0
+
+time_to_get.times do
+
+ id = rand(110 * 10000) + 1
+ db.get("news_#{id}")
+
+ gets_count = gets_count + 1
+ if (gets_count % 100000 == 0)
+ end_time = Time.now.to_i
+ puts "#{gets_count} gets: #{end_time - start_time} seconds"
+ end
+end
84 tt-insert.rb
@@ -0,0 +1,84 @@
+require 'tokyotyrant'
+include TokyoTyrant
+
+# create the object
+db = RDBTBL::new
+
+# connect to the server
+if !db.open("127.0.0.1", 1978)
+ ecode = db.ecode
+ STDERR.printf("open error: %s\n", db.errmsg(ecode))
+end
+
+puts db.vanish()
+
+# puts db.setindex("ID", RDBTBL::ITDECIMAL | RDBTBL::ITKEEP)
+puts db.setindex("UserID", RDBTBL::ITDECIMAL | RDBTBL::ITKEEP)
+puts db.setindex("CategoryID", RDBTBL::ITDECIMAL | RDBTBL::ITKEEP)
+puts db.setindex("CreateTime", RDBTBL::ITDECIMAL | RDBTBL::ITKEEP)
+puts db.setindex("Tags", RDBTBL::ITTOKEN | RDBTBL::ITKEEP)
+
+all_tags = [];
+chars = ('a' .. 'z')
+chars.each { |x|
+ chars.each { |y|
+ chars.each { |z|
+ all_tags << x + y + z
+ }
+ }
+}
+
+tag_index = 0;
+id = 1
+user_count = 10000
+begin_seconds = Time.mktime(2010, 1, 1).to_i # (1 Jan 2001)
+
+start_time = Time.now.to_i
+
+(1 .. 200 * 100).each do |cat_id| # 20000 × 55 = 1,100,000
+ count = (cat_id % 10 + 1) * 10
+ count.times do
+ title = "This is title of news #{id}"
+ create_time = Time.at(begin_seconds + id)
+ user_id = cat_id % user_count
+ source = "source of news #{id}"
+ source_url = "http://www.cnblogs.com/JeffreyZhao/"
+ status = 1
+
+ tags = ["Tag_#{cat_id % 3}_#{id % 5}"];
+ tag_count = id % 5 + 1
+ tag_count.times do
+ tags << all_tags[tag_index % all_tags.size]
+ tag_index = tag_index + 1
+ end
+
+ db.put("news_#{id}", {
+ "ID" => id.to_s,
+ "Title" => title,
+ "CategoryID" => cat_id.to_s,
+ "CreateTime" => create_time.to_i.to_s,
+ "UserID" => user_id.to_s,
+ "Tags" => tags.join(" "),
+ "Source" => source,
+ "SourceUrl" => source_url,
+ "Status" => status
+ });
+
+=begin
+ puts "=== #{id} ==="
+ puts "Title: #{title}"
+ puts "CategoryID: #{cat_id}"
+ puts "UserID: #{user_id}"
+ puts "CreateTime #{create_time}"
+ puts "Tags: #{tags.join(',')}"
+ puts "Source: #{source}"
+ puts "SourceUrl: #{source_url}"
+=end
+ id = id + 1
+
+ if (id % (100 * 1000) == 0)
+ end_time = Time.now.to_i
+ puts "#{id} records: #{end_time - start_time} seconds";
+ end
+ end
+end
39 tt-update-by-key.rb
@@ -0,0 +1,39 @@
+require 'tokyotyrant'
+include TokyoTyrant
+
+# create the object
+db = RDBTBL::new
+
+# connect to the server
+if !db.open("127.0.0.1", 1978)
+ ecode = db.ecode
+ STDERR.printf("open error: %s\n", db.errmsg(ecode))
+end
+
+time_to_update = 100 * 100 * 100
+start_time = Time.now.to_i
+update_count = 0
+
+time_to_update.times do
+
+ id = rand(110 * 10000) + 1
+ create_time = Time.now
+ title = "This is title of news #{id} - updated at #{create_time}"
+ source = "source of news #{id} - updated at #{create_time}"
+ source_url = "http://www.cnblogs.com/JeffreyZhao/ - updated at #{create_time}"
+ status = rand(5)
+
+ note = db.get("news_#{id}")
+ note["CreateTime"] = create_time.to_i.to_s
+ note["Title"] = title
+ note["Source"] = source
+ note["SourceUrl"] = source_url
+ note["Status"] = status.to_s
+ db.put("news_#{id}", note)
+
+ update_count = update_count + 1
+ if (update_count % 10000 == 0)
+ end_time = Time.now.to_i
+ puts "#{update_count} updates: #{end_time - start_time} seconds"
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.