Question about the mongostat tool

I have a question concerning the mongostat tool.

There is one field called getmore for which I need some explanations.

Looking in the documentation gives an idea of the meaning, it states:

getmore

    The number of get more (i.e. cursor batch) operations per second.

But concretely, what does this exactly mean?

An example by someone who clearly understands the idea may be helpful.

The same goes for the fields dirty and used .
Some simple explanation, maybe with an example, would help to clarify what these are about. Because I am not confident that the interpretation (based on the doc) I have is right.

Clean (unmodified) refers to data in the cache that is identical to the version stored on disk.

Dirty (modified) refers to data in the cache that has been modified and is different from the data stored in disk.

getMore : Use in conjunction with commands that return a cursor, e.g. find and aggregate , to return subsequent batches of documents currently pointed to by the cursor.

1 Like

OK. I hadn’t noticed any “clean” field.
So that means getMore is incremented each time those actions are executed:
find, findOne, it, aggregate ?
And what about “used” ?

It’s not quite like that. When you run a database command that gets documents (such as find and aggregate), MongoDB doesn’t necessarily return all the matching documents at once. Instead it returns a batch of say 1,000 documents and a cursor ID. A getMore command is a way to request extra documents from a cursor.

So say you’re using the NodeJS driver and you run collection.find(query).toArray(). This will find all documents matching query and put them into the array. Under the hood, the driver is first running the find database command. Then the driver will keep running getMore commands until the cursor is exhausted and all the documents have been returned.

So, say you have a 10,000 documents in a collection and you want to get them all. And say the batch size is 1,000. This will result in one find command and 9 getMores.

If you have 100 documents and your batch size is 1,000, running a find will never result in a getMore.

findOne will never result in a getMore because the minimum batch size is 1. The it command is a MongoDB Shell helper that actually just runs a getMore on the last cursor. So anytime you run it, getMores will increase.

Depending on what driver you use, you may never need to actually worry about using getMore. Some drivers have methods like toArray() that will handle all the getMore stuff for you under the hood.

As for “used”, that’s the percentage of the WiredTiger cache that is currently used. It goes up when WiredTiger pages in data from disk, and goes down when pages are evicted.

2 Likes

I see, it makes it much clearer. Thank you for this detailed explanation.