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

[FrameworkBundle] KernelTestCase Resetting Services take more memory than without #51006

Open
alexander-schranz opened this issue Jul 17, 2023 · 5 comments

Comments

@alexander-schranz
Copy link
Contributor

alexander-schranz commented Jul 17, 2023

Symfony version(s) affected

6.3.1 (not sure if lowers also effected)

Description

I'm currently fighting memory issues in a projects tests. I stumble over #45668 and in my case reverting that change uses less memory than more memory e.g.:

Before (with $container->reset()) memory increases faster:

Bildschirmfoto 2023-07-18 um 00 04 15

After (without $container->reset()) memory increases not so fast:

Bildschirmfoto 2023-07-18 um 00 05 48

How to reproduce

I'm not able to share the project. But the Extension outputting the memory usage from class to class can be found here: https://gist.github.com/alexander-schranz/d2b30177c1043099c44ef50b33db8412

So maybe somebody can test its own project if it increases or decreases when not call $container->reset() method.

Possible Solution

     protected static function ensureKernelShutdown()
     {

         if (null !== static::$kernel) {
             static::$kernel->boot();
-            $container = static::$kernel->getContainer();
             static::$kernel->shutdown();
             static::$booted = false;
             static::$kernel = null;

-            if ($container instanceof ResetInterface) {
-                $container->reset();
-            }
         }
     }

Additional Context

No response

@alexander-schranz alexander-schranz changed the title [FrameworkBundle] KernelTestCase Resetting Services take more memory then without [FrameworkBundle] KernelTestCase Resetting Services take more memory than without Jul 17, 2023
@nicolas-grekas
Copy link
Member

gc_collect_cycles to the rescue?

@alexander-schranz
Copy link
Contributor Author

alexander-schranz commented Jul 17, 2023

Sadly not actually, no changes measured on using gc_collect_cycles. Tried unsetting all my own test properties and calling gc_collect_cycles after every test: https://gist.github.com/alexander-schranz/f0e0bfd8c862b08373a97ff0ceed5192#file-cleanuppropertiestestlistener-php-L32. But that didn't decrease any memory usage for this test suite.

@alexander-schranz
Copy link
Contributor Author

alexander-schranz commented Jul 18, 2023

Got time today to run the whole test suite, the endresult of the whole test suite is not so dramatic as the first few tests but still it improves and currently avoids that our CI running into Killed by no memory available:

With Reset:

Memory: 2.21 GB

Without Reset (currently vendor-patched the class):

Memory: 1.98 GB

@nicolas-grekas are always all services reseted? Or only the one which where used?

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@alexander-schranz
Copy link
Contributor Author

I still use the vendor patch in the project to avoid memory increasing unexpectly.

@carsonbot carsonbot removed the Stalled label Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants