I. Index and its optimization
- Overview of Indexes
- The index of a database is like a directory in front of a book that speeds up data queries.
- Appropriate places to increase the index, unreasonable place to delete suboptimal index, can optimize poor performance of the application.
- Operation of the Index
- Base index: Db.ken.ensureIndex ({age:1})//CREATE index on column age
1 name _id_ is a system index and cannot be deleted.
- Silently CREATE INDEX: Db.ken.ensureIndex ({x:1},{background:true}); Background creation
- Document index: Embedded document not indexed
- Composite index: Multiple criteria together
- Unique index: Declaring uniqueness, that is, you cannot insert data with the same condition
- Force use Index: hint ({_id:1})
- Delete index: Db.ken.dropIndex ()
- Rebuild index: Db.ken.reIndex ()
- Use explain to see how a plan is executed
1 Millis field can see the time-consuming situation, indexbound can see whether the index is used, n represents the number of documents returned, nscaned represents the number of documents scanned.
2 If the information is incomplete, you can try to use a different version of the client.
- Optimizer: Profiler
- Open function.
1 can be started by adding parameters:-profiler=1
2 Execution Command: Db.setprofilinglevel (1)
- Query record: Db.system.profiler.find ()
- Performance Tuning Overview
- Performance Optimization principle: Modify one parameter at a time
- Parameters that affect performance: operating system, network, hardware, application server, application, database, query statement
- Common optimization Scheme
- Create a shrink index: When writing less Read more
- Limit number of returned bars: limit
- Query for fields that are used only
- Using capped Colletion
- Using Stored Procedures
- Force the use of indexes
- Using the profiler
Second, performance monitoring
- Mongosniff Tools
- Mongostat Tools
- Using Db.serverstatus ()
- Using Db.stats ()
- HTTP Monitoring interface
MongoDB Performance Chapter