I'm doing some tests to see what kind of throughput I can get from Mongodb. The documentation says that capped collections are the fastest option. But I often find that I can write to a normal collection much faster. Depending on the exact test, I can often get twice the throughput with a normal collection.
Am I missing something? How do I troubleshoot this?
I have a very simple C++ program that writes about 64,000 documents to a collection as fast as possible. I record the total time, and the time that I'm waiting for the database. If I change nothing but the collection name, I can see a clear difference between the capped and normal collections.
> use tutorial
switched to db tutorial
> db.system.namespaces.find()
{ "name" : "tutorial.system.indexes" }
{ "name" : "tutorial.persons.$_id_" }
{ "name" : "tutorial.persons" }
{ "name" : "tutorial.persons.$age_1" }
{ "name" : "tutorial.alerts.$_id_" }
{ "name" : "tutorial.alerts" }
{ "name" : "tutorial.capped.$_id_" }
{ "name" : "tutorial.capped", "options" : { "create" : "capped", "capped" : true, "size" : 100000000 } }
> db.alerts.stats()
{
"ns" : "tutorial.alerts",
"count" : 400000,
"size" : 561088000,
"avgObjSize" : 1402.72,
"storageSize" : 629612544,
"numExtents" : 16,
"nindexes" : 1,
"lastExtentSize" : 168730624,
"paddingFactor" : 1,
"systemFlags" : 1,
"userFlags" : 0,
"totalIndexSize" : 12991664,
"indexSizes" : {
"_id_" : 12991664
},
"ok" : 1
}
> db.capped.stats()
{
"ns" : "tutorial.capped",
"count" : 62815,
"size" : 98996440,
"avgObjSize" : 1576,
"storageSize" : 100003840,
"numExtents" : 1,
"nindexes" : 1,
"lastExtentSize" : 100003840,
"paddingFactor" : 1,
"systemFlags" : 1,
"userFlags" : 0,
"totalIndexSize" : 2044000,
"indexSizes" : {
"_id_" : 2044000
},
"capped" : true,
"max" : 2147483647,
"ok" : 1
}
linux version: 3.4.11-1.fc16.x86_64
mongo version: db version v2.2.2, pdfile version 4.5
This is a dedicated machine doing nothing but running the Mongodb server and my test client. The machine is ridiculously overpowered for this test.