官术网_书友最值得收藏!

Best practices for replication

Replica sets are MongoDB's mechanism to provide redundancy, high availability, and higher read throughput under the right conditions. Replication in MongoDB is easy to configure and light in operational terms:

  • Always use replica sets: Even if your dataset is at the moment small and you don't expect it to grow exponentially, you never know when that might happen. Also, having a replica set of at least three servers helps design for redundancy, separating work loads between real time and analytics (using the secondaries) and having data redundancy built from day one.
  • Use a replica set to your advantage: A replica set is not just for data replication. We can and should in most cases use the primary server for writes and preference reads from one of the secondaries to offload the primary server. This can be done by setting read preference for reads, together with the correct write concern to ensure writes propagate as needed.
  • Use an odd number of replicas in a MongoDB replica set: If a server does down or loses connectivity with the rest of them (network partitioning), the rest have to vote as to which one will be elected as the primary server. If we have an odd number of replica set members, we can guarantee that each subset of servers knows if they belong to the majority or the minority of the replica set members. If we can't have an odd number of replicas, we need to have one extra host set as an arbiter with the sole purpose of voting in the election process. Even a micro instance in EC2 could serve this purpose.

 

主站蜘蛛池模板: 兴山县| 农安县| 如东县| 句容市| 大悟县| 阳朔县| 佛坪县| 绥中县| 车险| 鄂托克旗| 原阳县| 湖口县| 霍邱县| 集贤县| 富裕县| 和龙市| 湾仔区| 玉门市| 九龙坡区| 宁津县| 余姚市| 府谷县| 友谊县| 安乡县| 淮安市| 泾川县| 磐安县| 汉沽区| 潮州市| 乐安县| 色达县| 舞阳县| 车致| 桂阳县| 平利县| 密云县| 泰和县| 甘泉县| 朝阳市| 福州市| 昭平县|