我测试了150个文件,每个文件都有2000个记录 这是内存使用情况:
Memory after collection: 1584
Memory after findOne: 530936
Memory after find: 81798960
因此,findOne使用大约0.5MB,而查找150个文档则使用78MB。
拥有如此高的内存使用率是否正常?或者我的文档对象太大了?我只是在2000条记录中存储了四个字符。
用于测试的代码:
<?php
$old = memory_get_usage();
$collection = $mongo->getMongoCollection($this->Mb);
$new = memory_get_usage();
echo "Memory after collection: " . ($new - $old) . "<br>";
$old = memory_get_usage();
$arr = $collection->findOne(array('capture' => '1367208145'));
$new = memory_get_usage();
echo "Memory after findOne: " . ($new - $old) . "<br>";
$old = memory_get_usage();
$cursor = $collection->find();
$arr = iterator_to_array($cursor);
$new = memory_get_usage();
echo "Memory after find: " . ($new - $old) . "<br>";
?>