In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Mongodb Profiling function-> slow query function
Profiling writes the collected information to the system.profile collection, which is a capped collection.
1. Locate the mongodb slow query statement method:
Enable the Profiling feature, locate the slow query log, find the statements that execute slowly, and then optimize them. The ideas are as follows:
a. Query slow query log (system.profile) to find slow query statements that exceed the defined time
For b.explain () to view the execution plan, you can refer to the following article: https://blog.51cto.com/1937519/2301699
c. Determining the causes of slow statements, such as lack of indexes, business batch problems, etc., is the same as the traditional sql optimization of rdbms.
two。 Open slow query:
2.1:Profiling level description:
A.0: turn off without collecting any data.
B.1: collect slow query data. The default is 100 milliseconds.
C.2: collect all data
2.2: database slow query configuration (note that the configuration file is written, which takes effect after restart):
a. View status: level and time
Repsetzhou:PRIMARY > db.getProfilingStatus ()
{"was": 1, "slowms": 200}
b. View level
Repsetzhou:PRIMARY > db.getProfilingLevel ()
one
c. Set level
Repsetzhou:PRIMARY > db.setProfilingLevel (2)
{"was": 1, "slowms": 200, "ok": 1}
d. Confirm the setting level:
Repsetzhou:PRIMARY > db.getProfilingLevel ()
two
e. Description: set level and time (1000 equals 1s)
Repsetzhou:PRIMARY > db.setProfilingLevel (1pime1000) # (including level, time parameters, time is in milliseconds)
{"was": 2, "slowms": 1000, "ok": 1}
2.3: enable slow query in the configuration file:
OperationProfiling:
SlowOpThresholdMs: 200
Mode: slowOp
3. Turn off Profiling:
a. Close:
Repsetzhou:PRIMARY > db.setProfilingLevel (0)
{"was": 2, "slowms": 1000, "ok": 1}
b. Confirm:
Repsetzhou:PRIMARY > db.getProfilingStatus ()
{"was": 0, "slowms": 1000}
4. Modify the size of the system.profile:
a. Turn off Profiling:
Repsetzhou:PRIMARY > db.setProfilingLevel (0)
{"was": 0, "slowms": 200, "ok": 1}
b. Delete the system.profile collection:
Repsetzhou:PRIMARY > db.system.profile.drop ()
True
c. Create a new system.profile collection-10m:
Repsetzhou:PRIMARY > db.createCollection ("system.profile", {capped: true, size:10000000})
{"ok": 1}
d. Reopen Profiling:
Repsetzhou:PRIMARY > db.setProfilingLevel (1)
{"was": 0, "slowms": 200, "ok": 1}
5.1 slow query (system.profile) analysis:
Repsetzhou:PRIMARY > db.system.profile.find ()
a. The query is greater than the specified time such as 500 milliseconds:
Db.system.profile.find ({"millis": {$gte:500}})
b. Query specified time slow query:
Db.system.profile.find (
{
Ts: {
Gt: new ISODate ("2018-10-22T03:01:45.976Z")
Lt: new ISODate ("2018-10-22T03:01:48.976Z")
}
}
)
c. Show 5 recent events:
Show profile
5.2. slow query logs are also recorded in the log file of mongodb. If system.profile has been overwritten, you can refer to the backend log of mongodb.
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: 280
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.