1. 程式人生 > >mongodb3.4.4安裝副本集,wt引擎配置優化(二)

mongodb3.4.4安裝副本集,wt引擎配置優化(二)

記錄 空間

今天大概研究下wiredtiger引擎,mongo從3.0開始引入,主要為了解決吃內存多,占用大量磁盤空間的問題,其實即使用了wt引擎,在性能上還是比tokuft要差,但是tokuft 在功能上代碼叠代的太慢,退而求其次大家還是用了mongo,首先3.0的時候默認還是mmapv1 引擎,所以需要重新指定wt引擎,從3.2版本後就是默認了wt了,我用的現在是3.4 主要是配置上的優化,看了好多人的寫的東西,都特麽是抄的,我寫個官方文檔上的吧,以此記錄

storage.wiredTiger Options
storage:
   wiredTiger:
      engineConfig:
         cacheSizeGB: <number>
         journalCompressor: <string>
         directoryForIndexes: <boolean>
      collectionConfig:
         blockCompressor: <string>
      indexConfig:
         prefixCompression: <boolean>

這個是官方的,一下是我自己的

storage:
  dbPath: /var/lib/mongo
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:
   wiredTiger:
      engineConfig:
         cacheSizeGB: 0.25  
         ###這裏Size是WT本身的Cache大小並不代表Mongod使用的內存,
         ###默認是Max(1G,內存的1/2),這裏盡可能給多一些吧,盡量把熱數據都可以Cache住,
         ###保證Dirty 不要超過1%,當然這個跟自己的業務、讀寫查詢快慢有關,
         ###另外它Cache的單位是Page而不是Document。
         
         journalCompressor: snappy
         ##單獨為Journal Log指定壓縮方式,默認snappy,支持"none、snappy、zlib",
         ##一般情況下不需要用zlib,雖然壓縮率較大,但cpu的占用率也高。
         
         directoryForIndexes: true   ## Index文件和數據文件分離,索引一個目錄,數據一個目錄。
      collectionConfig:
         blockCompressor: zlib
         ####數據庫中Collection的壓縮方式,默認是snappy,同樣支持"none、snappy、zlib"",
         ####一般snappy足夠,snappy cpu使用率較低,壓縮率不是非常高,但可以滿足一般業務需求,
         ####zlib是壓縮率最高的,cpu使用率也較高,如果cpu資源充裕,就為了降低磁盤空間可以選擇zlib。
      indexConfig:
         prefixCompression: true
         ###是否開啟索引的前綴壓縮,這裏影響所有DB的索引。它會一次存儲所有前綴一樣的索引,
         ###減少內存、磁盤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.

由此可以看出,在內存足夠大的情況下,還是要以提高cpu性能為主,zlib雖然是最高壓縮,但也最吃cpu另外,在存儲引擎切換的時候,先從second開始,進入服務器,db.shutdownServer(),把服務器關掉,然後清空所有數據,然後配置wt引擎,然後在掛載回去,進行重新同步

官方的原文:http://docs.mongoing.com/manual-zh/tutorial/change-replica-set-wiredtiger.html

步驟

這個步驟將復制集中 secondary 的數據完全移除, 然後使用 WiredTiger 存儲引擎重啟 mongod, 利用:doc:`初始化同步 完成數據同步.

在升級復制集中的成員存儲引擎時, 首先升級 secondary 成員. 然後將 primary 降級為從節點, 之後升級降級為從節點的成員.

1

Shut down the secondary member.

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 running with WiredTiger.

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 with WiredTiger.

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 <newWiredTigerDBPath> --replSet <replSetName>

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

Repeat the procedure for other replica set secondaries you wish to upgrade.

Perform this procedure again for the rest of the secondary members of the replica set you wish to use the WiredTiger storage engine.


mongodb3.4.4安裝副本集,wt引擎配置優化(二)