如何提高Mongo DB的性能

时间:2019-11-21 16:50:10

标签: mongodb

我想知道如何调整数据库设置以提高性能。

是否有关于如何修改设置以及检查当前设置是否最佳的文档?

谢谢

CPU

$ lscpu | egrep 'Model name|Socket|Thread|NUMA|CPU\(s\)'
CPU(s):                2
On-line CPU(s) list:   0,1
Thread(s) per core:    2
Socket(s):             1
NUMA node(s):          1
Model name:            Intel(R) Xeon(R) CPU E5-2686 v4 @ 2.30GHz
NUMA node0 CPU(s):     0,1

RAM

$ free -h
             total       used       free     shared    buffers     cached
Mem:           14G        10G       4.3G        76K        76M       4.2G
-/+ buffers/cache:       6.3G       8.6G
Swap:           0B         0B         0B

数据库信息

db.runCommand( { serverStatus: 1,  repl: 1 } )
{
        "host" : "ip-10-3-0-**",
        "version" : "4.0.10",
        "process" : "mongod",
        "pid" : NumberLong(2876),
        "uptime" : 7080678,
        "uptimeMillis" : NumberLong("7080678195"),
        "uptimeEstimate" : NumberLong(7080678),
        "localTime" : ISODate("2019-11-21T16:31:18.272Z"),
        "asserts" : {
                "regular" : 0,
                "warning" : 0,
                "msg" : 0,
                "user" : 390,
                "rollovers" : 0
        },
        "connections" : {
                "current" : 142,
                "available" : 51058,
                "totalCreated" : 30276,
                "active" : 2
        },
        "extra_info" : {
                "note" : "fields vary by platform",
                "page_faults" : 70
        },
        "freeMonitoring" : {
                "state" : "enabled",
                "retryIntervalSecs" : NumberLong(60),
                "lastRunTime" : "2019-11-21T16:30:49.082+0000",
                "registerErrors" : NumberLong(0),
                "metricsErrors" : NumberLong(0)
        },
        "globalLock" : {
                "totalTime" : NumberLong("7080678108000"),
                "currentQueue" : {
                        "total" : 0,
                        "readers" : 0,
                        "writers" : 0
                },
                "activeClients" : {
                        "total" : 183,
                        "readers" : 0,
                        "writers" : 0
                }
        },
        "locks" : {
                "Global" : {
                        "acquireCount" : {
                                "r" : NumberLong("2270490755"),
                                "w" : NumberLong(13923421),
                                "W" : NumberLong(20)
                        },
                        "acquireWaitCount" : {
                                "r" : NumberLong(2),
                                "W" : NumberLong(1)
                        },
                        "timeAcquiringMicros" : {
                                "r" : NumberLong(94559),
                                "W" : NumberLong(3721)
                        }
                },
                "Database" : {
                        "acquireCount" : {
                                "r" : NumberLong(1958002541),
                                "w" : NumberLong(13213287),
                                "R" : NumberLong(8),
                                "W" : NumberLong(2041)
                        },
                        "acquireWaitCount" : {
                                "r" : NumberLong(5),
                                "w" : NumberLong(509),
                                "W" : NumberLong(553)
                        },
                        "timeAcquiringMicros" : {
                                "r" : NumberLong(21591),
                                "w" : NumberLong(4328973),
                                "W" : NumberLong(7395246)
                        }
                },
                "Collection" : {
                        "acquireCount" : {
                                "r" : NumberLong(1902428633),
                                "w" : NumberLong(13211987)
                        }
                },
                "oplog" : {
                        "acquireCount" : {
                                "r" : NumberLong(55575425),
                                "w" : NumberLong(58)
                        }
                }
        },
        "logicalSessionRecordCache" : {
                "activeSessionsCount" : 13,
                "sessionsCollectionJobCount" : 23603,
                "lastSessionsCollectionJobDurationMillis" : 18,
                "lastSessionsCollectionJobTimestamp" : ISODate("2019-11-21T16:30:03.160Z"),
                "lastSessionsCollectionJobEntriesRefreshed" : 25,
                "lastSessionsCollectionJobEntriesEnded" : 1,
                "lastSessionsCollectionJobCursorsClosed" : 0,
                "transactionReaperJobCount" : 23603,
                "lastTransactionReaperJobDurationMillis" : 6,
                "lastTransactionReaperJobTimestamp" : ISODate("2019-11-21T16:30:03.157Z"),
                "lastTransactionReaperJobEntriesCleanedUp" : 1
        },
        "network" : {
                "bytesIn" : NumberLong("29953505953"),
                "bytesOut" : NumberLong("52003517135"),
                "physicalBytesIn" : NumberLong("23240368906"),
                "physicalBytesOut" : NumberLong("40682951564"),
                "numRequests" : NumberLong(66199009),
                "compression" : {
                        "snappy" : {
                                "compressor" : {
                                        "bytesIn" : NumberLong("28540070491"),
                                        "bytesOut" : NumberLong("16795429270")
                                },
                                "decompressor" : {
                                        "bytesIn" : NumberLong("15672880665"),
                                        "bytesOut" : NumberLong("23939907798")
                                }
                        }
                },
                "serviceExecutorTaskStats" : {
                        "executor" : "passthrough",
                        "threadsRunning" : 142
                }
        },
        "opLatencies" : {
                "reads" : {
                        "latency" : NumberLong("2215676124710"),
                        "ops" : NumberLong(12605100)
                },
                "writes" : {
                        "latency" : NumberLong("5348114919"),
                        "ops" : NumberLong(5870693)
                },
                "commands" : {
                        "latency" : NumberLong("2446973989"),
                        "ops" : NumberLong(47723214)
                },
                "transactions" : {
                        "latency" : NumberLong(0),
                        "ops" : NumberLong(0)
                }
        },
        "opReadConcernCounters" : {
                "available" : NumberLong(0),
                "linearizable" : NumberLong(0),
                "local" : NumberLong(0),
                "majority" : NumberLong(0),
                "snapshot" : NumberLong(0),
                "none" : NumberLong(1547227)
        },
        "opcounters" : {
                "insert" : 15274649,
                "query" : 1547227,
                "update" : 5872104,
                "delete" : 173652,
                "getmore" : 11124026,
                "command" : 47772895
        },
        "opcountersRepl" : {
                "insert" : 9668,
                "query" : 0,
                "update" : 2451,
                "delete" : 71,
                "getmore" : 0,
                "command" : 0
        },
        "repl" : {
                "hosts" : [
                        "10.3.80.**:27017",
                        "10.3.0.**:27017",
                        "10.3.62.**:27017"
                ],
                "setName" : "s0",
                "setVersion" : 1,
                "ismaster" : true,
                "secondary" : false,
                "primary" : "10.3.0.**:27017",
                "me" : "10.3.0.**:27017",
                "electionId" : ObjectId("7fffffff0000000000000007"),
                "lastWrite" : {
                        "opTime" : {
                                "ts" : Timestamp(1574353875, 2),
                                "t" : NumberLong(7)
                        },
                        "lastWriteDate" : ISODate("2019-11-21T16:31:15Z"),
                        "majorityOpTime" : {
                                "ts" : Timestamp(1574353875, 2),
                                "t" : NumberLong(7)
                        },
                        "majorityWriteDate" : ISODate("2019-11-21T16:31:15Z")
                },
                "replicationProgress" : [
                        {
                                "optime" : {
                                        "ts" : Timestamp(1574353875, 2),
                                        "term" : NumberLong(7)
                                },
                                "host" : "10.3.80.**:27017",
                                "memberId" : 1
                        },
                        {
                                "optime" : {
                                        "ts" : Timestamp(1574353875, 2),
                                        "term" : NumberLong(7)
                                },
                                "host" : "10.3.0.**:27017",
                                "memberId" : 2
                        },
                        {
                                "optime" : {
                                        "ts" : Timestamp(1574353875, 2),
                                        "term" : NumberLong(7)
                                },
                                "host" : "10.3.62.61:27017",
                                "memberId" : 3
                        }
                ],
                "rbid" : 1
        },
        "storageEngine" : {
                "name" : "wiredTiger",
                "supportsCommittedReads" : true,
                "supportsSnapshotReadConcern" : true,
                "readOnly" : false,
                "persistent" : true
        },
        "tcmalloc" : {
                "generic" : {
                        "current_allocated_bytes" : NumberLong("5806015912"),
                        "heap_size" : NumberLong("7962251264")
                },
                "tcmalloc" : {
                        "pageheap_free_bytes" : 852889600,
                        "pageheap_unmapped_bytes" : 1040392192,
                        "max_total_thread_cache_bytes" : NumberLong(1073741824),
                        "current_total_thread_cache_bytes" : 38479952,
                        "total_free_bytes" : 262953560,
                        "central_cache_free_bytes" : 220818344,
                        "transfer_cache_free_bytes" : 3655264,
                        "thread_cache_free_bytes" : 38479952,
                        "aggressive_memory_decommit" : 0,
                        "pageheap_committed_bytes" : NumberLong("6921859072"),
                        "pageheap_scavenge_count" : 650885,
                        "pageheap_commit_count" : 1398392,
                        "pageheap_total_commit_bytes" : NumberLong("1633218453504"),
                        "pageheap_decommit_count" : 738136,
                        "pageheap_total_decommit_bytes" : NumberLong("1626296594432"),
                        "pageheap_reserve_count" : 1801,
                        "pageheap_total_reserve_bytes" : NumberLong("7962251264"),
                        "spinlock_total_delay_ns" : NumberLong("5671177894"),
                        "formattedString" : "------------------------------------------------\nMALLOC:     5806016488 ( 5537.0 MiB) Bytes in use by application\nMALLOC: +    852889600 (  813.4 MiB) Bytes in page heap freelist\nMALLOC: +    220818344 (  210.6 MiB) Bytes in central cache freelist\nMALLOC: +      3655264 (    3.5 MiB) Bytes in transfer cache freelist\nMALLOC: +     38479376 (   36.7 MiB) Bytes in thread cache freelists\nMALLOC: +     48783616 (   46.5 MiB) Bytes in malloc metadata\nMALLOC:   ------------\nMALLOC: =   6970642688 ( 6647.7 MiB) Actual memory used (physical + swap)\nMALLOC: +   1040392192 (  992.2 MiB) Bytes released to OS (aka unmapped)\nMALLOC:   ------------\nMALLOC: =   8011034880 ( 7639.9 MiB) Virtual address space used\nMALLOC:\nMALLOC:         435196              Spans in use\nMALLOC:            200              Thread heaps in use\nMALLOC:           4096              Tcmalloc page size\n------------------------------------------------\nCall ReleaseFreeMemory() to release freelist memory to the OS (via madvise()).\nBytes released to the OS take up virtual address space but no physical memory.\n"
                }
        },
        "transactions" : {
                "retriedCommandsCount" : NumberLong(56),
                "retriedStatementsCount" : NumberLong(56),
                "transactionsCollectionWriteCount" : NumberLong(5048993),
                "currentActive" : NumberLong(0),
                "currentInactive" : NumberLong(0),
                "currentOpen" : NumberLong(0),
                "totalAborted" : NumberLong(0),
                "totalCommitted" : NumberLong(0),
                "totalStarted" : NumberLong(0)
        },
        "transportSecurity" : {
                "1.0" : NumberLong(0),
                "1.1" : NumberLong(0),
                "1.2" : NumberLong(0),
                "1.3" : NumberLong(0),
                "unknown" : NumberLong(0)
        },
        "wiredTiger" : {
                "uri" : "statistics:",
                "LSM" : {
                        "application work units currently queued" : 0,
                        "merge work units currently queued" : 0,
                        "rows merged in an LSM tree" : 0,
                        "sleep for LSM checkpoint throttle" : 0,
                        "sleep for LSM merge throttle" : 0,
                        "switch work units currently queued" : 0,
                        "tree maintenance operations discarded" : 0,
                        "tree maintenance operations executed" : 0,
                        "tree maintenance operations scheduled" : 0,
                        "tree queue hit maximum" : 0
                },
                "async" : {
                        "current work queue length" : 0,
                        "maximum work queue length" : 0,
                        "number of allocation state races" : 0,
                        "number of flush calls" : 0,
                        "number of operation slots viewed for allocation" : 0,
                        "number of times operation allocation failed" : 0,
                        "number of times worker found no work" : 0,
                        "total allocations" : 0,
                        "total compact calls" : 0,
                        "total insert calls" : 0,
                        "total remove calls" : 0,
                        "total search calls" : 0,
                        "total update calls" : 0
                },
                "block-manager" : {
                        "blocks pre-loaded" : 11272,
                        "blocks read" : 685129,
                        "blocks written" : 4031443,
                        "bytes read" : 3191664640,
                        "bytes written" : 37255380992,
                        "bytes written for checkpoint" : 35048415232,
                        "mapped blocks read" : 0,
                        "mapped bytes read" : 0
                },
                "cache" : {
                        "application threads page read from disk to cache count" : 45445,
                        "application threads page read from disk to cache time (usecs)" : 5222318,
                        "application threads page write from cache to disk count" : 2538144,
                        "application threads page write from cache to disk time (usecs)" : 100726874,
                        "bytes belonging to page images in the cache" : 4136571589,
                        "bytes belonging to the cache overflow table in the cache" : 182,
                        "bytes currently in the cache" : 5934061222,
                        "bytes dirty in the cache cumulative" : 1090081699698,
                        "bytes not belonging to page images in the cache" : 1797489633,
                        "bytes read into cache" : 2148484516,
                        "bytes written from cache" : 47853403441,
                        "cache overflow cursor application thread wait time (usecs)" : 0,
                        "cache overflow cursor internal thread wait time (usecs)" : 0,
                        "cache overflow score" : 0,
                        "cache overflow table entries" : 0,
                        "cache overflow table insert calls" : 0,
                        "cache overflow table remove calls" : 0,
                        "checkpoint blocked page eviction" : 2,
                        "eviction calls to get a page" : 456487,
                        "eviction calls to get a page found queue empty" : 397157,
                        "eviction calls to get a page found queue empty after locking" : 687,
                        "eviction currently operating in aggressive mode" : 0,
                        "eviction empty score" : 0,
                        "eviction passes of a file" : 268732,
                        "eviction server candidate queue empty when topping up" : 675,
                        "eviction server candidate queue not empty when topping up" : 804,
                        "eviction server evicting pages" : 0,
                        "eviction server slept, because we did not make progress with eviction" : 81597,
                        "eviction server unable to reach eviction goal" : 0,
                        "eviction state" : 32,
                        "eviction walk target pages histogram - 0-9" : 267742,
                        "eviction walk target pages histogram - 10-31" : 424,
                        "eviction walk target pages histogram - 128 and higher" : 0,
                        "eviction walk target pages histogram - 32-63" : 93,
                        "eviction walk target pages histogram - 64-128" : 473,
                        "eviction walks abandoned" : 14889,
                        "eviction walks gave up because they restarted their walk twice" : 232897,
                        "eviction walks gave up because they saw too many pages and found no candidates" : 15832,
                        "eviction walks gave up because they saw too many pages and found too few candidates" : 101,
                        "eviction walks reached end of tree" : 490268,
                        "eviction walks started from root of tree" : 262985,
                        "eviction walks started from saved location in tree" : 5747,
                        "eviction worker thread active" : 4,
                        "eviction worker thread created" : 0,
                        "eviction worker thread evicting pages" : 58611,
                        "eviction worker thread removed" : 0,
                        "eviction worker thread stable number" : 0,
                        "failed eviction of pages that exceeded the in-memory maximum count" : 2906,
                        "failed eviction of pages that exceeded the in-memory maximum time (usecs)" : 4341,
                        "files with active eviction walks" : 0,
                        "files with new eviction walks started" : 257371,
                        "force re-tuning of eviction workers once in a while" : 0,
                        "hazard pointer blocked page eviction" : 1794,
                        "hazard pointer check calls" : 69369,
                        "hazard pointer check entries walked" : 2623918,
                        "hazard pointer maximum array length" : 59,
                        "in-memory page passed criteria to be split" : 6259,
                        "in-memory page splits" : 2172,
                        "internal pages evicted" : 4156,
                        "internal pages split during eviction" : 20,
                        "leaf pages split during eviction" : 2658,
                        "maximum bytes configured" : 7476346880,
                        "maximum page size at eviction" : 0,
                        "modified pages evicted" : 11044,
                        "modified pages evicted by application threads" : 0,
                        "operations timed out waiting for space in cache" : 0,
                        "overflow pages read into cache" : 0,
                        "page split during eviction deepened the tree" : 0,
                        "page written requiring cache overflow records" : 0,
                        "pages currently held in the cache" : 121858,
                        "pages evicted because they exceeded the in-memory maximum count" : 2749,
                        "pages evicted because they exceeded the in-memory maximum time (usecs)" : 1721371,
                        "pages evicted because they had chains of deleted items count" : 4960,
                        "pages evicted because they had chains of deleted items time (usecs)" : 472591,
                        "pages evicted by application threads" : 0,
                        "pages queued for eviction" : 78454,
                        "pages queued for urgent eviction" : 1264,
                        "pages queued for urgent eviction during walk" : 606,
                        "pages read into cache" : 46246,
                        "pages read into cache after truncate" : 1376,
                        "pages read into cache after truncate in prepare state" : 0,
                        "pages read into cache requiring cache overflow entries" : 0,
                        "pages read into cache requiring cache overflow for checkpoint" : 0,
                        "pages read into cache skipping older cache overflow entries" : 0,
                        "pages read into cache with skipped cache overflow entries needed later" : 0,
                        "pages read into cache with skipped cache overflow entries needed later by checkpoint" : 0,
                        "pages requested from the cache" : 117658575637,
                        "pages seen by eviction walk" : 3351222,
                        "pages selected for eviction unable to be evicted" : 3113,
                        "pages walked for eviction" : 5655202,
                        "pages written from cache" : 2752326,
                        "pages written requiring in-memory restoration" : 1297,
                        "percentage overhead" : 8,
                        "tracked bytes belonging to internal pages in the cache" : 18074503,
                        "tracked bytes belonging to leaf pages in the cache" : 5915986719,
                        "tracked dirty bytes in the cache" : 4002055,
                        "tracked dirty pages in the cache" : 13,
                        "unmodified pages evicted" : 53315
                },
                "capacity" : {
                        "background fsync file handles considered" : 0,
                        "background fsync file handles synced" : 0,
                        "background fsync time (msecs)" : 0,
                        "threshold to call fsync" : 0,
                        "throttled bytes read" : 0,
                        "throttled bytes written for checkpoint" : 0,
                        "throttled bytes written for eviction" : 0,
                        "throttled bytes written for log" : 0,
                        "throttled bytes written total" : 0,
                        "time waiting due to total capacity (usecs)" : 0,
                        "time waiting during checkpoint (usecs)" : 0,
                        "time waiting during eviction (usecs)" : 0,
                        "time waiting during logging (usecs)" : 0,
                        "time waiting during read (usecs)" : 0
                },
                "connection" : {
                        "auto adjusting condition resets" : 2265374,
                        "auto adjusting condition wait calls" : 45844599,
                        "detected system time went backwards" : 0,
                        "files currently open" : 368,
                        "memory allocations" : 993391995,
                        "memory frees" : 984677910,
                        "memory re-allocations" : 165217512,
                        "pthread mutex condition wait calls" : 121181755,
                        "pthread mutex shared lock read-lock calls" : 1978821693,
                        "pthread mutex shared lock write-lock calls" : 82484974,
                        "total fsync I/Os" : 6593134,
                        "total read I/Os" : 924233,
                        "total write I/Os" : 9866649
                },
                "cursor" : {
                        "cached cursor count" : 494,
                        "cursor close calls that result in cache" : 61009274,
                        "cursor create calls" : 14367207,
                        "cursor insert calls" : 63580327,
                        "cursor modify calls" : 1796784,
                        "cursor next calls" : 204385588679,
                        "cursor operation restarted" : 14835,
                        "cursor prev calls" : 17970,
                        "cursor remove calls" : 2821892,
                        "cursor reserve calls" : 0,
                        "cursor reset calls" : 2320042889,
                        "cursor search calls" : 57966138156,
                        "cursor search near calls" : 1605149499,
                        "cursor sweep buckets" : 101542918,
                        "cursor sweep cursors closed" : 1302,
                        "cursor sweep cursors examined" : 6431248,
                        "cursor sweeps" : 16923590,
                        "cursor update calls" : 0,
                        "cursors reused from cache" : 60627612,
                        "open cursor count" : 26,
                        "truncate calls" : 70
                },
                ...

        "mem" : {
                "bits" : 64,
                "resident" : 6608,
                "virtual" : 9108,
                "supported" : true,
                "mapped" : 0,
                "mappedWithJournal" : 0
        },
        "metrics" : {
                "commands" : {
                        "<UNKNOWN>" : NumberLong(0),
                        "_cloneCatalogData" : {
                                "failed" : NumberLong(0),
                                "total" : NumberLong(0)
                        },
                        "_cloneCollectionOptionsFromPrimaryShard" : {
                                "failed" : NumberLong(0),
                                "total" : NumberLong(0)
                        },
                       ...
}

0 个答案:

没有答案