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
Linked issues
is duplicated by
relates to
Attachments
Comments


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-273334 describe 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:
Does this happen regardless of the used world? E.g. if you run a flatland or void world on the server, are there lag spikes still?
If this only happens with a specific world, please attach the affected (zipped) world file. If the file size is too large, please upload it somewhere else and then link to it here.
Is there anything special about the world, e.g. heavy data packs or large entity count in a particular area?
What are the server settings, e.g. simulation distance? Anything you changed from default? Note that a higher simulation and entity distance has a large impact on server performance.
Does this also happen with another Java runtime, e.g. the one provided by Mojang when downloading the game? I believe the latest version is at
runtime/java-runtime-delta/windows-x64/java-runtime-delta/bin
in your Launcher installation 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

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:
Happens regardless of world, although for less busy worlds the memory grows slower
Does not happen if server runs on Linux (appears to be a Windows-only issue)
Happens regardless of used Java runtime
Less allocated RAM makes the issue worse
@@unknown, 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.
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ย
ย