Home Database Mysql Tutorial mongodb 分布式读写操作(1)

mongodb 分布式读写操作(1)

Jun 07, 2016 pm 04:37 PM
mongodb distributed operate Read and write

mongodb shared cluster 和 replica set 架构应用非常广泛。在生产环境中,这两种架构随着业务量,数据量的增长以及高可用性的需求,日渐提上日程,系统架构从单台慢慢转向集群的架构,所有底层设施集群化。一. 分布式读操作介绍分片集群和副本集如何影响读

mongodb shared cluster 和 replica set 架构应用非常广泛。在生产环境中,这两种架构随着业务量,数据量的增长以及高可用性的需求,日渐提上日程,系统架构从单台慢慢转向集群的架构,所有底层设施集群化。 一. 分布式读操作 介绍分片集群和副本集如何影响读操作的性能。 1.1 分片集群读操作 分片集群允许数据分割到集群内的不同mongod实例上,这对应用程序来说几乎是透明的。 对于分片集群,应用程序发出操作与集群相关的mongos实例。   sharded-cluster 读操作直接定向到一个特定的分片上,集群读操作是最有效的。 查询到分片集合应该包括集合分片片键。?当一个查询包含分片片键,mongos从config ?server使用集群元数据将查询路由到分片。 查询条件包括分片关键。查询路由器mongos将查询直接到定位到相应的分片。 sharded-cluster-targeted-query 如果查询不包含分片片键,mongos将查询广播到集群中的所有分片。 这种分散聚集查询是非常低效的。对于大型集群,这种操作是要命的。 sharded-cluster-scatter-gather-query 1.2 复制集读操作 副本集使用读的优先模式来决定在哪里以及如何路由读操作到副本集的成员。 默认情况下,应用程序读操作在复制集的primary上。从primary读可以保证文档的最新版本,因为复制集是异步复制的。然后,通过分配部分或者全部读操作到复制集的secondary节点上,可以提高读取吞吐量或减少等待时间,对实时性应用程序需要并不高。 可以通过修改读操作的优先模式来更改读的特性。 读操作的模式有:
读模式 描述
primary 默认模式。所有读操作都从primary节点读取。
primaryPreferred 在大多数情况下,读操作从primary节点读取,但如果primary节点不可用,读操作从secondary节点读取。
secondary 所有读操作都从secondary节点读取。
secondaryPreferred 在大多数情况下,读操作从secondary节点读取,但如果secondary节点不可用,读操作从primary节点读取。
nearest 读操作从副本集网络延迟最小的节点读取,无论该节点的类型。
根据应用程序的需求,选择不同的读操作模式。 最大限度的一致性:在任何情况下,避免读取到旧数据,使用primary模式。在没有primary节点,发生在选举阶段,或大部分节点不可用,将阻塞所有的读取操作。 最大限度的高可用性:尽可能的保证读操作,使用?primaryPreferred 模式。当有一个primary节点会得到一致性读,如果没有,仍然可以查询secondary节点。 减少等待时间 :要始终从低延迟的节点读取,使用nearest。驱动和mongos从最少延迟读取。nearest不保证一致性。如果复制延迟,查询可能返回过期数据。nearest只反映网络的延迟,并不能反映I/O和CPU的负载。 replica-set-read-preference 从secondary节点读取,并不能反映primary当前的状态,异步复制下,secondary节点可能落后primary节点一定的时间。通常情况下,应用程序不要求这种严格的一致性,对于高可用性的要求是最多的。 二.?分布式写操作 介绍MongoDB中如何引导的分片集群和副本集的写操作,并且这些写操作的性能特点。具体内容请关注下节内容。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Astar staking principle, income dismantling, airdrop projects and strategies & operation nanny-level strategy Astar staking principle, income dismantling, airdrop projects and strategies & operation nanny-level strategy Jun 25, 2024 pm 07:09 PM

Table of Contents Astar Dapp Staking Principle Staking Revenue Dismantling of Potential Airdrop Projects: AlgemNeurolancheHealthreeAstar Degens DAOVeryLongSwap Staking Strategy & Operation "AstarDapp Staking" has been upgraded to the V3 version at the beginning of this year, and many adjustments have been made to the staking revenue rules. At present, the first staking cycle has ended, and the "voting" sub-cycle of the second staking cycle has just begun. To obtain the "extra reward" benefits, you need to grasp this critical stage (expected to last until June 26, with less than 5 days remaining). I will break down the Astar staking income in detail,

What is the use of net4.0 What is the use of net4.0 May 10, 2024 am 01:09 AM

.NET 4.0 is used to create a variety of applications and it provides application developers with rich features including: object-oriented programming, flexibility, powerful architecture, cloud computing integration, performance optimization, extensive libraries, security, Scalability, data access, and mobile development support.

How to configure MongoDB automatic expansion on Debian How to configure MongoDB automatic expansion on Debian Apr 02, 2025 am 07:36 AM

This article introduces how to configure MongoDB on Debian system to achieve automatic expansion. The main steps include setting up the MongoDB replica set and disk space monitoring. 1. MongoDB installation First, make sure that MongoDB is installed on the Debian system. Install using the following command: sudoaptupdatesudoaptinstall-ymongodb-org 2. Configuring MongoDB replica set MongoDB replica set ensures high availability and data redundancy, which is the basis for achieving automatic capacity expansion. Start MongoDB service: sudosystemctlstartmongodsudosys

How to ensure high availability of MongoDB on Debian How to ensure high availability of MongoDB on Debian Apr 02, 2025 am 07:21 AM

This article describes how to build a highly available MongoDB database on a Debian system. We will explore multiple ways to ensure data security and services continue to operate. Key strategy: ReplicaSet: ReplicaSet: Use replicasets to achieve data redundancy and automatic failover. When a master node fails, the replica set will automatically elect a new master node to ensure the continuous availability of the service. Data backup and recovery: Regularly use the mongodump command to backup the database and formulate effective recovery strategies to deal with the risk of data loss. Monitoring and Alarms: Deploy monitoring tools (such as Prometheus, Grafana) to monitor the running status of MongoDB in real time, and

What does DEKUBE distributed mean? The next rising star in the trillion-dollar DePin track What does DEKUBE distributed mean? The next rising star in the trillion-dollar DePin track Jun 14, 2024 pm 10:04 PM

What does DEKUBE distributed mean? The next rising star in the trillion-dollar DePin track! As a pioneer in global distributed GPU networks, DEKUBE is also the first 100% proof-of-work (PoW) Web3AI project. By leveraging idle consumer-grade GPUs and converting them into enterprise-grade computing power, DEKUBE provides an efficient and cost-effective solution for training large language models, pushing the boundaries of AI innovation so that everyone can benefit from it . Today, the editor of this site will share with you a detailed explanation of what DEKUBE distributed means. I hope you like it! Mission: Use technology and vision to popularize AI innovation and benefit the public with openness, democracy, and fairness——DEKUBE

Navicat's method to view MongoDB database password Navicat's method to view MongoDB database password Apr 08, 2025 pm 09:39 PM

It is impossible to view MongoDB password directly through Navicat because it is stored as hash values. How to retrieve lost passwords: 1. Reset passwords; 2. Check configuration files (may contain hash values); 3. Check codes (may hardcode passwords).

Use Composer to solve the dilemma of recommendation systems: andres-montanez/recommendations-bundle Use Composer to solve the dilemma of recommendation systems: andres-montanez/recommendations-bundle Apr 18, 2025 am 11:48 AM

When developing an e-commerce website, I encountered a difficult problem: how to provide users with personalized product recommendations. Initially, I tried some simple recommendation algorithms, but the results were not ideal, and user satisfaction was also affected. In order to improve the accuracy and efficiency of the recommendation system, I decided to adopt a more professional solution. Finally, I installed andres-montanez/recommendations-bundle through Composer, which not only solved my problem, but also greatly improved the performance of the recommendation system. You can learn composer through the following address:

What is the CentOS MongoDB backup strategy? What is the CentOS MongoDB backup strategy? Apr 14, 2025 pm 04:51 PM

Detailed explanation of MongoDB efficient backup strategy under CentOS system This article will introduce in detail the various strategies for implementing MongoDB backup on CentOS system to ensure data security and business continuity. We will cover manual backups, timed backups, automated script backups, and backup methods in Docker container environments, and provide best practices for backup file management. Manual backup: Use the mongodump command to perform manual full backup, for example: mongodump-hlocalhost:27017-u username-p password-d database name-o/backup directory This command will export the data and metadata of the specified database to the specified backup directory.

See all articles