副本集有三台机器(M1, M2, M3)
,然后服务器放在另外几台机器(S1, S2, ..Sn)
。用的 driver 是 pymongo。因为对实时性要求不高,所以 ReadPreference 打算设置成 NEAREST,也就是会把请求平均分布到各台 mongo 所在机器。然后现在的问题是,MongoReplicaSetClient 的第一个参数 hosts_or_uri
不知道该怎么设置。可能的选择有三种:
哪一种比较好呢?谢谢。
1
whatisnew 2015-04-28 22:50:18 +08:00
关于 mongodb 我一直没学会,如何删除前30行数据。
选择数据 asc 排序,删除前 asc 30行。试过 remove findandmodify 全都没成功,半小时后放弃。。。 |
2
EPr2hh6LADQWqRVH 2015-04-28 23:04:35 +08:00
读可以用slave,写可不行,但repl set的语境下对于任意时间点到底谁是Master这个问题是不确定的,所以任意一台需要访问mongodb的应用服务器都需要了解所有可能是Master的mongod实例地址。
具体URI格式参考官方文档 http://docs.mongodb.org/manual/reference/connection-string/ |
3
laike9m OP @avastms 嗯,我知道写不行,写的话会练到master的。如果只考虑度,一般来说初始化client的时候应该把所有地址都写上么?
|
4
laike9m OP mongodb 官方的人给了个回复:
You're only required to pass the hostname/port of one of the replica set members. MongoReplicaSetClient will discover the rest automatically. The being said, it is best practice to include more than one member in the seed list (hosts_or_uri). If you only include one member in the seed list and that member just happens to be unavailable when you (re)start your application, PyMongo won't be able to connect. If you include two or more members in the seed list, as long as one of the members in the seed list is available PyMongo will be able to connect. |
5
laike9m OP 所以最好是把所有 Mongodb 所在机器都写上。性能上应该没区别。
|