MongoDB副本集提高读写速率

摘要:
5000}cfg.settings.getLastErrorDefaults={w:type:{w:w:thej:andPriority0成员扫描确认:

一、提高副本集写的速率

MongoDB副本集提高读写速率第1张

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: } }
)

配置w:1,入库速度34m,提升到14m(500w数据),但是当主库数据导入完毕后,从库一直在追赶应用主库日志

MongoDB副本集提高读写速率第2张

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:

ValueDescription
<number>

Requests acknowledgment that the write operation has propagated to the specified number of mongod instances. For example:

w: 1
Requests acknowledgment that the write operation has propagated to the standalone mongod or the primary in a replica set. w: 1 is the default write concern for MongoDB.
w: 0

Requests no acknowledgment of the write operation. However, w: 0 may return information about socket exceptions and networking errors to the application.

If you specify w: 0 but include j: true, the j: true prevails to request acknowledgment from the standalone mongod or the primary of a replica set.

w greater than 1 requires acknowledgment from the primary and as many additional data-bearing secondaries to meet the specified write concern. For example, consider a 3-member replica set with no arbiters. Specifying w: 2 would require acknowledgment from the primary and one of the secondaries. Specifying w: 3 would require acknowledgment from the primary and both secondaries.

Note

Hidden, delayed, and priority 0 members can acknowledge w: <number> write operations.

Delayed secondaries can return write acknowledgment no earlier than the configured slaveDelay.

See Acknowledgment Behavior for when mongod instances acknowledge the write.

"majority"

Requests acknowledgment that write operations have propagated to the calculated majority of the data-bearing voting members (i.e. primary and secondaries with members[n].votes greater than 0).

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 members[n].votes greater than 0 can acknowledge "majority" write operations.

Delayed secondaries can return write acknowledgment no earlier than the configured slaveDelay.

After the write operation returns with a w: "majority" acknowledgment to the client, the client can read the result of that write with a "majority" readConcern.

See Acknowledgment Behavior for when mongod instances acknowledge the write.

<custom write concern name>

Requests acknowledgment that the write operations have propagated to tagged members that satisfy the custom write concern defined in settings.getLastErrorModes.

For an example, see Custom Multi-Datacenter Write Concerns.

See Acknowledgment Behavior for when mongod instances acknowledge the write.

 二、提高副本集读取效率

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.

MongoDB副本集提高读写速率第3张

相关文章

https://www.jianshu.com/p/c8236068204c

https://yq.aliyun.com/articles/60553

https://blog.csdn.net/qq_33642970/article/details/104155807

免责声明:文章转载自《MongoDB副本集提高读写速率》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇redis初步(1)JS来推断文本框内容改变事件下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

laravel 基础 --内置函数

简介 Laravel 自带了一系列 PHP 辅助函数,很多被框架自身使用,如果你觉得方便的话也可以在代码中使用它们。 https://laravelacademy.org/post/8967.html 模板里: 当前时间 当前时间:{{data('Y-m-d H:i:s')}} 控制器里: 模板里: 效果: 显示部分内容,多余的用...代替 如果内...

System.AccessViolationException,尝试读取或写入受保护的内存。这通常指示其他内存已损坏。

从事件查看器中发现,IIS不定期崩溃并重启的现象。抓取crash dump文件后,发现能够看到异常,但没有堆栈信息(主要是只会看托管代码的堆栈,非托管的不清楚。),问题表现及dump日志的截图如下: 从dump文件的异常信息分析看,System.AccessViolationException,尝试读取或写入受保护的内存。这通常指示其他内存已损坏。...

23.Android之颜色码制表

在Android应用开发中经常要用各种控件,并为控件设置其背景颜色,今天总结下颜色制表。 Android中146种颜色对应的XML值: 1 <?xml version="1.0" encoding="utf-8"?> 2 <resources> 3 <color name="white">#FFFFF...

PHP 多图片上传实例demo

upload.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/x...

highcharts配置的效果如下

配置如下: function init(categoryArray,seriesData,month_first_day,month_last_day,currDay){ var chart = Highcharts.chart('container', { chart: { type: 'columnrange...

R语言数据挖掘方法及应用

R语言数据挖掘方法及应用 第1篇 起步篇:R语言数据挖掘入门并不难 1 数据挖掘与R语言概述 1.1 为什么要学习数据挖掘和R语言 1.2 什么是数据挖掘 1.3 数据挖掘能给出什么 1.3.1 数据挖掘结果有哪些呈现方式 1.3.2 数据挖掘结果有哪些基本特征 1.4 数据挖掘能解决什么问题 1.4.1 数据预测 1.4.2 发现数据的内在结构 1.4....