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 :

  1. > db.system.profile.find({millis:{$gt:500}})
  2. { "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 }
  3. { "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

  1. > db.serverStatus()
  2. {
  3. "host" : "baobao-laptop",# Host name
  4. "version" : "1.8.2",# Version number
  5. "process" : "mongod",# Process name
  6. "uptime" : 15549,# The elapsed time
  7. "uptimeEstimate" : 15351,
  8. "localTime" : ISODate("2011-07-23T06:07:31.220Z"), current time
  9. "globalLock" : {
  10. "totalTime" : 15548525410,# Total operation time (ns)
  11. "lockTime" : 89206633,  # Total lock time (ns)
  12. "ratio" : 0.005737305027178137,# Lock ratio
  13. "currentQueue" : {
  14. "total" : 0,# The current queue to execute
  15. "readers" : 0,# Read the queue
  16. "writers" : 0# Write a queue
  17. },
  18. "activeClients" : {
  19. "total" : 0,# The number of links executed by the current client
  20. "readers" : 0,# Number of read Links
  21. "writers" : 0# Write Links
  22. }
  23. },
  24. "mem" : {# The memory of
  25. "bits" : 32,#32 Bit system
  26. "resident" : 337,# The amount of physical memory occupied
  27. "virtual" : 599,# Occupy virtual memory
  28. "supported" : true,# Whether it supports expanding memory
  29. "mapped" : 512
  30. },
  31. "connections" : {
  32. "current" : 2,# Current number of links
  33. "available" : 817# Number of links available
  34. },
  35. "extra_info" : {
  36. "note" : "fields vary by platform",
  37. "heap_usage_bytes" : 159008,# Heap usage bytes
  38. "page_faults" : 907 # The page pretends to be
  39. },
  40. "indexCounters" : {
  41. "btree" : {
  42. "accesses" : 59963, # The number of indexes accessed
  43. "hits" : 59963, # So the number of hits
  44. "misses" : 0,# Index deviation number
  45. "resets" : 0,# Reset number
  46. "missRatio" : 0# Miss rate
  47. }
  48. },
  49. "backgroundFlushing" : {
  50. "flushes" : 259,  # Refresh times
  51. "total_ms" : 3395, # Total refresh time
  52. "average_ms" : 13.108108108108109, # Average duration
  53. "last_ms" : 1, # The last time
  54. "last_finished" : ISODate("2011-07-23T06:07:22.725Z")# Last refresh time
  55. },
  56. "cursors" : {
  57. "totalOpen" : 0,# Number of open cursors
  58. "clientCursors_size" : 0,# Client cursor size
  59. "timedOut" : 16# Timeout time
  60. },
  61. "network" : {
  62. "bytesIn" : 285676177,# input data (byte)
  63. "bytesOut" : 286564,# Output data (byte)
  64. "numRequests" : 2012348# Number of requests
  65. },
  66. "opcounters" : {
  67. "insert" : 2010000, # Insert operands
  68. "query" : 51,# Query operands
  69. "update" : 5,# Update operands
  70. "delete" : 0,# Delete operands
  71. "getmore" : 0,# Get more operands
  72. "command" : 148# Other command operands
  73. },
  74. "asserts" : {# The number of assertions
  75. "regular" : 0,
  76. "warning" : 0,
  77. "msg" : 0,
  78. "user" : 2131,
  79. "rollovers" : 0
  80. },
  81. "writeBacksQueued" : false,
  82. "ok" : 1
  83. }

db.stats() View the original status of a library

  1. > db.stats()
  2. {
  3. "db" : "order",# Library name
  4. "collections" : 4,# Set number
  5. "objects" : 2011622,# Record number
  6. "avgObjSize" : 111.92214441878245,# The average of each record
  7. "dataSize" : 225145048,# The total size of the record
  8. "storageSize" : 307323392,# Pre allocated storage space
  9. "numExtents" : 21,# Number of events
  10. "indexes" : 1,# Index number
  11. "indexSize" : 74187744,# So the size
  12. "fileSize" : 1056702464,# file size
  13. "ok" : 1
  14. }

To view the set record

  1. > db.order.stats()
  2. {
  3. "ns" : "order.order",# Namespace
  4. "count" : 2010000,# Record number
  5. "size" : 225039600,# size
  6. "avgObjSize" : 111.96,
  7. "storageSize" : 307186944,
  8. "numExtents" : 18,
  9. "nindexes" : 1,
  10. "lastExtentSize" : 56089856,
  11. "paddingFactor" : 1,
  12. "flags" : 1,
  13. "totalIndexSize" : 74187744,
  14. "indexSizes" : {
  15. "_id_" : 74187744# The index for _id_ The index size of
  16. },
  17. "ok" : 1
  18. }

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

  1. > db.order.find({ "status": 1.0, "user.uid": { $gt: 2663199.0 } }).explain()
  2. {
  3. "cursor" : "BasicCursor",# cursor type
  4. "nscanned" : 2010000,# Number of scans
  5. "nscannedObjects" : 2010000,# Scanning objects
  6. "n" : 337800,# Return the data
  7. "millis" : 2838,# Time consuming
  8. "nYields" : 0,
  9. "nChunkSkips" : 0,
  10. "isMultiKey" : false,
  11. "indexOnly" : false,
  12. "indexBounds" : {# Use index ( Nothing here )
  13. }
  14. }

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

  1. db.order.find({ "status": 1.0, "user.uid": { $gt: 2663199.0 } }).explain()
  2. {
  3. "cursor" : "BtreeCursor user.uid_1",
  4. "nscanned" : 337800,
  5. "nscannedObjects" : 337800,
  6. "n" : 337800,
  7. "millis" : 1371,
  8. "nYields" : 0,
  9. "nChunkSkips" : 0,
  10. "isMultiKey" : false,
  11. "indexOnly" : false,
  12. "indexBounds" : {
  13. "user.uid" : [
  14. [
  15. 2663199,
  16. 1.7976931348623157e+308
  17. ]
  18. ]
  19. }
  20. }

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

  1. 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 ...

  2. Oracle Management monitoring section space utilization monitoring -oracle performance optimization

    SELECT S.OWNER,       S.SEGMENT_NAME,       S.SEGMENT_TYPE,       S.PARTITION_NAME,       ROUND(BYTE ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. MongoDB Learning notes ( Four )-- Indexes && performance optimization

    Indexes                                                                                              Basic index ...

Random recommendation

  1. Swipecards

    https://github.com/Diolor/Swipecards https://github.com/kikoso/Swipeable-Cards

  2. 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. ...

  3. 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 ...

  4. 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 ...

  5. 【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 ...

  6. 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 ...

  7. 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 ...

  8. 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= ...

  9. 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 ...

  10. 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 : ...