mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Memory leak with namedQuery execution? #6199
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @lashus on GitHub (Mar 11, 2019).
Originally assigned to: @lashus on GitHub.
Bug Report
Summary
I am using symfony 3.4 along with doctrine for my project. In one of the commands where I'm generating the ranking for users I've encountered potential memory leak when using namedQuery (though I might be wrong).
In each loop iteration (over 2000 records) I'm running an
EntityManager->clear()method along withgc_collect_cycles()(just to ensure proper garbage collection). Although the memory usage just after 10000 iterations jump to around 500mB which is really odd as it works normally in other commands that are using queryBuilder to form queries.I've made sure that no other code is responsible for this memory issue and extracted the execution to just fetchin results and running named query.
I've also tried disable sql logger in entity manager config but this didn't help. Anyone got ideas what could be wrong?
NamedQuery
Current behavior
The problematic part of code (up to ~500MB):
How to reproduce
Just iterate over some larger set of data and try to run simple namedQuery along with fetching the scalar result. Sample code extracted from one of commands below.
Expected behavior
The solution w/o memory leak (up to ~60-70MB):
@Ocramius commented on GitHub (Mar 11, 2019):
Can the memleak be reproduced with
doctrine/ormonly? Symfony notoriously adds SQL loggers that cause memleaks (usually only in dev mode).@lashus commented on GitHub (Mar 11, 2019):
@Ocramius SQL Loggers are disabled in the command but I can prepare some sample repo for this purpose.
@Ocramius commented on GitHub (Mar 11, 2019):
Please use our existing test suite. See https://github.com/doctrine/orm/tree/v2.6.3/tests/Doctrine/Tests/ORM/Functional/Ticket
@lashus commented on GitHub (Mar 11, 2019):
Here is the example created accordingly to the Contribution file in the repo. I hope i haven't missed anything important.
https://github.com/lashus/orm/blob/bug/%237642-memory-leak-namedquery-execution/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7642Test.php
@Ocramius commented on GitHub (Mar 11, 2019):
Can these two blocks be changed to not cause any I/O themselves? Hard to understand where the issue is otherwise:
f2e43267af/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7642Test.php (L33-L107)@lashus commented on GitHub (Mar 11, 2019):
Could you please elaborate? I'm not sure what do you mean by
I/O themselves. If I don't run queries we won't see the memory footprint they generate.@Ocramius commented on GitHub (Mar 11, 2019):
I'd need the test to be re-structured like this (pseudo-code):
@lashus commented on GitHub (Mar 11, 2019):
Ok, thanks for the help and sorry for wasting time - I'm closing this as it's not related to doctrine apparently as the fixed tests are showing almost 0 difference between two methods. I've uploaded them anyway just in case.
In the original tests I put the return statement by accident in one of the methods which was causing the significant difference in memory output of these two functions .
f2e43267af/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7642Test.php (L61)@Ocramius commented on GitHub (Mar 11, 2019):
@lashus no worries! Glad it could be solved somehow :)
@flaushi commented on GitHub (Mar 20, 2019):
I think I have a closely related issue, at least I can reproduce that the memory footprints do not differ even for a tiny byte.
I copied your test and filled in my problem, but the
memory_get_peak_usagevalues are equal. Any other way to measure the difference?@lashus commented on GitHub (Mar 20, 2019):
Hmmm it's going to be hard to be honest I was relying on that method and on my symfony command the leak still exists. Though I am using mysql in my project and as you pointed out in the related issue - the tests are ran on the sqlite database so it's not really reliable.
I'll try to reproduce this by running this code on external mysql connection but won't be able to do that until next week :/