Latency problems between cluster nodes

Source: Internet
Author: User
Latency problems between cluster nodes

MongoDB a weakness, which is final consistency, is also a problem for all nosql.
In Cap theory, the database is in (C) onsistency, (A) vailability and (P) artition-tolerance
Three can only meet two. For example, MongoDB has better high availability, distributed. The inevitable sacrifice. [Consistency]

Some time ago the development group's reflection said a record after inserting, again inquires, did not inquire, this question also many.

But the back test is again to reproduce the problem. But the delay must have been there, but it has not been known how serious the specific. Here for a while.

There must be a solution, but certainly not a complete solution.

------------------------------------------------------------------------------------------------------
In the application, you can avoid the data [consistency] problem from the following several aspects.


First, to monitor whether the network has bottlenecks and solve them.
This point our network, if it is all placed in the cloud server intranet, almost non-existent, but can not be completely excluded.


Second, confirm the hardware configuration, master and subordinate is consistent (Cpu,mem,io)

There are now a lot of clusters that are basically consistent. For example, [Business Library],[Statistical Database],[Log Library],
But there are exceptions: [Standard version of the formal library] cluster: [NGINX101,DB112,DB115],NGINX101 server performance is better,
But ran away from the other applications.


There are historical reasons for these problems. Individual is always recommended, database server data node, do not run other applications. So as not to appear
Mutual interference problem (io,net,cpu contention).


Third, oplog size configuration, I do not know will affect the delay, the configuration is now 10G, the data saved about 20 days of log volume.
Personally think it should be reduced to 3-5g

Iv. use of readpreference reading strategies

When you do encounter some problems with a delay in reading, you can use the read strategy to read the consistency of the strong, and put it in the main library for reading.
#python Code
Mon_conn = Pymongo. Mongoclient ([' mongodb:// 192.168.20.11:28000,192.168.20.19:28000,192.168.20.13:28000,192.168.20.15:28000,192.168.20.17:28000 '],
Read_preference=pymongo. Readpreference.primary)



(as far as our current version is concerned, only the above 3 methods can be used as a solution to the problem, so it is recommended that the upgrade be placed first)
(The following method, only in the 3.2 version available, of course, the use of both advantages and disadvantages, generally in the Log class data preservation will not use Writeconcern)

Using writeconcern mechanism to write data synchronously to multiple machines

1.3 nodes in the cluster, ensure that 2 nodes are inserted successfully, the timeout is set to 5 seconds

Db.products.insert (
{Item: "Envelopes", qty:100, type: "Clasp"},
{writeconcern: {w:2, wtimeout:5000}}
)

2. Setting most inserts successfully in the cluster configuration is successful.

CFG = rs.conf ()
Cfg.settings = {}
Cfg.settings.getLastErrorDefaults = {w: "Majority", wtimeout:5000}
Rs.reconfig (CFG)

3. Use tag, to each cluster node to set the label, insert, update, to ensure that a tag success only for success (Insert,update return 1)
3.1 First configure the node tag

conf = rs.conf ()
Conf.members[0].tags = {"DC": "East", "Use": "Production"}
Conf.members[1].tags = {"DC": "East", "Use": "Reporting"}
Conf.members[2].tags = {"DC": "West", "use": "Production"}
Rs.reconfig (CONF)

3.2 Set Error
Conf.settings = {getlasterrormodes: {multipledc: {"DC": 1, "Use": 1}}}


3.3 When inserting data, specify a node to save to a tag (possibly multiple) to be successful (Insert,update return 1)
Db.users.insert ({ID: "xyz", Status: "A"}, {writeconcern: {w: "Multipledc"}})



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.