我已经使用MongoDB配置了一个分片集群。我想比较分片集群和单个数据库(不分片)之间的查询执行时间。对于单个数据库,我使用system.profiler来获取每个查询的执行时间。但是对于分片的集群,system.profiler是不可用的。我在网上搜索,但我找不到如何在分片集群上获得查询的总执行时间。请帮帮我!!
发布于 2018-01-30 18:18:41
为此,您可以简单地使用mongo的explain()方法。示例:
对于单个数据库:
db.users.find({username: "joynalabedin"}).explain().millis
这将以毫秒为单位返回查询执行时间。
对于分片集群:
db.visitors.find({"siteId" : "511ffa78-9a1d-4c33-a3aa-4b4417ca4afc"}).explain('executionStats')
在返回的输出中,executionStats中有三个属性:
https://docs.mongodb.com/manual/reference/explain-results/#sharded-collection
https://stackoverflow.com/questions/39125961
复制相似问题