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

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

问题描述

实际上我有很多麻烦与symfony2和doctrine2的组合。我必须处理巨大的数据集(大约2-3百万的写入和读取),并且必须做很多额外的努力,以避免内存不足。



我想象出来2个要点,那个泄漏的记忆(实际上并不是真的泄漏,而是分配很多)


  1. 实体管理实体存储(我不知道这个的真实姓名)似乎它保留所有处理的内容,您必须使用

     $清除此存储规则entityManager-> clear()


  2. Doctrine QueryCache - 它缓存所有使用的查询,我发现唯一的配置是你能够决定什么你想要使用的那种Cache。我没有发现一个全局禁用,每个查询都禁用一个有用的标志。
    所以通常使用函数

     
    $ qb = $ repository-> createQueryBuilder($ a)禁用每个查询对象;
    $ query = $ qb-> getQuery();
    $ query-> useQueryCache(false);
    $ query-> execute();


so ..所有我现在想出来的...
我的问题是:



有没有一种简单的方法来拒绝Entitymanagerstorage中的一些对象?
有没有办法在entitymanager中设置querycache?
我可以在symonfony教义配置中的某个地方配置缓存行为吗?



如果有一些对我有一些不错的提示,会很酷,否则这可能帮助了一些新秀..



cya

解决方案

但是我想我刚刚在Benjamin Eberlei发现了一个 Google网上论坛线程这可以解答您的问题:由 Doctrine配置参考默认情况下记录的SQL连接被设置为 kernel.debug 的值,因此如果您已将实例化的AppKernel设置为 true ,那么SQL命令将被存储在内存中迭代。



您应该将AppKernel实例化为 false ,将记录设置为 配置YML,或者在使用EntityManager之前将SQLLogger手动设置为null。

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


actually 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 dont know the real name of this one) it seems like it keeps all processed entites and you have to clear this storage regulary 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 didnt found a global disable neither a usefull flag for each query to disable it. So usually disable it for every query object with the function

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

so.. thats 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 behaviours somethere in the symonfony doctrine configuration?

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

cya

解决方案

A little late, but I think I've just found a thread on Google Groups by Benjamin Eberlei that answers your question: 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天全站免登陆