-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Container - stripComments can still use a huge amount of memory #18007
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
Comments
That was my initial contribution to release memory for processing after this stripComments, but it's irrelevant if token_get_all itself can eat 290mb in a single php func call and push you into swap. |
The only issue I see with using |
yes indeed, if you do need to debug your container in production that's the downside - and most likely the reason why it wasn't used originally. |
Except that debugging is discouraged in production |
By "debugging" i meant analysing logs more than actually debugging. |
How often would you actually need the "prod" container? I think it's neglectable, worst case scenario you can throw a prettyfier over it. |
Another potential issue is that putting the entire container in one line could make it fail for complex containers (I guess PHP limits this length). |
@javiereguiluz did some googling but I don't think this matters for PHP. Line endings are nothing more than a whitespace character and probably stripped away. |
I thought the second question was more interesting - Is it even worth stripping the container if opcache is pretty standard now and Symfony 3 requires >= PHP 5.5.9 anyway? Anyone using PHP in production nowadays without Opcache has probably got more to worry about than just a stripped container... Based on my minimal knowledge of opcache, I would vote for just not stripping at all. Does anyone more informed than my have any thoughts? |
@peteward I guess we need a performance test to see what's the impact. Since you've already got an app with a huge container, perhaps it'd be easy for you to perform a comparision with blackfire? Btw, docblocks wouldn't be stripped unless |
OK that was the more informed point right there 👍 I was thinking comments would be stripped as standard from opcache but annotations are a good reason why not to. Still, the containers comment blocks are all very formulaic:
There should be more memory efficient ways of stripping these out and leaving the rest to opcache. I will try to do some performance tests this week. |
looks good, will give it a try later. |
That's actually a very nice work-around, 👍 for the idea! |
…er (nicolas-grekas) This PR was merged into the 2.3 branch. Discussion ---------- [HttpKernel] Fix mem usage when stripping the prod container | Q | A | ------------- | --- | Branch | 2.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #18007 | License | MIT | Doc PR | - I propose to just replace doc comments by regular comments, so that the parser removes them and opcache doesn't have to keep them in memory, which is the target. Commits ------- 4fa5844 [HttpKernel] Fix mem usage when stripping the prod container
Hi,
A while ago I contributed on trying to reduce memory consumption in building the container through #17377. This impacted me because I use Platform.sh with Sylius, a heavy application in a limited RAM environment.
However, despite the above PR, a growth in our Sylius application meant that we recently started swapping on container compile and could not deploy to Platform.sh because any attempt at running a console command would be killed after 5 mins of swapping.
After some investigation it is simply
token_get_all
here.In our application, checking memory consumption either side of this line on PHP 7.0.3:
That's just under 300MB to tokenize the container, I'm not sure how much it is on php5.X but it's likely to be more.
The workaround I've used for our application was to override the Kernel methods and use
php_strip_whitespace
instead:The memory consumption after dumping the container now was only an extra 10MB compared to 290MB with token_get_all. The time difference was fairly negligible, slightly slower though. The resulting container was 4.8MB compared to 5.6MB.
Clearly we are a heavier use-case here, probably one of the larger containers around, but as systems and platforms grow I could see more people in our situation.
The original comment on the
stripComments()
method is:My questions are:
If you want to keep the current approach then I would be more than happy to contribute a Cookbook chapter about this since it took me a while to work around this.
The text was updated successfully, but these errors were encountered: