我设置了蒙戈,一切都很好。当我使用MongoVUE或shell时,一切都像闪电一样快。
不过,在为Windows安装PHP驱动程序之后,每个查询都要花费15秒以上。甚至这个来自PHP.net的简单教程也需要15秒的时间。
教程示例:
$time_start = microtime(true);
// connect
$m = new Mongo();
// select a database
$db = $m->comedy;
// select a collection (analogous to a relational database's table)
$collection = $db->cartoons;
// add a record
$obj = array( "title" => "Calvin and Hobbes", "author" => "Bill Watterson" );
$collection->insert($obj);
// add another record, with a different "shape"
$obj = array( "title" => "XKCD", "online" => true );
$collection->insert($obj);
// find everything in the collection
$cursor = $collection->find();
// iterate through the results
foreach ($cursor as $obj) {
echo $obj["title"] . "\n";
}
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "\nOperation took $time seconds\n";
输出:
Calvin and Hobbes XKCD Operation took 15.000731945038 seconds
我使用的是Windows7、WAMP、MongoDB 2.0.7和Windows驱动程序(v1.1.12) 来自吉突布。
在答复评论中的问题时:
问:你有没有在你的系统上测试过其他PHP代码以及它的持续时间?
A:,这实际上是一个更大的web应用程序的一小块,其他的一切都很好。我很乐意发布你们认为有用的基准。
问:你在蒙戈描述过这个问题吗?
A:是的。如果我在shell中运行它,它会立即得到一个响应。
问:这是什么WAMP版本?
A: WampServer 2.2
问:这是什么PHP版本?
A: 5.3.13
问: mongodb里面已经有数据了吗?
A: --在我发布的基准测试之前,我删除了所有的数据库,所以它只有下面的代码插入的数据。
问:计算机的规格(主要是内存)是什么?
A: AMD X4 840T2.9GHz处理器,4GB DDR3 RAM,64位操作系统
发布于 2012-08-28 06:27:19
我同意15秒太荒谬了。即使打开SafeMode
,教程代码的运行时间也应该接近0.5秒(如果是这样的话)。您已经关闭了SafeMode
,从插入代码可以看到:
// add a record
$obj = array( "title" => "Calvin and Hobbes", "author" => "Bill Watterson" );
$collection->insert($obj);
// add another record, with a different "shape"
$obj = array( "title" => "XKCD", "online" => true );
$collection->insert($obj);
您正在执行异步插入,这意味着PHP代码不会等待DB的返回,因此理论上,对DB的调用不应该是代码中的问题。
不过,find()
可能会造成问题,所以我将对其进行分析。
司机仍有可能导致某种程度的减速,但这是极不可能的。为进一步帮助我们:
发布于 2012-08-28 06:05:45
插入新数据库需要一段时间,因为MongoDB需要先预先分配数据库文件。随后的插入将很快。除此之外:只执行一个插入的基准测试是没有意义的。
https://stackoverflow.com/questions/12160867
复制相似问题