一、提高副本集寫的速率
1、通過設置Write Concern for Replica Sets¶
cfg = rs.conf()
##cfg.settings.getLastErrorDefaults = { w: "majority", wtimeout: 5000 }
cfg.settings.getLastErrorDefaults ={w:1}
rs.reconfig(cfg)
2、insert數據時帶上配置參數
db.products.insert(
{ item: "envelopes", qty : 100, type: "Clasp" },
##{ writeConcern: { w: "majority" , wtimeout: 5000 } }
{ writeConcern: { w: 1 } }
)
配置w:1,入庫速度34m,提升到14m(500w數據),但是當主庫數據導入完畢后,從庫一直在追趕應用主庫日志
3、w
Option¶
The w
option requests acknowledgment that the write operation has propagated to a specified number of mongod
instances or to mongod
instances with specified tags.
Using the w
option, the following w: <value>
write concerns are available:
Value | Description |
---|---|
|
Requests acknowledgment that the write operation has propagated to the specified number of
Note Hidden, delayed, and priority 0 members can acknowledge Delayed secondaries can return write acknowledgment no earlier than the configured See Acknowledgment Behavior for when |
|
Requests acknowledgment that write operations have propagated to the calculated majority of the data-bearing voting members (i.e. primary and secondaries with For example, consider a replica set with 3 voting members, Primary-Secondary-Secondary (P-S-S). For this replica set, calculated majority is two, and the write must propagate to the primary and one secondary to acknowledge the write concern to the client. Note Hidden, delayed, and priority 0 members with Delayed secondaries can return write acknowledgment no earlier than the configured After the write operation returns with a See Acknowledgment Behavior for when |
|
Requests acknowledgment that the write operations have propagated to For an example, see Custom Multi-Datacenter Write Concerns. See Acknowledgment Behavior for when |
二、提高副本集讀取效率
PSA 3-member Architecture¶
Starting in MongoDB 3.6, "majority"
read concern, available for WiredTiger, is enabled by default. However, for MongoDB 4.0.3+, if you have a three-member replica set with a primary-secondary-arbiter (PSA) architecture, you can disable "majority"
read concern. Disabling "majority"
for a three member PSA architecture avoids possible cache-pressure build up.
The procedure below disables "majority"
read concern for MongoDB 4.0.3 PSA architecture by including --enableMajorityReadConcern false
. If you are running a MongoDB 4.0.1 or 4.0.2 PSA architecture, first upgrade to the latest 4.0 version in order to disable this read concern.
Note
Disabling "majority"
read concern disables support for Change Streams for MongoDB 4.0 and earlier. For MongoDB 4.2+, disabling read concern "majority"
has no effect on change streams availability.
For more information on PSA architecture and read concern "majority"
, see Disable Read Concern Majority.
相關文章
https://www.jianshu.com/p/c8236068204c
https://yq.aliyun.com/articles/60553
https://blog.csdn.net/qq_33642970/article/details/104155807