-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 recompress unchanged packets #3240
base: master
Are you sure you want to change the base?
Don't recompress unchanged packets #3240
Conversation
77eab47
to
272de22
Compare
Is this going to be next dusty PR that can potentially bring performance boost without any complications? |
Well, remember that we need to wait md_5 to see if will work good stability it's more important. |
Yeah the problem is that I do not operate any server where I could test this on. But apart from the entity map rework the changes should not cause subtle problems - either the packet works or it doesn't. |
I can test it if will send it to me as flamecord patch. |
try he's repository and check if its working |
I would test this in production :pep: |
I can't go back with security fixes etc, so the only way to test it in production by me is adding it to FlameCord. |
I will implement this into FlameCord if you give me permission to. We can test it on many servers that agree on experimental security/performance fixes. |
Permission granted for this patch to be included in Flamecord, Waterfall and IvanCord if contribution is given to me in the patch commit notes and the patch-adding commit. This patch could break stuff like ViaVersion-on-bungee or other bungee plugins which do not restrict themself to the bungee api, especially if they interact with the netty pipeline. |
IvanCord already breaks Via plugins so ima implement it just like some of the other patches you have :) |
I keep getting time outs. compression-threshold: 256 both on the server im connecting and bungee. |
Honestly I have no clue what might be going wrong @MrIvanPlays |
I will reimplement later and share the patch to make sure I haven't implemented something wrong. |
interesting... now it works fine... ok java ig |
Your patch looks shorter, is that's all what is needed? |
@MrIvanPlays |
BTW No recompressing means that if you have 4kb chunk packet you won't compress it to smaller size? |
No. This patch lowers cpu usage of bungee if your spigot servers have compresion threshold not disabled. In case of packets bungee does not need to edit (like chunk packets), this patch will keep and send the compressed data. This means bungee does not need to compress data again which it already recieved compressed. |
What if i have bukkit threshold set to 4000 for example? It will send like this to the client? It will be pretty big packet. |
Bungee's threshold is still respected. f bukkit threshold is at 4000 and bungee threshold at 256, packets between size 256 and 4000, as well as any packets bungee had to change, are still getting compressed by bungee. |
So they will be decompressed and compressed, right? |
If bukkit's threshold is at 4000, packets below 4000 are not compressed by bukkit. |
So without the same threshold on bukkit it won't bring anything, right? |
I think you misunderstood. Packets < 256 will stay uncompressed always. |
But you said that bungee's threshold is still respected, so you will send 4000 packet with 256 threshold? |
@Janmm14 I have entity rewrite disabled. |
when the threshold is at 256, packets with size <= 255 are sent uncompressed and packets with size >= 256 are sent compressed |
Exactly, compressed to 256, right? When you don't recompress, you send 4000 packet, yes? |
When I talk about packet size I mean the size of uncompressed packets (in bytes). |
I thought 256 threshold would not allow packet with compressed size larger than 256 bytes. |
Well thats wrong. 256 threshold means that only packets where the uncompressed size is found to be at least 256 bytes will be compressed before sending. Reason: |
Ok, I think I understand now. So if threshold doesn't impact the size, I can't wait for your patches to be implemented in Bungee. If @MrIvanPlays did everything right just with entity rewrite disabled, I'm going to test it too. 🚀 Thanks for explanation and work with this patch. ❤️ |
@andreasdc do you have discord so we can chat? |
skipString( buf, Short.MAX_VALUE ); | ||
} | ||
|
||
public static void skipString(ByteBuf buf, int maxLen) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are two methods for this necessary?
As we skip the bytes anyway i think we don't need a extra limit and just skip the len
Perhaps a tunneling protocol could also remove unnecessary decompression. Just like this.
I did this in my private branch with cpu usage from1000% to 200% cpu per thousand players. |
Doesn't this cause problems? For example, the player's status is incorrect. |
Bungee doesn't use entity rewrite for newer mc versions. |
It does for offline mode |
Ah yes, but thats limited to a few uuid rewrites. |
bump |
1.20.2 update? 🚀 There are changes to PacketWrapper |
9dbb458
to
bc8151e
Compare
… DefinedPacket to optimize EntityMap
…ress if compressed data is present
bc8151e
to
a4449be
Compare
Based on #3238 (comment)
old
I created a working example of keeping the compressed data until we change the packet.However as of now it does not work and I am unable to find the problem and I hope its not because I'm too tired.It works when I stop allow letting this if to evaluate to true: https://github.com/SpigotMC/BungeeCord/pull/3240/files#diff-c1c0d1f8d0b4bc645d9a23cd0daee5755bd8f3f58af400763d8ccfb0bbe5ac06R70Edit: I am definitely too tired. I just sliced too late.
Old, oiginal WIP code: https://github.com/Janmm14/BungeeCord/tree/dont-re-compress-unchanged-packets-orig
Plans for this PR:
Changes
This PR first refactors EntityMaps as the no-recompress changes involve changes in the EntityMaps and that code was not that nice to look at.
Then the main changes happen:
PacketWrapper
can contain aByteBuf compressed
PacketDecompressor
createsPacketWrapper
s on the pipeline for incoming compressed packets instead of theMinecraftDecoder
containg decompressed and compressed buffers.MinecraftDecoder
edited to support both ByteBuf and PacketWrappers as input.MinecraftDecoder
removes compressed data for fully decoded packets.PacketWrapper
instead of itsbuf
.PacketCompressor
can now also handlePacketWrapper
s to write and will write the originalcompressed
contents if available.PacketWrapper
s and will just write itsbuf
.At the end, I put in further optimizations of the EntityMaps, including to no longer involve the connections lock when a SpawnPlayer packet is sent with an online mode uuid (this is the default with ip_forward enabled).
Testing
As these changes are rather large, I am asking for some people to test these changes additionally to me.
I am fairly confident that the EntityMap changes are bug-free as 99% of the code I deduplicated was exactly identical.
Test build: https://ci.janmm14.de/job/public~mcjava~bungeecord-norecompress-entitymap/