Symfony2 memory leaks and performance issues #2938

Closed
vyarmolenko opened this Issue Mar 28, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@vyarmolenko
Contributor

vyarmolenko commented Mar 28, 2016

I wrote some functional tests for Symfony2 app with multiple requests in a test and encountered an issue with test failing due to lack of memory (3GB's was not enough to complete the test). I rewrote my tests and still memory consumption was too big.
The cause of memory leak was the cloning of kernel on each request. it was introduced in #2042 as a solution to problem with service container introduced in #2491.
This issue may relate to the following issues:
#2203 - memory consumption
#2025 - first call to doctrine after client reboot
#2886 - similar memory consumption
#2853
#1804

Possible issues include:

  • big memory consumption of tests with multiple requests
  • long execution time/slow speed of tests with multiple requests
@raistlin

This comment has been minimized.

Show comment
Hide comment
@raistlin

raistlin Apr 4, 2016

Member

You have made me to spot some issues between Symfony2 module and Symfony2 connector.
First, Symfony2 module declares a public container variable. This variable is never used on the module, but user tests have access to this variable. Problem is that this container instance is never the container linked on the request running kernel. Doctrine works because it is a persisted service and shared among all kernels, but it's a very high trouble.

This container variable is totally invalidated just before first test run, because Symfony2 connector boots a new kernel on every request, and booting a new kernel creates a new container instance. Just before booting a new kernel the connector save persisted services to inject them after kernel has been booted. As a side note, just because kernel is cloned here, kernel on Symfony2 module and Symfony2 connector will be out of sync, other big source of problems.

In conclusion:

  • Symfony2 module do not need the container anymore, if needed we should provide a getContainer method to return current container.
  • Kernel on Symfony2 module and Symfony2 connector will be out of sync, connector should never clone or create a new kernel!

I will create issue to fix the first. The second will reopen #2042, but it's better to reopen and fix it the good way that having memleaks.

Many thanks for your research!

Member

raistlin commented Apr 4, 2016

You have made me to spot some issues between Symfony2 module and Symfony2 connector.
First, Symfony2 module declares a public container variable. This variable is never used on the module, but user tests have access to this variable. Problem is that this container instance is never the container linked on the request running kernel. Doctrine works because it is a persisted service and shared among all kernels, but it's a very high trouble.

This container variable is totally invalidated just before first test run, because Symfony2 connector boots a new kernel on every request, and booting a new kernel creates a new container instance. Just before booting a new kernel the connector save persisted services to inject them after kernel has been booted. As a side note, just because kernel is cloned here, kernel on Symfony2 module and Symfony2 connector will be out of sync, other big source of problems.

In conclusion:

  • Symfony2 module do not need the container anymore, if needed we should provide a getContainer method to return current container.
  • Kernel on Symfony2 module and Symfony2 connector will be out of sync, connector should never clone or create a new kernel!

I will create issue to fix the first. The second will reopen #2042, but it's better to reopen and fix it the good way that having memleaks.

Many thanks for your research!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment