Mongo中MongoDB WiredTiger引擎调优技巧有哪些

发布时间:2021-11-11 13:51:53 作者:iii
来源:亿速云 阅读:293

这篇文章主要讲解了“Mongo中MongoDB WiredTiger引擎调优技巧有哪些”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Mongo中MongoDB WiredTiger引擎调优技巧有哪些”吧!

MongoDB3.0开始引入可插拔存储引擎的概念。当前,有不少存储引擎可供选择:MMAPV1WiredTigerMongoRocksTokuSE等等。每个存储引擎都有自己的优势,你需要根据性能要求及应用特征挑选最适合的一个。

3.2.x开始,WiredTiger成为默认的存储引擎。最为MongoDB目前最流行的存储引擎,WiredTiger与原先的MMAPV1相比有以下优势:

接下来,我会展示几个用来调优WiredTiger引擎性能的关键参数。

调优Cache Size

WiredTiger最重要的调优参数就是cache规模。默认,MongoDB3.x开始会保留可用物理内存的50%(3.2是60%)作为数据cache。虽然,默认的设置可以应对大部分的应用,通过调节为特定应用找到最佳配置值还是非常值得的。cache的规模必须足够大,以便保存应用整个工作集(working set)。

除了这个cacheMongoDB在做诸如聚合、排序、连接管理等操作时需要额外的内存。因此,必须确保有足够的内存可供使用,否则,MongoDB进程有被OOM killer杀死的风险。

调节这个参数,首先要理解在默认配置下,cache的使用情况。运行以下命令,可以获得cache统计:

db.serverStatus().wiredTiger.cache

命令输出结果例子如下:

{   "tracked dirty bytes in the cache" : 409861,   "tracked bytes belonging to internal pages in the cache" : 738956332,   "bytes currently in the cache" : 25769360777,   "tracked bytes belonging to leaf pages in the cache" : 31473298388,   "maximum bytes configured" : 32212254720,   "tracked bytes belonging to overflow pages in the cache" : 0,   "bytes read into cache" : 29628550664,   "bytes written from cache" : 34634778285,   "pages evicted by application threads" : 0,   "checkpoint blocked page eviction" : 102,   "unmodified pages evicted" : 333277,   "page split during eviction deepened the tree" : 0,   "modified pages evicted" : 437117,   "pages selected for eviction unable to be evicted" : 44825,   "pages evicted because they exceeded the in-memory maximum" : 74,   "pages evicted because they had chains of deleted items" : 33725,   "failed eviction of pages that exceeded the in-memory maximum" : 1518,   "hazard pointer blocked page eviction" : 34814,   "internal pages evicted" : 21623,   "maximum page size at eviction" : 10486876,   "eviction server candidate queue empty when topping up" : 8235,   "eviction server candidate queue not empty when topping up" : 3020,   "eviction server evicting pages" : 191708,   "eviction server populating queue, but not evicting pages" : 2996,   "eviction server unable to reach eviction goal" : 0,   "pages split during eviction" : 8821,   "pages walked for eviction" : 157970002,   "eviction worker thread evicting pages" : 563015,   "in-memory page splits" : 52,   "percentage overhead" : 8,   "tracked dirty pages in the cache" : 9,   "pages currently held in the cache" : 1499798,   "pages read into cache" : 2260232,   "pages written from cache" : 3018846}

第一个要关注的数值试,cache中脏数据的百分比。如果这个百分比比较高,那么调大cache规模很有可能可以提升性能。如果应用是重读的,可再关注bytes read into cache这个指标。如果这个指标比较高,那么调大cache规模很有可能可以提升读性能。

调节cache规模不一定非得重启服务,我们可以动态调整:

db.adminCommand( { "setParameter": 1, "wiredTigerEngineRuntimeConfig": "cache_size=xxG"})

如果你想让调整在重启后也有效,那么你需要将配置文件也相应调整一下。

控制Read/Write Tickets

WiredTiger使用tickets来控制可以同时被存储引擎处理的读/写操作数。默认值是128,在大部分情况下表现良好。如果这个值经常掉到0,所有后续操作将会被排队等待。例如,观察到读tickets下降,系统可能有大量长耗时的操作(未索引操作)。如果你想找出有哪些慢操作,可以用一些第三方工具。你可以根据系统需要和性能影响上下调节tickets

运行以下命令可以确认tickets的使用情况:

db.serverStatus().wiredTiger.concurrentTransactions

下面是一个输出例子:

{   "write" : {      "out" : 0,      "available" : 128,      "totalTickets" : 128
   },   "read" : {      "out" : 3,      "available" : 128,      "totalTickets" : 128
   }
}

同样,可以动态调节tickets

db.adminCommand( { setParameter: 1, wiredTigerConcurrentReadTransactions: xx } )db.adminCommand( { setParameter: 1, wiredTigerConcurrentWriteTransactions: xx } )

一旦做出调整,注意要观察系统的性能监控确保影响是符合预期的。

感谢各位的阅读,以上就是“Mongo中MongoDB WiredTiger引擎调优技巧有哪些”的内容了,经过本文的学习后,相信大家对Mongo中MongoDB WiredTiger引擎调优技巧有哪些这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

推荐阅读:
  1. mongodb3.4.4安装副本集,wt引擎配置优化(二)
  2. MongoDB升级到3.0以上的Zabbix监控模板变更

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

mongo

上一篇:GBase 8t HDR如何安装测试

下一篇:Django中的unittest应用是什么

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》