Try   HackMD

MongoDB Performance
ch3 Index Operations

tags: MongoDB University M201

Building Indexes

  • Foreground indexes are fase, but block operations
  • Background indexes are slow, but don't block operations

For feature compatibility version (fcv) "4.2", all index builds use an optimized build process that holds the exclusive lock only at the beginning and end of the build process. The rest of the build process yields to interleaving read and write operations. MongoDB ignores the background option if specified.

  • currentOp()
  • killOp(<opid>)

Understanding Explain

Using explain is best way to analyze what heppen when the query executed even without the query being executed.

db.<collection>.explain('<argument>')

argument

  • queryPlanner (default)
    • not actual executed
  • executionStats
    • actual executed
  • allPlansExecution
    • actual executed

Sort_key_generator: in memory sort
If a sort uses more than 32 mb, then the server is going to cancel that query

Hint()

To select the index to query manually

db.people.find( { name: 'John Doe', zipCode: { $gt: '63000' } } ).hint ( 'index_name' )

Resource Allocation for Indexes

  • Determine Index Size
  • Resource Allocation
  • Edge Case

Determine Index Size

  • db.stats()
  • db.<collection>.stats()

Resource Allocation

  • Disk
  • Memory (RAM)
// get memory size in cache let stats = db.<collection>.stats({1'indexDetail: true'}) stats.indexDetails.endstation_name_1.cache

Edge Case

  • Occasional Reports
  • Right-end-side index increments

Basic Benchmarking

Types of Performance Benchmarking

  • Public test suite
  • Specific or Private Testing environment

Low Level Benchmarking

  • File I/O Performance
  • Scheduler Performance
  • Memory allocation and transfer speed
  • Thread performance
  • Database server performance
  • Translation Isolation

Database server Benchmarking

  • Data set load
  • Writes per second
  • Reads per second
  • Balanced work loads
  • Read/Write ratio

Distributed Systems Benchmarking

  • Linearization
  • Serialization
  • Fault tolerance