mongodb avgObjSize confusion and effect of field length on storage size

336 Views Asked by At

I have a Replica Set of 3 instances

  • instance A: Mongodb 3.0 (using wiredtiger storage engine)
  • instance B: Mongodb 2.6 (using good old mmapv1)
  • instance C: Mongodb 3.0 arbiter

and i have 3 collections in a database

coll2 has 10 million objects like following:

{ "_id" : ObjectId("5577d21d38a96916351f935f"), "abcde" : "00000000000000000000" }
{ "_id" : ObjectId("5577d21d38a96916351f9360"), "abcde" : "00000000000000000001" }
{ "_id" : ObjectId("5577d21d38a96916351f9361"), "abcde" : "00000000000000000002" }

coll3 has 10 million objects like following:

{ "_id" : ObjectId("5577d49538a96924cc1ca59b"), "abcdefghijklmnopqrstuvwxyzabcd" : "00000000000000000000" }
{ "_id" : ObjectId("5577d49538a96924cc1ca59c"), "abcdefghijklmnopqrstuvwxyzabcd" : "00000000000000000001" }
{ "_id" : ObjectId("5577d49538a96924cc1ca59d"), "abcdefghijklmnopqrstuvwxyzabcd" : "00000000000000000002" }
{ "_id" : ObjectId("5577d49538a96924cc1ca59e"), "abcdefghijklmnopqrstuvwxyzabcd" : "00000000000000000003" }

coll4 has 100 million objects like following:

{ "_id" : ObjectId("5577e87538a9690a60de1bee"), "abcdefghijklmnopqrstuvwxyzabcd" : "00000000000000000000" }
{ "_id" : ObjectId("5577e87538a9690a60de1bef"), "abcdefghijklmnopqrstuvwxyzabcd" : "00000000000000000001" }
{ "_id" : ObjectId("5577e87538a9690a60de1bf0"), "abcdefghijklmnopqrstuvwxyzabcd" : "00000000000000000002" }
{ "_id" : ObjectId("5577e87538a9690a60de1bf1"), "abcdefghijklmnopqrstuvwxyzabcd" : "00000000000000000003" }

As you see , I'm changing the length of the field (5 vs 30), and keeping the data same among the collections. Because i was trying to find out if i should abbreviate the field names for a collection that i expect to store 1-2 billion objects soon.

collection stats on instance A :

db.coll2.stats()
{
        "ns" : "testtest.coll2",
        "count" : 10000000,
        "size" : 540000000,
        "avgObjSize" : 54,
        "storageSize" : 150802432,
        "capped" : false,
        "nindexes" : 1,
        "totalIndexSize" : 90808320,
        "indexSizes" : {
                "_id_" : 90808320
        },
        "ok" : 1
}

db.coll3.stats()
{
        "ns" : "testtest.coll3",
        "count" : 10000000,
        "size" : 790000000,
        "avgObjSize" : 79,
        "storageSize" : 216186880,        
        "nindexes" : 1,
        "totalIndexSize" : 90832896,
        "indexSizes" : {
                "_id_" : 90832896
        },
        "ok" : 1
}

db.coll4.stats()
{
        "ns" : "testtest.coll4",
        "count" : 100000000,
        "size" : 7900000000,
        "avgObjSize" : 79,
        "storageSize" : 2182111232,
        "capped" : false,       
        "nindexes" : 1,
        "totalIndexSize" : 943423488,
        "indexSizes" : {
                "_id_" : 943423488
        },
        "ok" : 1
}

collection stats on instance B:

db.coll2.stats()
{
        "ns" : "testtest.coll2",
        "count" : 10000000,
        "size" : 1120000000,
        "avgObjSize" : 112,
        "storageSize" : 1580150784,
        "numExtents" : 19,
        "nindexes" : 1,
        "lastExtentSize" : 415174656,
        "paddingFactor" : 1,
        "systemFlags" : 1,
        "userFlags" : 1,
        "totalIndexSize" : 324456384,
        "indexSizes" : {
                "_id_" : 324456384
        },
        "ok" : 1
}

db.coll3.stats()
{
        "ns" : "testtest.coll3",
        "count" : 10000000,
        "size" : 1120000000,
        "avgObjSize" : 112,
        "storageSize" : 1580150784,
        "numExtents" : 19,
        "nindexes" : 1,
        "lastExtentSize" : 415174656,
        "paddingFactor" : 1,
        "systemFlags" : 1,
        "userFlags" : 1,
        "totalIndexSize" : 324456384,
        "indexSizes" : {
                "_id_" : 324456384
        },
        "ok" : 1
}

db.coll4.stats()
{
        "ns" : "testtest.coll4",
        "count" : 100000000,
        "size" : 11200000000,
        "avgObjSize" : 112,
        "storageSize" : 13598789584,
        "numExtents" : 27,
        "nindexes" : 1,
        "lastExtentSize" : 2146426864,
        "paddingFactor" : 1,
        "systemFlags" : 1,
        "userFlags" : 1,
        "totalIndexSize" : 3245577664,
        "indexSizes" : {
                "_id_" : 3245577664
        },
        "ok" : 1
}

What bugs me is that the avgObjSize and storage size of coll2 and coll3 don't change on instance B , while they change on instance A .

According to stats on instance B , coll2 and coll3 has no difference at all .

How can that be possible ?

0

There are 0 best solutions below