Count query giving different result with same time range in mongodb -
i doing aggregation of records in collection time interval of 5 minute using match follows
{ "$match" : { "timestamp" : { "$gt" : 1460953500000 , "$lte" : 1460953800000})
scrip run @ time interval
10:01, (interval 9:55 10:00) 10:06, (interval 10:00 10:05)
after running above match query getting different count. count of document changes till 1-2 minute after time passed example run query of count in collection
query hit time
10:01:05 db.xxx.count({ "timestamp" : { "$gt" : 1460953500000 , "$lte" : 1460953800000}) count : 44350 10:01:015 db.xxx.count({ "timestamp" : { "$gt" : 1460953500000 , "$lte" : 1460953800000}) count : 44578 10:01:40 db.xxx.count({ "timestamp" : { "$gt" : 1460953500000 , "$lte" : 1460953800000}) count : 44830
and time onward count become stable.
i have found https://docs.mongodb.org/manual/core/journaling/#journal-process journaling process
with journaling, mongodb’s storage layer has 2 internal views of data set: private view, used write journal files, , shared view, used write data files:
- mongodb first applies write operations private view.
mongodb applies changes in private view on-disk journal files in journal directory every 100 milliseconds. mongodb records write operations on-disk journal files in batches called group commits. grouping commits minimize performance impact of journaling since these commits must block writers during commit. writes journal atomic, ensuring consistency of on-disk journal files. information on frequency of commit interval, see storage.journal.commitintervalms.
upon journal commit, mongodb applies changes journal shared view.
finally, mongodb applies changes in shared view data files. more precisely, @ default intervals of 60 seconds, mongodb asks operating system flush shared view data files. operating system may choose flush shared view disk @ higher frequency 60 seconds, particularly if system low on free memory. change interval writing data files, use storage.syncperiodsecs setting.
is reason count diff ?. using mongodb 3.2 please me find stable count result.
you have found answer yourself. check how working , records count waiting written disk using command:
db.runcommand( { serverstatus: 1 } )
Comments
Post a Comment