[英]How can I tell which secondary the MongoDB PHP driver is reading from?
I am using the legacy MongoDB driver (1.6.x) to connect to a MongoDB (2.4.x) replicaset. 我使用传统的MongoDB驱动程序(1.6.x)连接到MongoDB(2.4.x)复制集。 I've got "?readPreference=secondary" in my connection string and two MongoDB secondaries on a replicaSet.
我的连接字符串中有“?readPreference = secondary”,副本集上有两个MongoDB辅助节点。 My connection string includes all the servers:
我的连接字符串包括所有服务器:
mongodb://dev-mongo01:27017,dev-mongo02:27017,dev-mongo03:27017/?replicaSet=dev-mongo-replica&readPreference=secondary
I'd like to find out which secondary the read comes from both to verify the readPreference is working as expected and to calculate the secondary's replication delay. 我想找出读取来自哪个次要来验证readPreference是否按预期工作并计算辅助复制延迟。 I've tried looking at MongoClient->getConnections(), MongoClient->getHosts(), "serversatus" and "replSetGetStatus" from the admin database but can't find anything that tells me which secondary is providing the data.
我试过从管理数据库查看MongoClient-> getConnections(),MongoClient-> getHosts(),“serversatus”和“replSetGetStatus”,但找不到任何告诉我哪个辅助提供数据的东西。
If it's just to verify whether your code is reading the right server, mongodb.log is the right place to look for. 如果只是为了验证您的代码是否正在读取正确的服务器,那么mongodb.log是正确的查找位置。 You'll see who's connecting to the node and its IP address.
您将看到谁连接到节点及其IP地址。
Also, you can turn on profiling by set: 此外,您可以通过设置打开分析:
db.setProfilingLevel(2);
to record all operations from clients. 记录客户的所有操作。 Be careful because this way it reduce performance a lot.
要小心,因为这样会大大降低性能。 turn it off by:
把它关掉:
db.setProfilingLevel(0);
If you are looking for a way to control which secondary should serve specific requests, replica set tag is what you are looking for. 如果您正在寻找一种方法来控制哪个辅助服务器应该为特定请求提供服务,那么副本集标记就是您要查找的内容。
You can call $cursor->info()
after you've iterated/read from the cursor to get a data structure which contains a host
, port
and connection_type_desc
keys. 在迭代/读取游标后,可以调用
$cursor->info()
来获取包含host
, port
和connection_type_desc
键的数据结构。 The host
and port
keys specify which MongoDB server satisfied that particular query. host
和port
密钥指定哪个MongoDB服务器满足该特定查询。
$cursor = $this->mongoclient->selectDB("test")->selectCollection("test")->find();
$cursor->rewind();
print_r($cursor->info()); //MongoDB Cursor Info
See http://php.net/manual/en/mongocursor.info.php 见http://php.net/manual/en/mongocursor.info.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.