-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
don't set -XX:MetaspaceSize= setting since it can prevent cleanup of allocated native memory #159
Conversation
Hey lhotari! Thanks for submitting this pull request! All pull request authors must have a Contributor License Agreement (CLA) on-file with us. Please sign the appropriate CLA (individual or corporate). When sending signed CLA please provide your github username in case of individual CLA or the list of github usernames that can make pull requests on behalf of your organization. |
@lhotari At the very least you'll need to squish your two commits into a single one. Beyond that, do you have any evidence that this change (which would be different than everything other memory setting) does actually change the cleanup behavior of the |
@nebhale The Rubocop fix wasn't related to the change I made. That's why I didn't squish it. I'll rebase the PR and see if the Rubocop error has been fixed else where. |
@nebhale I assume that setting This is documented in this Oracle documentation about Class Metadata and that lead me to make these conclusions. Class metadata is deallocated when the corresponding Java class is unloaded. Java classes are unloaded as a result of garbage collection, and garbage collections may be induced in order to unload classes and deallocate class metadata. When the space committed for class metadata reaches a certain level (a high-water mark), a garbage collection is induced. After the garbage collection, the high-water mark may be raised or lowered depending on the amount of space freed from class metadata. The high-water mark would be raised so as not to induce another garbage collection too soon. The high-water mark is initially set to the value of the command-line option `MetaspaceSize`. It is raised or lowered based on the options `MaxMetaspaceFreeRatio` and `MinMetaspaceFreeRatio`. If the committed space available for class metadata as a percentage of the total committed space for class metadata is greater than `MaxMetaspaceFreeRatio`, then the high-water mark will be lowered. If it is less than `MinMetaspaceFreeRatio`, then the high-water mark will be raised. Specify a higher value for the option `MetaspaceSize` to avoid early garbage collections induced for class metadata. The amount of class metadata allocated for an application is application-dependent and general guidelines do not exist for the selection of `MetaspaceSize`. The default size of `MetaspaceSize` is platform-dependent and ranges from 12 MB to about 20 MB. |
66f3fb2
to
7480abe
Compare
@nebhale Now it's a single commit after rebasing it on the latest master. |
Why are you keen on getting a Metaspace GC earlier than you'd absolutely have to? As long as the container has enough memory to handle |
@nebhale I believe that Metaspace GC does do some cleanup that reduces the RSS allocation of the Java process. I think that it does matter that Metaspace GC is postponed. I'm currently testing this hypothesis with the webapp I'm maintaining and running in Pivotal WS. Since setting |
Let's assume for a moment that the |
@nebhale From my understanding metaspace isn't allocated from the heap at all.
Why would better accounting for the |
To be more precise, we need to better account for all types of memory allocation. We know exactly how much memory the Warden container will allow us before the process is killed. Given that, we can back out how much heap, permgen/metaspace, native, and stack needs to be allocated to keep us under that number. If you're seeing a situation where the amount of memory being used is going over what Warden is allowing and the process is being terminated because of it, it means that our accounting for how the total memory space is used, is wrong. When we solve that problem, the rest of this disappears. |
@nebhale I agree here. That's the primary reason I opened #157 and #158 so that we can improve how much memory should be reserved for thread stacks and limit the number of threads in the Tomcat container to the amount we have reserved.
I disagree here. It cannot be solved by just improving memory calculation in the Java buildpack. It looks like it's essential to tune the glibc memory allocation settings like |
Well, for #158, there is already a limit, we just need to make sure that we take it into account (changing it if we get signoff from @markt-asf). #157 has veered off into dealing with |
I have now made an observation that after I started using the buildpack fork that doesn't set I'm getting memory info from the production app with the MemoryInfoServlet solution. I have a cron job on one of my linux boxes to log that info. I'm basing my observations on the data I've been gathering this way. I haven't yet started using the |
@lhotari do you have any further information that setting
As that's the reason we matched them in the first place, I'm inclined to stick with it unless you've got something compelling that overrides that benefit. |
@nebhale No. I've been posting quite a lot of information here and explained my reasoning. I don't have any new information about it.
The class metadata garbage collection doesn't reduce normal JVM heap space GC since class metadata isn't using the JVM heap in Java 8. Where can you find recommendation to set |
@lhotari That quote came from the link where you references the pre-allocation. We've set it to minimize that GC, but have no other recommendation to set it. |
@nebhale Is there some reason to minimize that GC (class metadata garbage collection in Java 8)? |
Simply the best possible startup time. We match the heap sizes as well just to ensure that no time is lost to the GC at startup. |
@nebhale Yes there is always tradeoffs involved. |
…allocated native memory
7480abe
to
d14f6d6
Compare
We've performed some testing with this change, and if you set the MaxMetaspaceSize and MetaspaceSize to the same value then it disables garbage collection. This is a vital change to the buildpack. |
@cagiti Do you have any documentation stating that it disables garbage collection? Specifically, I'm wondering if you're seeing that GC never happens because there is so much headroom, vs. it going OOM without ever even trying. |
@nebhale we are monitoring our application using newrelic, this shows that under testing without this change we did not witness GC Collection, it shows the GC Sweep. However, testing of this change shows that when the MetaspaceSize is not set then GC Collection occurs. |
Right, so it seems like what you are seeing is that GC is happening when needed, it's just not needed very often (which is what I'd expect with this configuration). Unless you're seeing OOM problems, I'm not sure you can deduce that garbage collection is disabled. Keep in mind that in each container, it's perfectly reasonable for your application to use the entire allocated memory space. There's no need for a GC unless you've got so much garbage you can't say under the max. |
Hi @lhotari Also, we have some other work underway that will allow the setting of initial memory (Xms, MetaspaceSize etc..) independently from the maximum. The default will remain with the current behavior, initial and max memory set the same but it will be easy to change with an environment variable. #200 With this is mind would you like to update this pull request and we will proceed with the investigations or will the changes coming satisfy your needs here. Thanks, Chris. |
@cgfrost . this pull request doesn't make any sense any more since memory calculations are now in https://github.com/cloudfoundry/java-buildpack-memory-calculator . |
I have made a comment on the other issue where we are making changes to the memory calculator about supporting no |
No description provided.