坚持和冲洗 - 教义和MongoDB [英] Persist and flush - Doctrine and MongoDB

查看:94
本文介绍了坚持和冲洗 - 教义和MongoDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我想知道收藏多少时间是空的。在删除和刷新之间。

解决方案

我创建了一个基准,用于分析各种批量大小的简单双字段文档的刷新: https://gist.github.com/2725976

  $ php src / benchmark.php 10 100 1000 10000 20000 50000 100000 
冲洗10个项目需要0.014058秒和2097152个字节
冲洗100个项目花费0.024325秒和524288字节
冲洗1000个项目花费0.196992秒和5505024字节
冲洗10000个项目花费2.563700秒和57933824个字节
冲洗20000个项目花费6.291873秒和89915392个字节
冲洗50000个项目19.118011秒和240386048字节
冲洗100000个物品占58.582809秒和469499904字节

期望,实际将数据插入Mongo仅占这些测量的一小部分NTS。原则将花费相当多的时间来走出诸如事件调度和变更计算的步骤,后者将受到您的域模型的复杂性的极大影响。



您可以通过查看 flush()中的所有Doctrine特定操作, odm / blob / master / lib / Doctrine / ODM / MongoDB / UnitOfWork.phprel =nofollow> UnitOfWork :: commit()


How fast is flush()? I'm adding several thousand item to a collection with persist(), then emptying the collection then flushing it.

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

I want to know how much time will the collection stay empty. Between the remove and the flush.

解决方案

I created a benchmark to profile flushes of a simple two-field document in various batch sizes: 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

As you might expect, actually inserting the data into Mongo only accounts for a small fraction of these measurements. Doctrine is going to spent quite a bit of time walking through steps like events dispatching and changeset computation, the latter of which will be significantly impacted by the complexity of your domain model.

You can trace all of the Doctrine-specific operations in flush() by taking a look at UnitOfWork::commit().

这篇关于坚持和冲洗 - 教义和MongoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆