开发者

How to track how long some Mongo queries take

I have a few Mongo queries in the JS format, such as:

db.hello.update(params,data);

How do I run them in such a way that I can see exactly ho开发者_运维技巧w long they've taken to run later?


There are a couple of options:

  1. Do your updates with safe=true, which will cause the update call to block until mongod has written the data (the exact syntax for this depends on the driver you're using). You can add timing code around your updates in your application code, and log as appropriate.

  2. Enable verbose (or more-verbose) logging, and use the log files to determine the time spent during your updates. See the mongo docs on logging for more information.

  3. Enable the profiler, which stores information about queries and updates in a capped collection, db.system.profile, including the time spent servicing the query or update. Note that enabling the profiler affects performance, though not severely. See the mongo docs on profiling for more information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜