One .mongodb Monitoring of
mongodb Can pass profile To monitor data , To optimize .
See if it's on profile Function with command
db.getProfilingLevel() return level Grade , The value is 0|1|2, Respectively means :0 On behalf of closed ,1 For recording slow orders ,2 Represent all
Start profile The function is
db.setProfilingLevel(level); #level Grade , The value is the same as above.
level by 1 When , The default value of slow command is 100ms, Change to db.setProfilingLevel(level,slowms) Such as db.setProfilingLevel(1,50) This changes to 50 millisecond
adopt db.system.profile.find() View the current monitoring log .
Such as :
- > db.system.profile.find({millis:{$gt:500}})
- { "ts" : ISODate("2011-07-23T02:50:13.941Z"), "info" : "query order.order reslen:11022 nscanned:672230 \nquery: { status: 1.0 } nreturned:101 bytes:11006 640ms", "millis" : 640 }
- { "ts" : ISODate("2011-07-23T02:51:00.096Z"), "info" : "query order.order reslen:11146 nscanned:672302 \nquery: { status: 1.0, user.uid: { $gt: 1663199.0 } } nreturned:101 bytes:11130 647ms", "millis" : 647 }
The value here means
ts: Command execution time
info: The content of the order
query: Representative query
order.order: Represents the library and collection of queries
reslen: Returned result set size ,byte Count
nscanned: Number of scan records
nquery: After that is the query criteria
nreturned: Return the number of records and time used
millis: Time spent
If it takes a long time , Then we need to optimize .
such as nscanned It's a big number , Or close to the total number of records , Then you may not use index queries .
reslen It's big , It is possible to return unnecessary fields .
nreturned It's big , Then it is possible to query without restrictions .
mongo Can pass db.serverStatus() see mongod Operating state
- > db.serverStatus()
- {
- "host" : "baobao-laptop",# Host name
- "version" : "1.8.2",# Version number
- "process" : "mongod",# Process name
- "uptime" : 15549,# The elapsed time
- "uptimeEstimate" : 15351,
- "localTime" : ISODate("2011-07-23T06:07:31.220Z"), current time
- "globalLock" : {
- "totalTime" : 15548525410,# Total operation time (ns)
- "lockTime" : 89206633, # Total lock time (ns)
- "ratio" : 0.005737305027178137,# Lock ratio
- "currentQueue" : {
- "total" : 0,# The current queue to execute
- "readers" : 0,# Read the queue
- "writers" : 0# Write a queue
- },
- "activeClients" : {
- "total" : 0,# The number of links executed by the current client
- "readers" : 0,# Number of read Links
- "writers" : 0# Write Links
- }
- },
- "mem" : {# The memory of
- "bits" : 32,#32 Bit system
- "resident" : 337,# The amount of physical memory occupied
- "virtual" : 599,# Occupy virtual memory
- "supported" : true,# Whether it supports expanding memory
- "mapped" : 512
- },
- "connections" : {
- "current" : 2,# Current number of links
- "available" : 817# Number of links available
- },
- "extra_info" : {
- "note" : "fields vary by platform",
- "heap_usage_bytes" : 159008,# Heap usage bytes
- "page_faults" : 907 # The page pretends to be
- },
- "indexCounters" : {
- "btree" : {
- "accesses" : 59963, # The number of indexes accessed
- "hits" : 59963, # So the number of hits
- "misses" : 0,# Index deviation number
- "resets" : 0,# Reset number
- "missRatio" : 0# Miss rate
- }
- },
- "backgroundFlushing" : {
- "flushes" : 259, # Refresh times
- "total_ms" : 3395, # Total refresh time
- "average_ms" : 13.108108108108109, # Average duration
- "last_ms" : 1, # The last time
- "last_finished" : ISODate("2011-07-23T06:07:22.725Z")# Last refresh time
- },
- "cursors" : {
- "totalOpen" : 0,# Number of open cursors
- "clientCursors_size" : 0,# Client cursor size
- "timedOut" : 16# Timeout time
- },
- "network" : {
- "bytesIn" : 285676177,# input data (byte)
- "bytesOut" : 286564,# Output data (byte)
- "numRequests" : 2012348# Number of requests
- },
- "opcounters" : {
- "insert" : 2010000, # Insert operands
- "query" : 51,# Query operands
- "update" : 5,# Update operands
- "delete" : 0,# Delete operands
- "getmore" : 0,# Get more operands
- "command" : 148# Other command operands
- },
- "asserts" : {# The number of assertions
- "regular" : 0,
- "warning" : 0,
- "msg" : 0,
- "user" : 2131,
- "rollovers" : 0
- },
- "writeBacksQueued" : false,
- "ok" : 1
- }
db.stats() View the original status of a library
- > db.stats()
- {
- "db" : "order",# Library name
- "collections" : 4,# Set number
- "objects" : 2011622,# Record number
- "avgObjSize" : 111.92214441878245,# The average of each record
- "dataSize" : 225145048,# The total size of the record
- "storageSize" : 307323392,# Pre allocated storage space
- "numExtents" : 21,# Number of events
- "indexes" : 1,# Index number
- "indexSize" : 74187744,# So the size
- "fileSize" : 1056702464,# file size
- "ok" : 1
- }
To view the set record
- > db.order.stats()
- {
- "ns" : "order.order",# Namespace
- "count" : 2010000,# Record number
- "size" : 225039600,# size
- "avgObjSize" : 111.96,
- "storageSize" : 307186944,
- "numExtents" : 18,
- "nindexes" : 1,
- "lastExtentSize" : 56089856,
- "paddingFactor" : 1,
- "flags" : 1,
- "totalIndexSize" : 74187744,
- "indexSizes" : {
- "_id_" : 74187744# The index for _id_ The index size of
- },
- "ok" : 1
- }
mongostat Command to view running real-time statistics , Represents the number of real-time execution per second
mongodb It also provides an opportunity http Monitoring page of , You can visit http://ip:28017 Check it out. , This page is basically a synthesis of the above commands , So I won't go into details here .
Two .mongodb The optimization of the
According to the above monitoring methods , After finding the problem , We can optimize
There's a slow command on it , Now we can track it by executing the plan , Such as
- > db.order.find({ "status": 1.0, "user.uid": { $gt: 2663199.0 } }).explain()
- {
- "cursor" : "BasicCursor",# cursor type
- "nscanned" : 2010000,# Number of scans
- "nscannedObjects" : 2010000,# Scanning objects
- "n" : 337800,# Return the data
- "millis" : 2838,# Time consuming
- "nYields" : 0,
- "nChunkSkips" : 0,
- "isMultiKey" : false,
- "indexOnly" : false,
- "indexBounds" : {# Use index ( Nothing here )
- }
- }
For something like this , We can create indexes
Can pass db.collection.ensureIndex({" Field name ":1}) To create an index ,1 In ascending order ,-1 For the descending order , In the case of multiple data already available , It can be executed in the background , sentence db.collection.ensureIndex({" Field name ":1} , {backgroud:true})
Get the reference db.collection.getIndexes() see
Here we create a user.uid The index of >db.order.ensureIndex({"user.uid":1})
Re execute after creation
- db.order.find({ "status": 1.0, "user.uid": { $gt: 2663199.0 } }).explain()
- {
- "cursor" : "BtreeCursor user.uid_1",
- "nscanned" : 337800,
- "nscannedObjects" : 337800,
- "n" : 337800,
- "millis" : 1371,
- "nYields" : 0,
- "nChunkSkips" : 0,
- "isMultiKey" : false,
- "indexOnly" : false,
- "indexBounds" : {
- "user.uid" : [
- [
- 2663199,
- 1.7976931348623157e+308
- ]
- ]
- }
- }
Fewer scans , Speed up .mongodb The design of index is similar to that of relational database , Search by index to speed up reading , But too much pressure on writing , So I'm not going to talk about it here .
2. Other optimizations can use hint Force index lookup , Return just the data you need , Paging data, etc .
mongodb More articles on monitoring and performance optimization of
- Dynamic CRM 2013 Learning notes ( 7、 ... and ) track 、 Monitoring and performance optimization
This article will introduce CRM Three content tracking of . Monitoring and performance optimization . Tracking is CRM It's a very useful function in , It can serve our CRM Debug or fix errors . Warnings provide valuable information : We can use window Performance monitoring tools to understand CRM The performance status of : Last ...
- Oracle Management monitoring section space utilization monitoring -oracle performance optimization
SELECT S.OWNER, S.SEGMENT_NAME, S.SEGMENT_TYPE, S.PARTITION_NAME, ROUND(BYTE ...
- Mongodb Performance optimization problem of
Abstract Database performance has a crucial impact on the overall performance of software , about Mongodb The common performance optimization methods of database mainly include : Paradigmatization and anti paradigmatization : The use of fill factor : Use of index : One . Paradigmatization and anti paradigmatization Paradigms are about eliminating duplicate data ...
- iOS Performance optimization summary
iOS Performance optimization summary . About iOS Performance optimization : Basic tools . Business optimization . Memory optimization . Carton optimization . Layout optimization . Power optimization . Install the bag to slim down . Startup optimization . Network optimization, etc . About iOS Performance optimization : Basic tools . Business optimization . Memory ...
- mongodb Can pass profile To monitor data (mongodb performance optimization )
mongodb Can pass profile To monitor data (mongodb performance optimization ) Turn on Profiling function , Optimize slow queries : mongodb Can pass profile To monitor data , To optimize . see ...
- MongoDB performance optimization
One . Indexes MongoDB Provides diverse indexing support , The index information is stored in system.indexes in , And the default is always _id Create index , Its index uses basic and MySQL Like a relational database . In fact, it can be said that , Indexes ...
- MongoDB Performance optimization guidelines
One . Indexes MongoDB Provides diverse indexing support , The index information is stored in system.indexes in , And the default is always _id Create index , Its index uses basic and MySQL Like a relational database . In fact, it can be said that , Indexes ...
- Mongodb Advanced - performance optimization
1. monitor mongodb Can pass profile To monitor data , To optimize . See if it's on profile Function with command :db.getProfilingLevel() return level Grade , The value is 0|1|2, Represent the ...
- MongoDB Learning notes ( Four )-- Indexes && performance optimization
Indexes Basic index ...
Random recommendation
- Swipecards
https://github.com/Diolor/Swipecards https://github.com/kikoso/Swipeable-Cards
- ios Project development summary
UI Interface iOS and Android Interface design dimension specification http://www.alibuybuy.com/posts/85486.html iPhone app Interface design dimension specification http://www. ...
- Explain profound theories in simple language ES6: Indefinite parameters and default parameters
Uncertain parameters We usually use variable parameter functions to construct API, Variable parameter functions can take any number of parameters . for example ,String.prototype.concat Method can accept any number of string parameters .ES6 Provides a new way to write variable parameter functions ...
- Alibaba cloud uses js Realization OSS Image upload 、 obtain OSS Picture list 、 Get the picture Internet access address ( Read write access is private 、 Read and write access public );
Please refer to :https://help.aliyun.com/document_detail/32069.html?spm=a2c4g.11186623.6.763.ZgC59a perhaps https://h ...
- 【Qt】 The window is centered
w.move((a.desktop()->width() - w.width())/, (a.desktop()->height() - w.height())/); The above method can be put in the middle , but ...
- 10-03 Java Overview and explanation of the package
Compile and run with package A: Manual a: Write a java file . b: adopt javac Command to compile the java file . c: Manually create the package name . d: hold b The steps of the class Files in c The lowest level package of the step e: Go back to the same location as the package root ...
- sysfs File system learning --sysfs
One .sysfs brief introduction 1.sysfs Is the use VFS Interface to read and write kobject Hierarchical structure , File systems built up . The updates and deletions are those xxx_register()/unregister() What to do love . from sysfs ...
- JavaScript in Function Declaration And Function Expression Or say function fn(){} and var fn=function(){} The difference between
JavaScript It's an interpretative language , The function declaration will be in JavaScript After the code loads . Explained before execution , Function expressions are interpreted only when executed to this line of code . stay JS There are two ways to define functions in , 1 yes :var aaa= ...
- 160705、 summary :commons-codec.jar Common methods in
One .Base64 Encoding and decoding import org.apache.commons.codec.EncoderException;import org.apache.commons.codec.binary ...
- flask The signal
Sao Shi blog : The signal That's how you understand the signal , Request is compared to racing car , The process of asking to go is racing track , And the signal is located in the gas station and maintenance station on the racetrack , The function of signal registration is like the person in the maintenance station , Every time I pass the maintenance station and someone in the maintenance station carries out maintenance The signal is understood here : ...