Java server lags insanely hard when the GC frees up RAM
Hi! I don't know where else to report this, didn't find anything useful on the internet, so i decided as a last try to write here.
My issue is that when my server's GC frees up the ram, or even just while running, it gets insanely laggy sometimes. Sending the warnings "Can't keep up! Is the server overloaded? Running 6980ms or 139 ticks behind" like this. I gave the server 16GB ram, but as i noticed its not using my cpu fully, only a few cores.
Here are the specs:
CPU: AMD Ryzen 7 5800X3D
Motherboard: MSI B550-A-PRO
RAM: 2x16GB Corsair Vengeance 3600MHz CL16
GPU: AMD Radeon RX6600XT
SSD: Apacer AS2280Q4 1TB
I really hope this is the right place to post this, and hoping to find a solution.
The lags on the normal server were much worse than on papermc, happened every minute, rather than 2-3 minutes on paper)
Performance logs of the original server file attached, every other information is the same
Environment
Operating system: Windows 10 (amd64) version 10.0
Java version: 21.0.3, Eclipse Adoptium
Java VM version: OpenJDK 64-Bit Server VM (mixed mode, sharing), Eclipse Adoptium
Processor: AMD Ryzen 7 5800X3D 8-Core Processor
CPUs: 8
Frequency: 3.4 GHz
Graphics card: AMD Radeon RX 6600 XT
Linked Issues
is duplicated by1
Created Issue:
My java server lags insanely hard when the GC frees up ram(now with original server file, not papermc)
Hi! I don't know where else to report this, didn't find anything useful on the internet, so i decided as a last try to write here.
My issue is that when my server's GC frees up the ram, or even just while running, it gets insanely laggy sometimes. Sending the warnings "Can't keep up! Is the server overloaded? Running 6980ms or 139 ticks behind" like this. I gave the server 16GB ram, but as i noticed its not using my cpu fully, only a few cores.Here are the specs:
CPU: AMD Ryzen 7 5800X3D
Motherboard: MSI B550-A-PRO
RAM: 2x16GB Corsair Vengeance 3600MHz CL16
GPU: AMD Radeon RX6600XT
SSD: Apacer AS2280Q4 1TBI really hope this is the right place to post this, and hoping to find a solution.
The lags on the normal server were much worse than on papermc, happened every minute, rather than 2-3 minutes on paper)
Performance logs of the original server file attached, every other information is the same
Environment
Server: Java 21
Windows 10 Pro
We do not have enough information to find the cause of this issue.
While the lag occurs, please press F3 + L once, then wait a short moment until profiling has finished.
Afterwards, please attach the generated .zip file containing the profiling results here. The file path is shown in chat; the file can be found in minecraft/debug/profiling/<DATE>.zip.If you are playing on a server please additionally run the command /perf start to create a profiling report for the server. In case you do not have the permission to run this command, make sure that you're a server operator.
Once profiling has finished, please attach the generated .zip file from debug/profiling/<DATE>.zip of the server folder.This issue is being temporarily resolved as Awaiting Response. Once the requested information has been delivered, the report will be reopened automatically.
Quick Links:
📓 Bug Tracker Guidelines – 💬 Community Support – 📧 Mojang Support (Technical Issues) – 📧 Microsoft Support (Account Issues)
📓 Project Summary – ✍️ Feedback and Suggestions – 📖 Game Wiki
Think of it this way increasing that value allows more cpu usage and causes increased memory usage.
so you are using a boatload of pseudo/virtual memory (doesn't show as using mem but is)
main solutions:
a) (least optimal due to experimental nature)-XX:ActiveProcessorCount=4 ... is like using a horse instead of a car.
b) (optimal method) remove all usages of -XX:ActiveProcessorCount cause it won't help, and then try my arguments again. c) (optimal method) use config mod YOSBR to fix the situation. d) try regular server with solutions a, b, c
Note: all minecraft versions have more issues when low disc space on any drives, especially low disk space on temp folder drive and make sure main directory drive has a lot of disk space.
conditionals to check:
- drive space for all drives that are being used(including drives for temp folders Minecraft occasionally uses)
- make sure to allocate a decent amount of memory for game.
- something* I can't figure out what, is using more ticks than it should be.
Server: Java 21
Windows 10 Pro
Myjava server lags insanely hard when the GC frees upram(now with original server file, not papermc)My Java server lags insanely hard when the GC frees up RAM
relates to
Operating system: Windows 10 (amd64) version 10.0
Java version: 21.0.3, Eclipse Adoptium
Java VM version: OpenJDK 64-Bit Server VM (mixed mode, sharing), Eclipse AdoptiumProcessor: AMD Ryzen 7 5800X3D 8-Core Processor
CPUs: 8
Frequency: 3.4 GHz
Graphics card: AMD Radeon RX 6600 XT
MyJava server lags insanely hard when the GC frees up RAM
relates to
His thread: "DestroyJavaVM" prio=5 Id=30 RUNNABLE
relates to
is duplicated by
Thank you for your report!
We're tracking this issue in MC-271756, so this ticket is being resolved and linked as a duplicate.
If you would like to add a vote and any extra information to the main ticket it would be appreciated.
If you haven't already, you might like to make use of the search feature to see if the issue has already been mentioned.
Quick Links:
📓 Bug Tracker Guidelines – 💬 Community Support – 📧 Mojang Support (Technical Issues) – 📧 Microsoft Support (Account Issues)
📓 Project Summary – ✍️ Feedback and Suggestions – 📖 Game Wiki
– I am a bot. This action was performed automatically! The ticket was resolved by one of our moderators, and I left this message to give more information to you.
So this is mainly an issue with (minecraft's caches) and an (issue with mobs), best option atm is using modrinth "aesthetic and performant" page
also I noticed the JVM flag -XX:ActiveProcessorCount=8 is causing worse performance on server and host computer.
Thanks for the reply, I'll try these as soon as possible. I use the jvm flag "-XX:ActiveProcessorCount=8" because as i noticed these lags were a bit less frequent
I also found out this only happens on Windows. When I ran the server and the client both on Arch Linux I haven't noticed these lags. Plus i tried that i ran the client on my pc, and the server on a lower end laptop (8gb ddr3 ram, gave 7gb to the server, the cpu is i5-4200U), and i haven't noticed these lags there neither.
Simple explanation: -XX:ActiveProcessorCount=8 this java argument apparently decreases minor GC's and results in more major GC runs. So even though it is a valid java argument treat it as experimental.
Tried those JVM arguments, sadly it still didn't fix it
Final main answer unless none of my solutions work, 1. use standard server 2. use config mod YOSBR to fix the situation
3. (least optimal due to experimental nature)-XX:ActiveProcessorCount=4 ... is like using a horse instead of a car.
4.(-XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+AlwaysPreTouch -XX:+OptimizeStringConcat -XX:+UseCriticalJavaThreadPriority) doesn't fix issue, just states I want performance. {note to minecraft moderators: (minecraft's caches) and an (issue with mobs) and (GC) bug increased by paper although still present in regular}{}
Does
MC-273334describe your issue?Please check if this is still an issue for you in 1.21. If so, please update the affected version.
Yes, the issue still present in 1.21, and no, those options didn't fix the issue
Could you please provide the following information:
This issue is being temporarily resolved as Awaiting Response. Once the requested information has been delivered, the report will be reopened automatically.
Quick Links:
📓 Bug Tracker Guidelines – 💬 Community Support – 📧 Mojang Support (Technical Issues) – 📧 Microsoft Support (Account Issues)
📓 Project Summary – ✍️ Feedback and Suggestions – 📖 Game Wiki
I'll test it on a flat world soon. No this isn't world specific issue, happens on every world i create, and there aren't any datapacks. The server settings are the default settings, i haven't changed anything. Yes it happens on every java runtime on windows. I don't remember if i already said this, but it might be an issue with the windows java runtime only. Since I've tested it on Arch, and Ubuntu and it ran really fine there. Even on a low end system.
It happens on a flat world too, but less noticable since the GC doesn't empty much amount in such a short time, like a normal world would
What are you doing in the world when you experience the issue? Does the lag spike occur just at random intervals even when completely idle — or at least staying roughly in the same radius, or does it occur when you are doing things such as exploring new chunks?
Provided the fairly vague nature of this report, I am inclined to investigate further and find more context as to when this occurs to try and reproduce (and thus confirm) it on my own server. It would also be helpful to know if decreasing the ram down from 16gb to something like 8gb benefits the performance of the garbage collector at all.
Yes it happens while completely idle too, only happens when thr gc empties (ram usage goes down), and no, decteasing the ram doesn’t help at all, only makes it worse. Only thing that helped was running the server on linux
This seems like a duplicate of MC-273262, as that issue is also caused by the default garbage collector used in Minecraft. Does using another version of Java (e.g. Java 22) to run the server help?
No it didn’t help, i was already running it with a different java (not the minecraft default java)
I've set this bug report to "plausible" so that Mojang can investigate, as this could be a bad memory leak somewhere.
Important information from the comments not mentioned in the bug report itself:
@GaborV, regarding your comment "Only thing that helped was running the server on linux", I'm assuming you were running it on the same hardware but with different OS? If not, what hardware did you use to run it on Linux?
Also if there's any information that you think could be useful for investigating this, please provide it.
Yes, this is a memory leak in jdk 21 G1GC, also present in MC-273262 ,
MC-271216, MC-273024, and many more. Two easy solutions, one more challenging 1. Implement along the lines of using java args such as (ParallelGC by default with 6 threads, a minimal GCTimeRatio such as 0, and minimal GCPauseMillis=1) 2. Remove G1GC from valid java arguments. 3. Other solutions such as fixing Minecraft's caches could work.Are you still able to reproduce this issue on the latest version?
It seems to me, yes this is still persistent on the latest version. Only on Windows obviously, when I have more time i'll try to mess with the settings to see if anything changes.