[SERVER-10998] avgObjSize keep enlarging when setup usePowerOf2Sizes Created: 02/Oct/13  Updated: 10/Dec/14  Resolved: 07/Oct/13

Status: Closed
Project: Core Server
Component/s: Storage
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Chimeng Wong Assignee: Unassigned
Resolution: Done Votes: 0
Labels: avgObjSize, usePowerOf2Sizes
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Redhat 5.2 64bit, mongoDB 2.4.6, ruby 1.9.3


Operating System: Linux
Participants:

 Description   

avgObjSize keep enlarging when setup usePowerOf2Sizes again

I am trying to use "usePowerOf2Sizes" on my collection for reusing space since i need to drop the whole collection later. But i find out when i setup "usePowerOf2Sizes" after my insert operation, the avgObjSize is being larger and larger. The avgObjSize should only change once then return

{ok:1}

right? example as below
===================================================

> db.gs_e89dfd94_7be7_44aa_b55b_6297cdfd9cbf.stats();
{
        "ns" : "test007.gs_e89dfd94_7be7_44aa_b55b_6297cdfd9cbf",
        "count" : 19999,
        "size" : 5119760,
        "avgObjSize" : 256.000800040002,
        "storageSize" : 5586944,
        "numExtents" : 5,
        "nindexes" : 1,
        "lastExtentSize" : 4194304,
        "paddingFactor" : 1,
        "systemFlags" : 1,
        "userFlags" : 1,
        "totalIndexSize" : 654080,
        "indexSizes" : {
                "_id_" : 654080
        },
        "ok" : 1
}
 
> db.runCommand({collMod:"gs_e89dfd94_7be7_44aa_b55b_6297cdfd9cbf","usePowerOf2Sizes":true})
{ "usePowerOf2Sizes_old" : false, "usePowerOf2Sizes_new" : true, "ok" : 1 }
 
> insert
 
> db.runCommand({collMod:"gs_e89dfd94_7be7_44aa_b55b_6297cdfd9cbf","usePowerOf2Sizes":true})
{ "ok" : 1 }
> db.gs_e89dfd94_7be7_44aa_b55b_6297cdfd9cbf.stats();
{
        "ns" : "test007.gs_e89dfd94_7be7_44aa_b55b_6297cdfd9cbf",
        "count" : 20000,
        "size" : 5120256,
        "avgObjSize" : 256.0128,
        "storageSize" : 5586944,
        "numExtents" : 5,
        "nindexes" : 1,
        "lastExtentSize" : 4194304,
        "paddingFactor" : 1,
        "systemFlags" : 1,
        "userFlags" : 1,
        "totalIndexSize" : 654080,
        "indexSizes" : {
                "_id_" : 654080
        },
        "ok" : 1
}
 
 
> insert 
 
>db.gs_e89dfd94_7be7_44aa_b55b_6297cdfd9cbf.stats();
{
        "ns" : "test007.gs_e89dfd94_7be7_44aa_b55b_6297cdfd9cbf",
        "count" : 20001,
        "size" : 5120752,
        "avgObjSize" : 256.02479876006197,
        "storageSize" : 5586944,
        "numExtents" : 5,
        "nindexes" : 1,
        "lastExtentSize" : 4194304,
        "paddingFactor" : 1,
        "systemFlags" : 1,
        "userFlags" : 1,
        "totalIndexSize" : 654080,
        "indexSizes" : {
                "_id_" : 654080
        },
        "ok" : 1
}

===================================================

Is it a bug? finally my avgObjSize got double( 500B ) after around 20k insert operation,



 Comments   
Comment by Daniel Pasette (Inactive) [ 09/Oct/13 ]

You set up powerOf2Size on the collection, not on the document. You can do it at any time, because it only affects subsequent allocations in the collection. If you insert many documents where your document is > 128b and < 256b then the avgObjSize should remain at 256b.

Comment by Chimeng Wong [ 07/Oct/13 ]

Hi Dan,

I still have a question, assume my each doc is 260Bytes ( more than 256Bytes ), keep insert and setup powerOf2Size on each new document. I know the avgObjSize will be enlarged by itself, but will the avgObjSize stop in 512Bytes?
Another case is documents are less than 256Bytes, the same operation, and will the avgObjSize stop in 256Bytes as well?

Comment by Daniel Pasette (Inactive) [ 07/Oct/13 ]

That's correct.

Comment by Chimeng Wong [ 07/Oct/13 ]

Hi Dan,

So powerOf2Size option will not effect on inserted doc, only affect on future insert right?

Comment by Daniel Pasette (Inactive) [ 07/Oct/13 ]

avgObjSize is calculated by dividing the size by the count. It can be affected by the usePowerOf2Sizes option depending on the documents which are inserted after it's turned on.

If all of the new documents you are inserting are larger than 256 bytes, mongod will allocate the next power of 2 size (512 bytes) for these new documents. Eventually, this will increase your average document size accordingly.

Comment by Chimeng Wong [ 02/Oct/13 ]

Sorry, title should remove using Ruby

Generated at Thu Feb 08 03:24:36 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.