坚持和冲洗 - 学说和MongoDB(Persist and flush - Doctrine an

2019-07-29 11:08发布

有多快的flush()? 我添加数千项的集合与坚持(),然后清空集合,然后刷新它。

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

我想知道多少时间将收集留空。 将捞出冲洗之间。

Answer 1:

我创建了一个标杆来分析一个简单的两场文件的刷新在各种批量: 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

正如你所预料的,实际插入的数据转换成蒙戈仅占这些测量的一小部分。 原则是要花费相当多的时间,通过类似的事件调度和变更计算,后者将通过您的域模型的复杂性显著影响的步骤走。

您可以跟踪所有在具体的学说,操作flush()通过在考虑看看的UnitOfWork ::提交() 。



文章来源: Persist and flush - Doctrine and MongoDB