Home Database Mysql Tutorial MongoDB应用实践思考

MongoDB应用实践思考

Jun 07, 2016 pm 04:02 PM
mongodb practice application think Research

最近研究MongoDB,利用其可以简单快速地搭建一套灵活的no schema存储系统。本文通过论证和分析需求,利用MongoDB快速搭建了一套具有良好性能及可用性满足上亿规模的存储系统。在关于NoSQL数据库的选型上,需要结合自身 数据模型 、 访问方式 以及 成本 等方面

最近研究MongoDB,利用其可以简单快速地搭建一套灵活的no schema存储系统。 本文通过论证和分析需求,利用MongoDB快速搭建了一套具有良好性能及可用性满足上亿规模的存储系统。 在关于NoSQL数据库的选型上,需要结合自身数据模型访问方式以及成本等方面的考虑作一个权衡(trade off)。
那么经过研究MongoDB(2.6.4版本)有如下特点: 可用性:
1.支持高可用灵活的服务集群配置,有主从、副本集、自动分片模式。
2.基于文档的查询,高性能,简单查询上万的QPS。
3.支持全文检索。

一致性:
1.支持文档内更新模式,效率高。
2.当前最新的2.6版本采用读写锁、写锁优先,锁的粒度为collection级别。

易用性:
1.近似传统关系型数据库的SQL使用。
2.丰富的管理配置工具。
3.支持基于用户角色的权限管理体系。

存储机制:
采用mmap file + 内存索引的方式。内存与缓存管理由操作系统负责,当使用数据集大小超出时,性能下降。 Linux下内存控制可以通过配置用户ulimit -u 实现。
现实需求: 1. 需要存储字段灵活的半结构化数据。 2. 1~2亿条记录的存储规模,平均每条记录20k上限。 3. 读需求远大于写(以8:2计算),写以批量写入的方式,读需支持灵活复杂的查询方式。 4. 写性能:5000qps 读性能:2W qps
由于MongoDB灵活的存储和访问方式,以及良好的查询性能与伸缩性及维护成本,故想到利用MongoDB来存储这约2亿的数据量。 根据需求分析如下: 1. 以2亿规模计算,总存储量约4TB。现在市面上服务器硬盘最大有2TB规格的,部署时可以考虑以LVM方式,先安装1~2TB磁盘,待容量增长时根据需求方便地做扩容。 2. 在已存在1亿数据量的情况下插入1000W条记录,每次写入4条索引,qps能达到8000满足写性能的5000 qps需求。 3. 单线程简单读情况下qps能达到8W qps,换做多线程并发读取总性能也接近8W qps可满足2W qps的查询性能,后续若对读性能有增长需求可考虑从节点开启读权限分摊读压力。在测试中,读延迟 根据需求论证的结果,利用MongoDB来存储这2亿条记录的方案是可行的。在实际部署当中,MongoDB支持多种方式有主从、副本集、分片。其中副本集相对于主从模式有自动故障迁移的优势,但是其也带来了复杂性和机器成本增加的劣势。 故综合考虑后,选用主从模式进行部署,选用服务器配置为16物理核 + 256G内存 + 2TB硬盘的机器两台搭建主备节点。 其中,从节点开启读权限,一方面应用层在主不可读时可向从节点发起读请求,另一方面前端可根据负载把部分读请求分摊到从节点上。 由于数据的写入求属于离线操作,故只需监控好主从节点的状态,能够及时恢复好服务状态即可。
通过以上实践,即完成了利用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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

Which version is generally used for mongodb? Which version is generally used for mongodb? Apr 07, 2024 pm 05:48 PM

It is recommended to use the latest version of MongoDB (currently 5.0) as it provides the latest features and improvements. When selecting a version, you need to consider functional requirements, compatibility, stability, and community support. For example, the latest version has features such as transactions and aggregation pipeline optimization. Make sure the version is compatible with the application. For production environments, choose the long-term support version. The latest version has more active community support.

How to Undo Delete from Home Screen in iPhone How to Undo Delete from Home Screen in iPhone Apr 17, 2024 pm 07:37 PM

Deleted something important from your home screen and trying to get it back? You can put app icons back on the screen in a variety of ways. We have discussed all the methods you can follow and put the app icon back on the home screen. How to Undo Remove from Home Screen in iPhone As we mentioned before, there are several ways to restore this change on iPhone. Method 1 – Replace App Icon in App Library You can place an app icon on your home screen directly from the App Library. Step 1 – Swipe sideways to find all apps in the app library. Step 2 – Find the app icon you deleted earlier. Step 3 – Simply drag the app icon from the main library to the correct location on the home screen. This is the application diagram

The difference between nodejs and vuejs The difference between nodejs and vuejs Apr 21, 2024 am 04:17 AM

Node.js is a server-side JavaScript runtime, while Vue.js is a client-side JavaScript framework for creating interactive user interfaces. Node.js is used for server-side development, such as back-end service API development and data processing, while Vue.js is used for client-side development, such as single-page applications and responsive user interfaces.

Where is the database created by mongodb? Where is the database created by mongodb? Apr 07, 2024 pm 05:39 PM

The data of the MongoDB database is stored in the specified data directory, which can be located in the local file system, network file system or cloud storage. The specific location is as follows: Local file system: The default path is Linux/macOS:/data/db, Windows: C:\data\db. Network file system: The path depends on the file system. Cloud Storage: The path is determined by the cloud storage provider.

What are the advantages of mongodb database What are the advantages of mongodb database Apr 07, 2024 pm 05:21 PM

The MongoDB database is known for its flexibility, scalability, and high performance. Its advantages include: a document data model that allows data to be stored in a flexible and unstructured way. Horizontal scalability to multiple servers via sharding. Query flexibility, supporting complex queries and aggregation operations. Data replication and fault tolerance ensure data redundancy and high availability. JSON support for easy integration with front-end applications. High performance for fast response even when processing large amounts of data. Open source, customizable and free to use.

What does mongodb mean? What does mongodb mean? Apr 07, 2024 pm 05:57 PM

MongoDB is a document-oriented, distributed database system used to store and manage large amounts of structured and unstructured data. Its core concepts include document storage and distribution, and its main features include dynamic schema, indexing, aggregation, map-reduce and replication. It is widely used in content management systems, e-commerce platforms, social media websites, IoT applications, and mobile application development.

PHP Coding Practices: Refusing Alternatives to Goto Statements PHP Coding Practices: Refusing Alternatives to Goto Statements Mar 28, 2024 pm 09:24 PM

PHP Coding Practices: Refusal to Use Alternatives to Goto Statements In recent years, with the continuous updating and iteration of programming languages, programmers have begun to pay more attention to coding specifications and best practices. In PHP programming, the goto statement has existed as a control flow statement for a long time, but in practical applications it often leads to a decrease in the readability and maintainability of the code. This article will share some alternatives to help developers refuse to use goto statements and improve code quality. 1. Why refuse to use goto statement? First, let's think about why

How to open mongodb How to open mongodb Apr 07, 2024 pm 06:15 PM

On Linux/macOS: Create the data directory and start the "mongod" service. On Windows: Create the data directory and start the MongoDB service from Service Manager. In Docker: Run the "docker run" command. On other platforms: Please consult the MongoDB documentation. Verification method: Run the "mongo" command to connect and view the server version.

See all articles