Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in Manager::persist() #16

Open
epashkov opened this issue Dec 3, 2020 · 3 comments
Open

Memory leak in Manager::persist() #16

epashkov opened this issue Dec 3, 2020 · 3 comments

Comments

@epashkov
Copy link

epashkov commented Dec 3, 2020

When indexing a large set of documents in a cycle i see that memory usage grows every time i call manager->persist($document);

@epashkov
Copy link
Author

epashkov commented Dec 3, 2020

I had tried to add __destruct method like this

public function __destruct() {
    unset($this->document);
}

to class https://github.com/handcraftedinthealps/ElasticsearchBundle/blob/5.x/Event/PrePersistEvent.php but it still leaks.

@alexander-schranz
Copy link
Member

I think this could be more a listener which listen to the PrePersistEvent event. Also PHP is not the best for importing large amount of data but you could work agains it by using gc_collect_cycles method if you read from doctrine also make sure the clear the doctrine manager sometimes e.g.::

$counter = 0;
foreach ($dataList as $data) {
     ++$counter;

     // create and persist documents here:

     if (0 === $counter % 100) {
         // clear also the entityManager if used
         $entityManager->clear();
         // call garbage collector manually
         gc_collect_cycles();
     }
}

Also make sure you doing imports in prod environment under dev and debug symfony collecters are active which will collect all events so it normally there that the memory usage increases and grow, so memory can only be tested when running under app_env=prod with app_debug disabled.

@epashkov
Copy link
Author

epashkov commented Dec 7, 2020

@alexander-schranz Thanks for response. Think you are right about PrePersist Event. Seem that gc_collect_cycles() is not working as well in my case. Really in production environment memory usage increases less. It's quite satisfactory for my needs. Thanks a lot for clarifications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants