坚持和冲洗 - Doctrine和MongoDB

时间:2012-05-17 16:35:17

标签: mongodb doctrine

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(); 

我想知道收集时间会保持空白。在删除和刷新之间。

1 个答案:

答案 0 :(得分: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将花费相当多的时间来完成事件调度和变更集计算等步骤,后者将受到域模型复杂性的显着影响。

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