内存泄漏 Symfony2 Doctrine2/超出内存限制 [英] Memory leaks Symfony2 Doctrine2 / exceed memory limit

查看:20
本文介绍了内存泄漏 Symfony2 Doctrine2/超出内存限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在symfony2和doctor2的结合上遇到了很多麻烦.我必须处理庞大的数据集(大约 2-3 百万次写入和读取),并且必须做很多额外的努力来避免内存不足.

我想出了两个要点,即泄漏"内存(它们实际上并不是真的泄漏,而是分配了很多).

  1. Entitymanager 实体存储(我不知道它的真名)它似乎保留了所有已处理的实体,您必须定期使用

    清除此存储

    $entityManager->clear()

  2. Doctrine QueryCache - 它缓存所有使用过的查询,我发现的唯一配置是,您可以决定要使用哪种缓存.我没有找到全局禁用,也没有找到每个查询禁用它的有用标志.所以通常我会为每个带有函数的查询对象禁用它

    <前>$qb = $repository->createQueryBuilder($a);$query = $qb->getQuery();$query->useQueryCache(false);$query->execute();

所以..这就是我现在想到的全部..我的问题是:

是否有一种简单的方法可以拒绝 Entitymanagerstorage 中的某些对象?有没有办法在实体管理器中设置查询缓存的使用?我可以在 Symfony/doctrine 配置中的某处配置这个缓存行为吗?

如果有人给我一些不错的提示,那就太酷了..否则这可能会帮助一些菜鸟..

青色

解决方案

正如 Doctrine 配置参考 默认情况下,SQL 连接的logging 设置为 kernel.debug 的值,所以如果你已经用调试集实例化了 AppKernel到 true,SQL 命令会在每次迭代时存储在内存中.

您应该在配置 YML 中将 AppKernel 实例化为 false,将 logging 设置为 false,或者在此之前手动将 SQLLogger 设置为 null使用实体管理器

$em->getConnection()->getConfiguration()->setSQLLogger(null);

I have a lot of trouble with the combination of symfony2 and doctrine2. I have to deal with huge datasets (around 2-3 million write and read) and have to do a lot of additional effort to avoid running out of memory.

I figgured out 2 main points, that "leak"ing memory (they are actually not really leaking, but allocating a lot).

  1. The Entitymanager entity storage (I don't know the real name of this one) it seems like it keeps all processed entities and you have to clear this storage regularly with

    $entityManager->clear()

  2. The Doctrine QueryCache - it caches all used Queries and the only configuration I found was, that you are able to decide what kind of Cache you wanna use. I didn't find a global disable neither a useful flag for each query to disable it. So usually I disable it for every query object with the function

     $qb = $repository->createQueryBuilder($a);
     $query = $qb->getQuery();
     $query->useQueryCache(false);
     $query->execute();
     

So.. that's all I figured out right now.. My questions are:

Is there a easy way to deny some objects from the Entitymanagerstorage? Is there a way to set the querycache use in the entitymanager? Can I configure this caching behaviors somewhere in the Symfony/doctrine configuration?

Would be very cool if someone has some nice tips for me.. otherwise this may help some rookie..

cya

解决方案

As stated by the Doctrine Configuration Reference by default logging of the SQL connection is set to the value of kernel.debug, so if you have instantiated AppKernel with debug set to true the SQL commands get stored in memory for each iteration.

You should either instantiate AppKernel to false, set logging to false in you config YML, or either set the SQLLogger manually to null before using the EntityManager

$em->getConnection()->getConfiguration()->setSQLLogger(null);

这篇关于内存泄漏 Symfony2 Doctrine2/超出内存限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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