MongoDB Best Practices

Source: Internet
Author: User
Tags mongodb sharding
Selecting a suitable NoSQL database is not discussed in this article, but please do some research before using NoSQL. No database is suitable for all situations. This article is false

Selecting a suitable NoSQL database is not discussed in this article, but please do some research before using NoSQL. No database is suitable for all situations. This article is false

There are already many articles about NoSQL selection. Factors that affect your database include read/write throughput, persistence, consistency, and latency. The document "Visual Guide to NoSQL System" by Nathan urst summarizes this point.

Selecting a suitable NoSQL database is not discussed in this article, but please do some research before using NoSQL. No database is suitable for all situations. This article assumes that you have selected MongoDB.


General NoSQL Best Practices

1. Complete Testing

Simulate your production environment, including traffic for testing. If your testing environment cannot meet the stress of the production environment, you will not be able to find performance bottlenecks and architecture defects.

2. RDBMS may not be able to migrate to NoSQL

Anything that works well on RDBMS may not necessarily work on MongoDB. Therefore, please be prepared and carefully compare the functions of the database. For better performance, you should design your documents and query according to 10gen suggestions. Your application may need to be restructured to facilitate migration to non-relational databases.

3. Consider your data consistency and persistence requirements

This is important! MongoDB uses multi-instance backup to solve data persistence issues. We do not recommend that you use only one MongoDB instance in the production environment. You must understand why.

MongoDB Best Practices

1. Always enable backup

Backup ensures high availability of your applications. If one of your nodes is down, the second node can be quickly enabled without interrupting your application.

2. Use the latest version.

10gen is continuously releasing updates, especially 2.0.x, which includes high performance improvement and parallel improvement, index improvement and bug fixing. If you are still using 1.6.3, you should upgrade it as soon as possible.

3. Do not run MongoDB on a 32-bit System

MongoDB has "GB Data limit" on 32-bit systems ". Its storage engine uses memory ing to read files for better performance. This function depends on memory addressing, and the 32-bit system memory cannot exceed 4 GB.

4. log is enabled by default.

MongoDB supports write-ahead journaling ). This feature helps disaster recovery.

5. Pay attention to the location of your data file

You should ensure that your MongoDB data files are stored on physical drives, such as/data/mongodb. You can also use a virtual drive, but be very careful. Because it may affect your cluster architecture. We recommend that you use Amazon EBS to store your database files.

6. Ensure enough memory

To ensure the performance of the entire cluster, you must ensure that all MongoDB working instances (working set), including indexes, can be fully loaded into the memory. If you find that the probability of "page faults" is increasing, it is very likely that the volume of mongoDB data exceeds your memory. In this case, you have two options: add memory or create a Sharding cluster ). We recommend that you first consider adding memory.

7. Keep the pressure below 65%

If you find that your cluster is under 65% pressure, you should consider expanding your cluster. Generally, you should ensure that the database pressure is less than 65%.

8. Be careful with sharding Cluster

Clustering requires you to fully understand the data access method of your application. You should fully understand the MongoDB sharding method and confirm that you really need this function. Also, selecting a sharding key is important for performance.

Configuring servers is also important for the health of a cluster. In the sharded cluster environment, you must have three configuration servers. Never delete the data on the configuration server. Always back up the data. These configuration servers also require a 64-bit environment. Also, do not place the three configuration servers on the same machine!

9. Use Mongo MMS to visually monitor your database

If you have not used Mongo MMS, I strongly recommend this tool. 10gen is vigorously developing this product. It provides a very friendly visual interface to monitor your MongoDB cluster.

10. MongoDB Resources

Technology is constantly improving. You need to pay attention to this information in the market:
Documentation:
Google Group:
Bugs: https://jira.mongodb.org
Blog:

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.