我想用MongoDB扩展读取。要做到这一点,我可以设置主从复制或副本集,但如果我像这样创建与Mongo的连接:
from pymongo import ReplicaSetConnection, ReadPreference
from pymongo.errors import ConnectionFailure
try:
connection = ReplicaSetConnection("somehost:10000", replicaSet='myapp_repl',
read_preference=ReadPreference.SECONDARY)
except ConnectionFailure ...
或:
from pymongo.master_slave_connection import MasterSlaveConnection
from pymongo.errors import ConnectionFailure
try:
master = Connection(host="somehost", port=10000)
slave1 = Connection(host="somehost", port=10001)
slave2 = Connection(host="somehost", port=10002)
connection = MasterSlaveConnection(master, slaves=[slave1, slave2])
except ConnectionFailure ...
pymongo 驱动程序将在副本集secondaries / slaves之间分发查询。在这种情况下,primary / master不会处理查询,所以如果我有2个节点,我就不会增强读取功能,因为只有1个节点会处理查询。如何让master和slave(primary和secondaries)处理查询?
答案 0 :(得分:1)
这有点像黑客但是:
connection = MasterSlaveConnection(master, slaves=[slave1, slave2, master)
不推荐使用MasterSlaveConnection。
我不确定是否有任何其他解决方法。
您可能需要查看分片或添加仲裁者,以便在新的初选中投票:http://www.mongodb.org/display/DOCS/Adding+an+Arbiter