How to check application is reading from Secondary Node in MongodB?

笑着哭i 提交于 2020-07-07 08:17:04

问题


I have a 3 member replica set. Read preference is set as "Secondary Preferred" How to check application is reading from Secondary Node in MongodB? Please suggest.


回答1:


Firstly you can configure profiling. For that you need to start your mongodb servers with option --profile 2 and configure log file. It'll log all queries. After that you can read log for each instance db. Simple example:

db.your_collection.profile.find({ns: "name_your_db.your_collection"})

Secondly you can use mongotop. You need to start it for each mongodb server. For example:

mongotop -h server_ip:server_port seconds
mongotop -h 127.0.0.1:27017 5

It'll print every specified period of time log, where you can read how much time for read or write is taken for each collection.




回答2:


Other means of determining whether queries are sent to secondaries:

  • Enable command logging in the driver, which should tell you which server each command was sent to.
  • Inspect server logs for connections being made or not made, then set minimum connection pool size to 0 so that a connection is only made when needed for a query, then run some queries.


来源:https://stackoverflow.com/questions/34267909/how-to-check-application-is-reading-from-secondary-node-in-mongodb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!