持久化和刷新 - Doctrine 和 MongoDB [英] Persist and flush - Doctrine and MongoDB

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

问题描述

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

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.

推荐答案

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

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

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

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.

您可以通过查看 UnitOfWork::commit().

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

这篇关于持久化和刷新 - Doctrine 和 MongoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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