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

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.

 

主站蜘蛛池模板: 林口县| 定日县| 辰溪县| 保山市| 乌恰县| 盈江县| 临沭县| 淮南市| 清水县| 饶平县| 上饶县| 化德县| 雅江县| 鸡西市| 汕头市| 义马市| 霍州市| 堆龙德庆县| 建瓯市| 准格尔旗| 津南区| 宜州市| 科尔| 浠水县| 泸溪县| 西安市| 亳州市| 池州市| 岑溪市| 西丰县| 黎城县| 沂水县| 惠水县| 兰州市| 鹰潭市| 许昌市| 黄大仙区| 隆子县| 富顺县| 墨脱县| 余江县|