简体   繁体   English

如何判断MongoDB PHP驱动程序正在读取哪个辅助节点?

[英]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()来获取包含hostportconnection_type_desc键的数据结构。 The host and port keys specify which MongoDB server satisfied that particular query. hostport密钥指定哪个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.

相关问题 您如何知道使用PHP安装了哪些sql驱动程序? - How can you tell which sql driver(s) are installed using PHP? 我如何尝试使用PHP驱动程序从MongoDB中的2个或更多集合中获取信息 - How can I try to get information from 2 or more collections in MongoDB using PHP driver 如何从命令行判断哪些 Screen 会话仍在运行 PHP 进程? - How can I tell which Screen sessions are still running a PHP process from the command line? PHP-如何确定脚本将在哪个域中查找C​​ookie? - PHP - How can I tell in which domain a script will look for cookies? 我怎样才能告诉PHP提交哪种表格 - How can i tell PHP which form is submitted 如何判断在 PHP 表单提交中点击了哪个按钮? - How can I tell which button was clicked in a PHP form submit? 我如何配置xampp以安装最新版本的php version 7.1的php mongo驱动程序并从php脚本连接到mongodb - How can i configure xampp to install php mongo driver for latest version of php version 7.1 and connect to mongodb from php script 我应该在哪个目录中安装官方PHP mongodb驱动程序? - Which directory should I install the official PHP mongodb driver in? 我现在应该使用哪个PHP mongodb驱动程序? - Which PHP mongodb driver should I now be using? 我如何知道单击了哪个按钮? - How can I tell which button was clicked?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM