Where are cursors stored?

I am having trouble finding documentation on where exactly cursors are stored in a sharded cluster, and would like to better understand how cursors work internally.

Main reason for this being that there is a decision in the company I work at to couple 1 mongos instance with each application instance, the reason stated being that in a sharded cluster, cursors are stored on the mongos processes in memory. I have, however, come across sharded cluster deployments that do not have the same architecture - only having a few mongos processes running on larger machines to allow more client applications to connect to them.

Is there any definitive way to find out this information? I’ve searched online for documentation, but have come up short.

HI @George_Kontridze, welcome!

It is a common pattern to place a mongos on each application server. However, the reason for deploying one mongos router on each application server is to reduce network latency between the application and the router.

If you have many application clients however, the architecture above may not be suitable depending on the case. This is because mongos routers communicate frequently with the config servers, and too many mongos may affect the performance of the config servers.

Another reason to host mongos on a dedicated instance is to avoid memory contention between the application client and the mongos, especially if the application client is memory hungry. As you can see it really depends on the use case, but it’s not related to cursors memory.

I would recommend reviewing the following resources:


1 Like