如何通过索引加速MongoDB的查找速度?

时间:2015-09-08 10:11:21

标签: performance mongodb indexing wiredtiger

我正在使用带有WiredTiger引擎的MongoDB 3.0.6。每天我都会在日志中看到很多慢查询。像这样:

2015-09-08T11:55:32.767+0200 I QUERY    [conn157653] query assets.items query: { path: "/7ee6cceab7274515eb4b5d1de35639e6" } planSummary: IXSCAN { path: 1.0 } ntoskip:0 nscanned:1 nscannedObjects:1 keyUpdates:0 writeConflicts:0 numYields:0 nreturned:1 reslen:84181 locks:{ Global: { acquireCount: { r: 2 } }, Database: { acquireCount: { r: 1 } }, Collection: { acquireCount: { r: 1 } } } 125ms

我看到此查询使用索引并执行 IXSCAN 。但它太长了。有没有可能加快这个查询?

这是我的索引统计信息:

{
  "ns" : "assets.items",
  "count" : 16470344,
  "size" : NumberLong("1608392512147"),
  "avgObjSize" : 97653,
  "storageSize" : NumberLong("1564940533760"),
  "capped" : false,
  "wiredTiger" : {
    "metadata" : {
      "formatVersion" : 1
    },
    "creationString" : "allocation_size=4KB,app_metadata=(formatVersion=1),block_allocation=best,block_compressor=snappy,cache_resident=0,checkpoint=(WiredTigerCheckpoint.3642=(addr=\"01e31baf1b81e48318bd5ce4034d250ec09ae4db5515d1e402dbc1a4c07ee4850f23a4808080e6016c5db95fc0e601698e5abfc0\",order=3642,time=1441706190,size=1552871514112,write_gen=13958214)),checkpoint_lsn=(35558,53880320),checksum=on,collator=,columns=,dictionary=0,format=btree,huffman_key=,huffman_value=,id=2585,internal_item_max=0,internal_key_max=0,internal_key_truncate=,internal_page_max=4KB,key_format=q,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=64MB,memory_page_max=10m,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=0,prefix_compression_min=4,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,value_format=u,version=(major=1,minor=1)",
    "type" : "file",
    "uri" : "statistics:table:assets/collection-1286-6367141254744722582",
    "LSM" : {
    // ...
    }},
    "block-manager" : {
      "file allocation unit size" : 4096,
      "blocks allocated" : 515519,
      "checkpoint size" : NumberLong("1552871514112"),
      "allocations requiring file extension" : 0,
      "blocks freed" : 496562,
      "file magic number" : 120897,
      "file major version number" : 1,
      "minor version number" : 0,
      "file bytes available for reuse" : 12082257920,
      "file size in bytes" : NumberLong("1564940533760")
    },
    "btree" : {
      "btree checkpoint generation" : 1568,
      "column-store variable-size deleted values" : 0,
      "column-store fixed-size leaf pages" : 0,
      "column-store internal pages" : 0,
      "column-store variable-size leaf pages" : 0,
      "pages rewritten by compaction" : 0,
      "number of key/value pairs" : 0,
      "fixed-record size" : 0,
      "maximum tree depth" : 75,
      "maximum internal page key size" : 368,
      "maximum internal page size" : 4096,
      "maximum leaf page key size" : 3276,
      "maximum leaf page size" : 32768,
      "maximum leaf page value size" : 67108864,
      "overflow pages" : 0,
      "row-store internal pages" : 0,
      "row-store leaf pages" : 0
    },
    "cache" : {
      "bytes read into cache" : 54305601257,
      "bytes written from cache" : 28288529220,
      "checkpoint blocked page eviction" : 191,
      "unmodified pages evicted" : 286870,
      "page split during eviction deepened the tree" : 0,
      "modified pages evicted" : 275984,
      "data source pages selected for eviction unable to be evicted" : 26647,
      "hazard pointer blocked page eviction" : 4310,
      "internal pages evicted" : 208571,
      "pages split during eviction" : 891,
      "in-memory page splits" : 0,
      "overflow values cached in memory" : 0,
      "pages read into cache" : 632202,
      "overflow pages read into cache" : 0,
      "pages written from cache" : 513631
    },
    "compression" : {
      "raw compression call failed, no additional data available" : 0,
      "raw compression call failed, additional data available" : 0,
      "raw compression call succeeded" : 0,
      "compressed pages read" : 229002,
      "compressed pages written" : 149994,
      "page written failed to compress" : 132842,
      "page written was too small to compress" : 230793
    },
    "cursor" : {
      "create calls" : 67,
      "insert calls" : 555941,
      "bulk-loaded cursor-insert calls" : 0,
      "cursor-insert key and value bytes inserted" : 42986335470,
      "next calls" : 0,
      "prev calls" : 1,
      "remove calls" : 0,
      "cursor-remove key bytes removed" : 0,
      "reset calls" : 2630310,
      "search calls" : 2610311,
      "search near calls" : 0,
      "update calls" : 0,
      "cursor-update value bytes updated" : 0
    },
    "reconciliation" : {
      "dictionary matches" : 0,
      "internal page multi-block writes" : 239,
      "leaf page multi-block writes" : 1174,
      "maximum blocks required for a page" : 68,
      "internal-page overflow keys" : 0,
      "leaf-page overflow keys" : 0,
      "overflow values written" : 0,
      "pages deleted" : 0,
      "page checksum matches" : 5423,
      "page reconciliation calls" : 496234,
      "page reconciliation calls for eviction" : 60217,
      "leaf page key bytes discarded using prefix compression" : 0,
      "internal page key bytes discarded using suffix compression" : 20966
    },
    "session" : {
      "object compaction" : 0,
      "open cursor count" : 67
    },
    "transaction" : {
      "update conflicts" : 6814
    }
  },
  "nindexes" : 2,
  "totalIndexSize" : 1008476160,
  "indexSizes" : {
    "_id_" : 216711168,
    "path_1" : 791764992
  },
  "ok" : 1
}

服务器有30Gb的内存,其中一半用于我的WiredTiger缓存。似乎还不够?

0 个答案:

没有答案