3

flush() 有多快?我正在使用 persist() 将数千个项目添加到集合中,然后清空集合然后刷新它。

$dm = $this->get('doctrine.odm.mongodb.document_manager');

while(stuff))
{
     $item = new Item();
     $item->setItem("item stuff");           
     $dm->persist($item);
}

$qb = $dm->createQueryBuilder('Bundle:Item')->remove();
$query = $qb->getQuery();
$query->execute();

$dm->flush(); 

我想知道收藏品会空置多长时间。在移除和冲洗之间。

4

1 回答 1

3

我创建了一个基准来分析不同批次大小的简单两字段文档的刷新:https ://gist.github.com/2725976

$ php src/benchmark.php 10 100 1000 10000 20000 50000 100000
Flushing     10 items took  0.014058 seconds and   2097152 bytes
Flushing    100 items took  0.024325 seconds and    524288 bytes
Flushing   1000 items took  0.196992 seconds and   5505024 bytes
Flushing  10000 items took  2.563700 seconds and  57933824 bytes
Flushing  20000 items took  6.291873 seconds and  89915392 bytes
Flushing  50000 items took 19.118011 seconds and 240386048 bytes
Flushing 100000 items took 58.582809 seconds and 469499904 bytes

如您所料,实际上将数据插入 Mongo 只占这些测量的一小部分。Doctrine 将花费相当多的时间来完成诸如事件调度和变更集计算之类的步骤,后者将受到域模型复杂性的显着影响。

flush()您可以通过查看UnitOfWork::commit()来跟踪所有特定于 Doctrine 的操作。

于 2012-05-18T16:02:58.240 回答