简体   繁体   English

学说和大量数据

[英]doctrine and large amount of data

i have a query that returns ~50k rows, seems like doctrine put this whole result into memory what exceeds memory limit(128M) the only solution i found that saves some memory is 我有一个返回~50k行的查询,看起来像doctrine将整个结果放入内存超出内存限制(128M)我找到的唯一解决方案是节省一些内存

$result->execute(array(), Doctrine_Core::HYDRATE_NONE);

but it still exceeds the limit, is there any way to read one row at a time with doctrine ? 但是它仍然超出了限制,有没有办法一次用学说阅读一行?

Doctrine Documentation - 13. Batch Processing Doctrine Documentation - 13.批处理

Update: For 1.2 check out this page: http://docs.doctrine-project.org/projects/doctrine1/en/latest/en/manual/data-hydrators.html 更新:对于1.2,请查看此页面: http//docs.doctrine-project.org/projects/doctrine1/en/latest/en/manual/data-hydrators.html

Under the "On Demand" heading you will find the answer. 在“按需”标题下,您将找到答案。

Batch processing helps! 批处理有帮助!

It took me a long time to figure out what helps. 我花了很长时间才弄清楚有什么帮助。 I have the impression that as long as you stay in the same php-process you can't free your memory. 我的印象是,只要你保持相同的php进程你就无法释放你的记忆。 So this didn't help for me: 所以对我没有帮助

  • $object->free(true) $对象 - >免费(真)
  • unset($object) 未设置($对象)
  • sfConfig::set('sf_debug', false) sfConfig :: set('sf_debug',false)
  • gc_collect_cycles() / gc_enable() gc_collect_cycles()/ gc_enable()
  • Doctrine_Core::HYDRATE_ON_DEMAND Doctrine_Core :: HYDRATE_ON_DEMAND
  • sfCommandApplicationTask::runTask() sfCommandApplicationTask :: runTask()
  • sfDoctrinePager sfDoctrinePager

What really helped was a hint from Rich Sage who suggested to spawn subprocesses to execute Portions of the work. 真正有用的Rich Sage的暗示,他建议产生子进程来执行部分工作。 Limit and Offset for the query are given as parameters between the processes. 查询的限制和偏移量作为进程之间的参数给出。 To get row by row set $options['limit'] to 1, but 50 should be a good value too: 要逐行设置$options['limit']为1,但50也应该是一个很好的值:

daddyTask.class.php daddyTask.class.php

[..]
$total = ItemTable::getInstance()->createQuery('i')->count();

for ($offset = 0; $offset < $total; $offset += $options['limit'] )
{
    passthru(
        sprintf('%s %s/symfony doTask --limit=%s --offset=%s', sfToolkit::getPhpCli(), sfConfig::get('sf_root_dir'), $options["limit"], $offset),
        $returnVar
    );
 }

doTask.class.php doTask.class.php

$items = ItemTable::getInstance()->createQuery('i')->limit($options['limit'])->offset($options['offset'])->execute();

foreach( $items as $item )
{
    // ..do something with the item
    $this->log( 'INFO: '.memory_get_peak_usage(true).' memory in use.' );
}

(I'm using Doctrine 1.2 in the Symfony 1.4 framework on PHP 5.3.10) (我在PHP 5.3.10的Symfony 1.4框架中使用Doctrine 1.2)

Any comments or critique on this topic is greatly appreciated as it's a difficult one for me! 对此主题的任何评论或批评都非常感谢,因为这对我来说很难!

你有没有使用 - > limit()和 - > offset()的原因?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM