
Troubleshooting Java container memory outages
Bunch of work to improve performance and app stability, and a deep dive on the investigation.
Transcript
This transcript is auto-generated. Names and product terms may be wrong.
bit of a non-demo here. Um I um we had a couple of um I guess no at this point it was uh a little over a month ago we had a little outage. Um it happened sort of early early early in the morning and um we required uh waking up uh folks on on our team in order to make sure that we could get it solved.
um sort of the what what ultimately ended up happening is that we had um released a change to our um container to upgrade to JDK 21. Uh we wanted to move to more modern uh JDK and we um released a tune to do that. The idea was that it was going to be available on the container and we were going to start using it.
Um however um the when the way our release process worked out um the change got merged in when we expected it to you know given part of the day but uh hadn't been released to hadn't started being used because we didn't have anything that had triggered a new deploy of of those new containers. Um ultimately what ended up happening was that um at around 2 or so in the morning in the Pacific um the uh change went out um due to uh something else being merged and um pretty much immediately a container started crashing.
Now, it wasn't necessarily um all of the containers, so there was it was only a little sort of partial outage, but we sort of noticed some some bad behavior going on. And um what we sort of very quickly were able to pinpoint sort of what the top level cause of the issue was and sort of revert that and go back to fixing fixing the problem.
um and and but we never really came back and solved um of why um the the upgrade to the JDK actually ended up causing problems. Um so I decided to spend a little time this week to go dig into that and figure out what happened. Um I wasn't really even sure where to start cuz by the time I decided to go actually go look into this, I didn't have u it had been over a month.
we were missing some of the uh telemetry data that we had created because it had just expired out, but I really wanted to get us moved back to DDK21, especially now that JDK25 is out um LTS. So, I wanted to um see what I could figure out and see if I could get us uh get that process at least going again.
Um what was pretty fortunate was that I I decided to go take a look at um I knew it was me memory related. I can go look, I can see all the the crash reports and find that the containers were dying because the containers, not the JVM, but the containers had run out of memory. Um, this was a little bit surprising to me.
Like, you take a look at the the JVM, it didn't look like it was all that large. Um, nothing seemed to be all that crazy. It wasn't affecting all of our containers, only some of them. Um, so I started to dig in and look through sort of our um to see if there was anything that looked like it was showing up incorrectly.
Uh, fortunately it kind of popped out at me pretty quick. Um, one of the things that I had noticed was that um, in the containers that was were running at the time, we we had we're running with about 64 GB of of memory on the containers. Um, and at the time we were decided we wanted to allocate some amount to the uh OS, some amount to the native memory allocations and some amount to um the the JVM heat memory.
Um, pretty and I know just off the top of my head that we had allocated 30 GB to the to the JVM heap. However, um, just looking at the first like this is this is the log lines of the container right as it boots up. Looking at the the GC logs, we can pretty quickly see the initial heat capacity was 47.6 gigs.
Um that surprised me. I saw that really quickly and I said that's interesting. I'll come and look at look into what happened there. Um and then I went and looked at some of our other containers um pre before this um before we made this change and noticed that it was as I expected around I think it was 30 or 24 gigs.
Um, so I decided to start keep digging and try to figure out what happened. And um, of course, because this happened a while ago, I didn't have a a great way to necessarily guarantee that I could reproduce it. Um however I um very quickly found that um if one deploys um out uh if one tries to start the JVM with u a a sort of small amount of of memory and um specify exactly how much it it should have it um starts to ignore you um on the new JVM.
Um and I wasn't really sure what hap what was going on there. um I could pretty reliably reproduce that it was doing that. Um and I wanted to really understand why it was doing that so that we didn't you know accidentally go deploy this new thing and have a misunderstanding was happening there and of course have this happen again.
Uh, as it turns out, um, I had kind of was watching the startup sequence on JDK 17 and JDK 21 and found that, um, something different happens. In particular, on JDK 21 17, it quickly goes it it looks the sort of croup memory. it finds that the the uh it there's an unlimited memory limit in the non- hierarchical memory limit but then it checks the hierarchical memory limit and and finds that it is sort of what is expected here with uh 32 gigs.
Um however on JDK 21 it sees that um there's an unlimited um container memory um and it never checks the hierarchical memory limit um and it finds that this is unlimited sees that there's you know 66 or 63 I guess gigabytes there and and it says okay cool I'm going to go use that 66 GB goes ahead uses that to measure how to to determine how much it should have it says we want to run with 75% of the heap there.
Um that's around 47 gigs and that's a lot more than we expected. Of course, the container actually only had 32 GB. Um so then immediately you can start to see why things start crashing without a memory exceptions. Ultimately, um it turns out that there is a JDK 21 bug where hierarchical memory limits are are not honored after some version of the JDK.
Um and and some some patch that happened there. Um, and it just so happened that we were running a version that was affected by this and it ended up causing this sort of problem. Um, turns out it is not actually yet fixed in JDK 21. It has been backported to JDK25 but has not made its way back to JDK21.
Something that um, we will probably uh, if if we want to solve this and go use JDK21, we will have to have a workound. I have some ideas. I've already put them in place with the PR up, but um probably will need some discussion when other folks come back from the holiday break. But ultimately, it was sort of get good to dive into the problems that we were seeing and make sure that we had a full understanding of what was going on so it doesn't happen again.
Cool.