Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory leaks Symfony2 Doctrine2 / exceed memory limit

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

like image 202
MonocroM Avatar asked Mar 14 '12 09:03

MonocroM


People also ask

What does memory limit exceeded mean in C++?

Memory Limit Exceeded Error: It typically occurs when no memory limit has been set. It means that the program is trying to allocate more memory than the memory limit for the particular problem. For Example, if the memory limit is 256 MB, then there is no need to write code that requires more than 256 MB of memory.

How to prevent memory leaks in your application?

There are various types of garbage collectors, and understanding how your application’s garbage collector functions is an important step in preventing memory leaks. Another method to prevent memory leakage is by writing a code that disposes of unneeded resources.

What is a memory leak?

What Is a Memory Leak? Computer memory is temporarily stored and retrieved from random access memory (RAM) for running various applications. A memory leak is a portion of an application that uses memory from RAM without finally freeing it.

What happens when the memory leak in an IIS pool occurs?

When the memory leak in an IIS application pool occurs, increasing physical memory (RAM) does not effective because the memory in this scenario is not the physical memory (RAM) but a virtual memory. The following table summarizes the virtual memory which is addressable memory from the web application. Overview.


1 Answers

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); 
like image 175
Sergi Avatar answered Sep 22 '22 21:09

Sergi