Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
So when I connect to a MongoDB with multiple hosts, there is a delay in every one minute when executing a command. The delay time is exactly 10 seconds. I know this sounds so weird.
First I thought that the problem is related to MongoDB server configuration. But it only happens when I use PHP mongodb driver because it works fine when I tested with Java mongodb driver. - MongoDB Server: 3.6 - PHP mongodb driver: 1.5.3 - Java mongodb driver: 3.10.1
I also tested older version of PHP mongodb driver with the same problem.
PHP
// start tracking reading time
$start= microtime(true);
$m =new \MongoDB\Client('mongodb://rs1.host.com,rs2.host.com');
$db = $m->selectDatabase('test');// slow when querying
$db->selectCollection('user')->findOne();// end tracking reading time
$end = microtime(true);
$duration = $end - $start;
No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that
you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice
sessions to improve your knowledge and scores.
manpreet
Best Answer
2 years ago
So when I connect to a MongoDB with multiple hosts, there is a delay in every one minute when executing a command. The delay time is exactly 10 seconds. I know this sounds so weird.
First I thought that the problem is related to MongoDB server configuration. But it only happens when I use PHP mongodb driver because it works fine when I tested with Java mongodb driver. - MongoDB Server: 3.6 - PHP mongodb driver: 1.5.3 - Java mongodb driver: 3.10.1
I also tested older version of PHP mongodb driver with the same problem.
PHP
Full source code: https://drive.google.com/open?id=1r-EKiCntZbUq59sFzaBOiCrfy0tzjadt
Java
Full source code: https://drive.google.com/open?id=1TYTFrRxUiQUZdIUJdetllHpnOYHQiepd
I repeated the script above every 2 seconds, so here is result I tested:
PHP
Java