PHP Mongo cursor move speed is very slow

This code takes ~ 0.1 s

// find
$benchmark = Profiler::start ('Testing', 'find()');
$cursor = MongoBG::getInstance ( )->setDatabase ('test')->setCollection ('testcoll')->find();
Profiler::stop ($benchmark);

$benchmark = Profiler::start ('Testing', 'cursor walk');
while ($cursor->hasNext()) {
    print_r($cursor->getNext());
}
Profiler::stop ($benchmark);

therefore, "find ()" took only 0.000017 seconds but a "cursor move" of 0.102812 seconds

The collection has about 100 lines, the speed remains unchanged with 1000 or only 10 elements in it.

Server information: FreeBSD 8.1, PHP 5.3.5 c (mongo / 1.1.4), version MongoDB 1.6.6-pre

+3
source share
1 answer

With such a fast time, it seems that he finddid nothing but prepare the object (without connecting to the database), and only when using the cursor the actual query was executed and the results were read. The cursor does the job, so it’s slower.

, mongodb node.js. , , , , , / .

+4

Source: https://habr.com/ru/post/1791514/


All Articles