跳到正文

RatNetworking

作者:SolarBiscuit

Mixed fork of Krypton, VMP, and PacketFixer for 1.20.1 w/ a myriad of fixes & some new behavior to optimize network behavior both client-side and server-side.

收藏

介绍

中文介绍正在准备中,下面暂时显示原文。

RatNetworking

FYI: This mod will be renamed fairly soon on the next public release, so please keep note if you are following this. Enjoy the rat eating the sea cable in the meantime 😀

RatNetworking combines Krypton, Very Many Players (VMP) and Packet Fixer into a single Forge 1.20.1 mod, with bugfixes in each of them as well as some new optimizations.

Why it exists:

  1. Age on Forge The Forge 1.20.1 version of VMP specifically haven’t been updated since 2023–3 years ago. As a result, several older bugs remain in them from over the years.

  2. Compatibility. These mods often conflict with each other and with other mods in dense modpacks. Stitching VMP into large packs in particular has caused problems. RatNetworking is built and tested to work alongside heavy Forge packs (tested with ATM9, BetterMC 4, Valhelsia 6, and my own 450+ mod pack).

What’s new

Flush batching across the whole tick (server)

In vanilla, every packet triggers its own socket flush (a writev syscall), so a busy player costs hundreds of syscalls per tick. RatNetworking holds the flushes while a dimension runs its chunk tick (all block-change broadcasts plus entity tracking) and while a player’s chunks are loading, then flushes each connection once. A flush still goes through every 64 KiB, so large bursts fire immediatley. The result is about 1–2 syscalls per player per tick instead of hundreds (or higher in a modded context).

Entity-tracking shortcut on player movement (server)

For every movement packet, vanilla will check the moving player against every tracked entity in the dimension: roughly entities × players × 20 checks per second (as you can imagine this is a lot). RatNetworking runs a cheaper check: if the player is beyond view distance and isn’t already tracking the entity, a full check is skipped. The outcome is identical to vanilla; most checks are skipped in large worlds. This is something I’m working on benchmarking for more accurate numbers in vanilla + modded installs, should have some more data on this next month.

Memory leak fixes at join and disconnect (client + server)

Forge never releases the buffers used by login query packets (registry and config sync), so every join leaked direct memory; that’s megabytes per join in large modpacks. Custom-payload packets during play could leak the same way. RatNetworking keeps this data in normal heap buffers the garbage collector reclaims. Vanilla’s native zlib state (around 256 KiB per connection) is also freed as soon as a connection closes instead of whenever the GC does.

Zero-copy frame-length writing (client + server)

Vanilla copies every outgoing packet into a new buffer just to put a 1–3 byte length in front of it. RatNetworking writes the length into its own smaller buffer and sends it together with the untouched packet body into a single writev. It also supports 4–5 byte lengths, so packets larger than 2 MiB can be sent. (Measured to be roughly 1.8–2x faster on Windows; delta is zero on Linux.)

Rejecting invalid packets before allocating memory (server)

A fixed version of Packet Fixer’s raised limits. Packet Fixer lets a connection that hasn’t logged in announce a huge packet, and the server holds memory for it until the read timeout. RatNetworking:

  • applies raised packet limits only after a player has logged in;
  • rejects oversized packets from their length header alone, before buffering any data;
  • rejects any claimed decompressed size beyond DEFLATE’s maximum possible expansion (~1032x);
  • caps decompression output at the claimed size and requires an exact match.

(Benched vs PacketFixer: a 200 MiB packet announced before login is closed in about 3 ms vs 15s+ PacketFixer the connection stayed open.)

Included from the original mods

  • Faster compression (from Krypton): libdeflate on Linux (x86_64 / aarch64): 4.4x faster compression and 1.9x faster decompression than vanilla, at vanilla’s compression level, so no extra bandwidth.

  • Faster packet splitting (from Krypton): no copy per incoming packet, and floods of empty “nullping” packets are skipped. 2.5–4x faster, 94% less memory churn.

  • Non-blocking disconnect (from VMP): the server no longer stalls waiting for kicked players’ sockets to close.

  • Raised packet limits and timeouts (from Packet Fixer): fixes errors like Payload may not be larger than 1048576 bytes, length wider than 21-bit and Tried to read NBT tag that was too big, with safe defaults.

  • Some of the bugfixes in the originals:

  • Packet Fixer’s server read timeout never applied. It also made tab-list ping go stale.

  • Krypton could free compression memory that was still in use. It’s chunk entity lookup could also leave entities to appear invisible in some cases.

Most speedups was benchmarked against vanilla before it was kept. Any Krypton changes that measured slower on Java 17+ were left out (20 benched runs against vanilla & 2 modded instances).

Installation

  • Optional on both sides. It works on the server only, the client only, or both. Packets larger than vanilla’s limits need RatNetworking (or Packet Fixer) on the receiving side.
  • Recommended: install on both the server and the client.
  • Everything can be toggled in config/ratnetworking.properties. Operators can run /ratnetworking to see active modules and limits.

Compatibility

Mod Status
Krypton Reforged / Krypton Reno Incompatible. The game won’t start with both installed; this is based in it’s core on the original Krypton. 
Krypton (Fabric, through Sinytra Connector) Detected; RatNetworking turns off its overlapping parts. Not needed alongside RatNetworking.
Very Many Players Not supported. If detected, RatNetworking turns off its overlapping parts.
Packet Fixer Compatible. RatNetworking turns off its packet limits, timeouts, packet splitter/prepender and compression, so Packet Fixer’s apply instead. Removing Packet Fixer is recommended.
Connectivity Compatible. RatNetworking turns off its timeouts, outgoing packet size limit and non-blocking disconnect, so Connectivity’s settings apply. 

License

GPL-3.0-or-later. Based on Krypton (LGPL-3.0), VMP (MIT) and Packet Fixer (MIT), and bundles velocity-native (GPL-3.0) for native compression.

常见问题

RatNetworking 支持哪些 Minecraft 版本?

RatNetworking 支持 Minecraft Java 版 1.20.1,可用的加载器:Forge。下载时注意选择和你游戏版本一致的文件。

RatNetworking 怎么安装?

先用 PCL2 或 HMCL 启动器安装对应版本的 Forge,再把下载的 .jar 文件放进游戏目录的 mods 文件夹,重新启动游戏即可。开启了版本隔离的,mods 文件夹在 versions/版本名 下面。

评论

登录后评论和评分

SolarBiscuit 的其他作品

查看全部 →