Skip to content

Instantly share code, notes, and snippets.

@paul
Created October 10, 2010 21:02
Show Gist options
  • Save paul/619566 to your computer and use it in GitHub Desktop.
Save paul/619566 to your computer and use it in GitHub Desktop.
require 'benchmark'
require 'mongoid'
require 'pp'
require 'active_support'
conn = Mongo::Connection.new
conn.drop_database('mongoid_test')
db = conn.db("mongoid_test")
{
:daily => 2.days / 1.minute,
:monthly => 3.months / 1.hour,
:yearly => 3.years / 1.day
}.each do |name, count|
db.create_collection("datapoints_#{name}")
coll = db["datapoints_#{name}"]
coll.drop_indexes
coll.create_index([[:m, 1], [:ts, 1]])
start = Time.now
puts "Inserting #{count} * 100 #{name} rows..."
100.times do
id = BSON::ObjectId.new
count.to_i.times do |i|
coll.insert(
:m => id,
:t => i * 60,
:c => 0, # Count
:s => 0.0, # Sum
:q => 0.0, # Sum of squares
:n => 0.0, # Min
:x => 0.0 # Max
)
end
end
stats = coll.stats
stats.each do |k,v|
if k.to_s =~ /Size$/i
stats[k] = "%.2f KiB" % (v.to_f / 1024)
end
end
pp stats
end
stats = db.stats
stats.each do |k,v|
if k.to_s =~ /Size$/i
stats[k] = "%.2f KiB" % (v.to_f / 1024)
end
end
pp stats
__END__
Inserting 2880 * 100 daily rows...
{"ns"=>"mongoid_test.datapoints_daily",
"count"=>288000,
"size"=>"27000.00 KiB",
"avgObjSize"=>"0.09 KiB",
"storageSize"=>"32546.50 KiB",
"numExtents"=>8,
"nindexes"=>2,
"lastExtentSize"=>"11796.25 KiB",
"paddingFactor"=>1.0,
"flags"=>0,
"totalIndexSize"=>"23920.00 KiB",
"indexSizes"=>{"_id_"=>11935744, "m_1_ts_1"=>12558336},
"ok"=>1.0}
Inserting 2160 * 100 monthly rows...
{"ns"=>"mongoid_test.datapoints_monthly",
"count"=>216000,
"size"=>"20250.00 KiB",
"avgObjSize"=>"0.09 KiB",
"storageSize"=>"32546.50 KiB",
"numExtents"=>8,
"nindexes"=>2,
"lastExtentSize"=>"11796.25 KiB",
"paddingFactor"=>1.0,
"flags"=>0,
"totalIndexSize"=>"17944.00 KiB",
"indexSizes"=>{"_id_"=>8953856, "m_1_ts_1"=>9420800},
"ok"=>1.0}
Inserting 1095.75 * 100 yearly rows...
{"ns"=>"mongoid_test.datapoints_yearly",
"count"=>109500,
"size"=>"10265.62 KiB",
"avgObjSize"=>"0.09 KiB",
"storageSize"=>"20750.25 KiB",
"numExtents"=>7,
"nindexes"=>2,
"lastExtentSize"=>"9830.25 KiB",
"paddingFactor"=>1.0,
"flags"=>0,
"totalIndexSize"=>"9112.00 KiB",
"indexSizes"=>{"_id_"=>4546560, "m_1_ts_1"=>4784128},
"ok"=>1.0}
{"collections"=>5,
"objects"=>613516,
"avgObjSize"=>"0.09 KiB",
"dataSize"=>"57516.75 KiB",
"storageSize"=>"85853.50 KiB",
"numExtents"=>25,
"indexes"=>6,
"indexSize"=>"50976.00 KiB",
"fileSize"=>"507904.00 KiB",
"ok"=>1.0}
require 'hitimes'
require 'pp'
require 'time'
require 'active_support'
require 'rrd'
@start = Time.parse("2010-01-01T00:00:00Z")
100.times do |i|
file = "all/rrd-#{i}.rrd"
@rrd = RRD::Base.new(file)
@rrd.create! :step => 1.minutes, :start => @start - 1 do
datasource "rrd", :type => :gauge, :heartbeat => 10.minutes, :min => 0, :max => :unlimited
archive :average, :every => 1.minute, :during => 2.days
archive :min, :every => 1.minute, :during => 2.days
archive :max, :every => 1.minute, :during => 2.days
archive :last, :every => 1.minute, :during => 2.days
archive :average, :every => 1.hour, :during => 3.months
archive :min, :every => 1.hour, :during => 3.months
archive :max, :every => 1.hour, :during => 3.months
archive :average, :every => 1.day, :during => 3.years
archive :min, :every => 1.day, :during => 3.years
archive :max, :every => 1.day, :during => 3.years
end
end
__END__
% du -sh all
17M all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment