十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
今天大概研究下wiredtiger引擎,mongo從3.0開始引入,主要為了解決吃內(nèi)存多,占用大量磁盤空間的問題,其實即使用了wt引擎,在性能上還是比tokuft要差,但是tokuft 在功能上代碼迭代的太慢,退而求其次大家還是用了mongo,首先3.0的時候默認還是mmapv1 引擎,所以需要重新指定wt引擎,從3.2版本后就是默認了wt了,我用的現(xiàn)在是3.4 主要是配置上的優(yōu)化,看了好多人的寫的東西,都特么是抄的,我寫個官方文檔上的吧,以此記錄
創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于網(wǎng)站建設(shè)、做網(wǎng)站、德化網(wǎng)絡(luò)推廣、微信平臺小程序開發(fā)、德化網(wǎng)絡(luò)營銷、德化企業(yè)策劃、德化品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎;創(chuàng)新互聯(lián)為所有大學生創(chuàng)業(yè)者提供德化建站搭建服務(wù),24小時服務(wù)熱線:18982081108,官方網(wǎng)址:www.cdcxhl.com
storage.wiredTiger Options storage: wiredTiger: engineConfig: cacheSizeGB:journalCompressor: directoryForIndexes: collectionConfig: blockCompressor: indexConfig: prefixCompression:
這個是官方的,一下是我自己的
storage: dbPath: /var/lib/mongo journal: enabled: true # engine: # mmapv1: # wiredTiger: wiredTiger: engineConfig: cacheSizeGB: 0.25 ###這里Size是WT本身的Cache大小并不代表Mongod使用的內(nèi)存, ###默認是Max(1G,內(nèi)存的1/2),這里盡可能給多一些吧,盡量把熱數(shù)據(jù)都可以Cache住, ###保證Dirty 不要超過1%,當然這個跟自己的業(yè)務(wù)、讀寫查詢快慢有關(guān), ###另外它Cache的單位是Page而不是Document。 journalCompressor: snappy ##單獨為Journal Log指定壓縮方式,默認snappy,支持"none、snappy、zlib", ##一般情況下不需要用zlib,雖然壓縮率較大,但cpu的占用率也高。 directoryForIndexes: true ## Index文件和數(shù)據(jù)文件分離,索引一個目錄,數(shù)據(jù)一個目錄。 collectionConfig: blockCompressor: zlib ####數(shù)據(jù)庫中Collection的壓縮方式,默認是snappy,同樣支持"none、snappy、zlib"", ####一般snappy足夠,snappy cpu使用率較低,壓縮率不是非常高,但可以滿足一般業(yè)務(wù)需求, ####zlib是壓縮率最高的,cpu使用率也較高,如果cpu資源充裕,就為了降低磁盤空間可以選擇zlib。 indexConfig: prefixCompression: true ###是否開啟索引的前綴壓縮,這里影響所有DB的索引。它會一次存儲所有前綴一樣的索引, ###減少內(nèi)存、磁盤IO的消耗,默認開啟。
官方原文:
Values can range from 256MB to 10TB and can be a float. In addition, the default value has also changed.
Starting in 3.4, the WiredTiger internal cache, by default, will use the larger of either:
50% of RAM minus 1 GB, or
256 MB.
Avoid increasing the WiredTiger internal cache size above its default value.
With WiredTiger, MongoDB utilizes both the WiredTiger internal cache and the filesystem cache.
Via the filesystem cache, MongoDB automatically uses all free memory that is not used by the WiredTiger cache or by other processes. Data in the filesystem cache is compressed.
由此可以看出,在內(nèi)存足夠大的情況下,還是要以提高cpu性能為主,zlib雖然是最高壓縮,但也最吃cpu另外,在存儲引擎切換的時候,先從second開始,進入服務(wù)器,db.shutdownServer(),把服務(wù)器關(guān)掉,然后清空所有數(shù)據(jù),然后配置wt引擎,然后在掛載回去,進行重新同步
官方的原文:http://docs.mongoing.com/manual-zh/tutorial/change-replica-set-wiredtiger.html
這個步驟將復制集中 secondary 的數(shù)據(jù)完全移除, 然后使用 WiredTiger 存儲引擎重啟 mongod, 利用:doc:`初始化同步 完成數(shù)據(jù)同步.
在升級復制集中的成員存儲引擎時, 首先升級 secondary 成員. 然后將 primary 降級為從節(jié)點, 之后升級降級為從節(jié)點的成員.
1
In the mongo shell, shut down the secondary mongod instance you wish to upgrade.
db.shutdownServer()
2
Prepare a data directory for the new mongod instance that will run with the WiredTiger storage engine.mongod must have read and write permissions for this directory. You can either delete the contents of the stopped secondary member’s current data directory or create a new directory entirely.
mongod with WiredTiger will not start with data files created with a different storage engine.
3
Start mongod, specifying wiredTiger as the --storageEngine and the prepared data directory for WiredTiger as the --dbpath. Specify additional options as appropriate for this replica set member.
mongod --storageEngine wiredTiger --dbpath--replSet
Since no data exists in the --dbpath, the mongod will perform an initial sync. The length of the initial sync process depends on the size of the database and network connection between members of the replica set.
You can also specify the options in a configuration file. To specify the storage engine, use thestorage.engine setting.
4
Perform this procedure again for the rest of the secondary members of the replica set you wish to use the WiredTiger storage engine.