Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Slow query of mongodb

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Slow query log in mongodb

1. Open the query log.

(1) enable the slow log dynamically. You can optionally enable the slow log for the specified DB, but manually enable the slow log after the server is restarted.

Db.setProfilingLevel (1300)

SetProfilingLevel has two parameters. The first parameter represents the slow log switch. (the available values are 0 _ 1 _ 1 _ 2.

0: disable slow query log, 1: enable slow query log, 2: record all queries in database)

The second parameter is the slow query threshold in milliseconds, which is 100ms by default.

(2)。 Open in the configuration file and take effect permanently. Effective for all data DB

Add the following two parameters to the configuration file of mongo to permanently turn on the slow query.

Profile: indicates the slow log switch.

Slowms: slow log threshold.

Corresponds to two parameters in setProfilingLevel.

two。 View the slow query log status of the server

Db.getProfilingStatus ()

Rs0:SECONDARY > db.getProfilingStatus ()

{"was": 1, "slowms": 100}

Db.getProfilingLevel ()

Rs0:SECONDARY > db.getProfilingLevel ()

one

3. View the full query log.

In general, a system.profile is generated under each db when the slow log is turned on.

This collection records all the query records that the current database query time exceeds the threshold.

Rs0:PRIMARY > db.system.profile.find ({ns:/ ^ gow /}) .limit (1)

{"op": "update"

"ns": "gow.broadcasts"

"query": {"_ id": ObjectId ("54b73af6bab3047b5593c456")}

"updateobj": {"_ id": ObjectId ("54b73af6bab3047b5593c456"), "content": "each new stone"}

"nscanned": 0

"nscannedObjects": 0

"nMatched": 1

"nModified": 0

"upsert": true

"keyUpdates": 0

"numYield": 0

"lockStats": {"timeLockedMicros": {"r": NumberLong (0), "w": NumberLong (10)}}

Millis: 157

"execStats": {}

Ts: ISODate ("2015-01-26T19:05:00.118Z")

"client": "10.136.3.117"

"allUsers": [{"user": "root", "db": "admin"}], "user": "root@admin"}

Key value interpretation:

Op: operation type.

Ns: a collection of objects that perform the operation

Millis: time taken by the operation (milliseconds)

Client: the customer server that performs the operation.

AllUsers: the mongodb account under which the operation is performed

Ts: timestamp (time when the operation occurred)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report