MongoDB 訪問超時
阿新 • • 發佈:2020-08-07
MongoDB版本:3.2.6
cacheSizeGB: 32
引擎:WiredTiger
架構:副本集
業務請求MongoDB出現超時現象。
檢視MongoDB日誌,存在大量的慢更新語句,通過netdata檢視伺服器監控,排除io問題,發現單核CPU持續出現100%
通過pidstat檢視MongoDB程序的CPU使用情況
[root@127-0-0-1 ~]# pidstat -t -p ALL |grep mongod
懷疑mongodb自身刷髒頁,通過perf檢視mongod程序
[root@127-0-0-1 ~]# perf top -p pid
再選擇 Annotate,找出熱點(可以精確到 CPU 指令):(忘記截圖,隨便截一個)
為了保證線上業務的可用和穩定性,先切換primary為業務提供正常的服務。
解決方法:
1、將版本升級到3.2.10,官方修復了該問題
2、eviction 引數調優:降低eviction_target 或 eviction_dirty_target,讓evict 儘早將資料從 wiredtiger 的 cache 刷到作業系統的 page cache,以便提早刷盤。
db.runCommand({setParameter: 1, wiredTigerEngineRuntimeConfig: "eviction_dirty_target=5,eviction_target=80"})