Independent socket send & receive buffer size

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-09-04 16:43:45 +02:00
parent 96bfc4c6fa
commit f717279adc
3 changed files with 9 additions and 7 deletions

View File

@ -19,7 +19,9 @@ public final class Server {
public static final int WORKER_COUNT = Integer.getInteger("minestom.workers",
Runtime.getRuntime().availableProcessors());
public static final int MAX_PACKET_SIZE = 2_097_151; // 3 bytes var-int
public static final int SOCKET_BUFFER_SIZE = Integer.getInteger("minestom.buffer-size", MAX_PACKET_SIZE);
public static final int SOCKET_SEND_BUFFER_SIZE = Integer.getInteger("minestom.send-buffer-size", MAX_PACKET_SIZE);
public static final int SOCKET_RECEIVE_BUFFER_SIZE = Integer.getInteger("minestom.receive-buffer-size", 32_767);
public static final boolean NO_DELAY = true;
private volatile boolean stop;
@ -52,7 +54,7 @@ public final class Server {
serverSocket.bind(address);
serverSocket.configureBlocking(false);
serverSocket.register(selector, SelectionKey.OP_ACCEPT);
serverSocket.socket().setReceiveBufferSize(SOCKET_BUFFER_SIZE);
serverSocket.socket();
LOGGER.info("Server starting, wait for connections");
new Thread(() -> {
while (!stop) {

View File

@ -81,8 +81,8 @@ public final class Worker extends Thread {
channel.configureBlocking(false);
channel.register(selector, SelectionKey.OP_READ);
var socket = channel.socket();
socket.setSendBufferSize(Server.SOCKET_BUFFER_SIZE);
socket.setReceiveBufferSize(Server.SOCKET_BUFFER_SIZE);
socket.setSendBufferSize(Server.SOCKET_SEND_BUFFER_SIZE);
socket.setReceiveBufferSize(Server.SOCKET_RECEIVE_BUFFER_SIZE);
socket.setTcpNoDelay(Server.NO_DELAY);
socket.setSoTimeout(30 * 1000); // 30 seconds
this.selector.wakeup();

View File

@ -36,8 +36,8 @@ import java.util.zip.Deflater;
public final class PacketUtils {
private static final PacketListenerManager PACKET_LISTENER_MANAGER = MinecraftServer.getPacketListenerManager();
private static final ThreadLocal<Deflater> COMPRESSOR = ThreadLocal.withInitial(Deflater::new);
private static final LocalCache PACKET_BUFFER = LocalCache.get("packet-buffer", Server.SOCKET_BUFFER_SIZE);
private static final LocalCache COMPRESSION_CACHE = LocalCache.get("compression-buffer", Server.SOCKET_BUFFER_SIZE);
private static final LocalCache PACKET_BUFFER = LocalCache.get("packet-buffer", Server.MAX_PACKET_SIZE);
private static final LocalCache COMPRESSION_CACHE = LocalCache.get("compression-buffer", Server.MAX_PACKET_SIZE);
private static final Object VIEWABLE_PACKET_LOCK = new Object();
private static final Map<Viewable, ViewableStorage> VIEWABLE_STORAGE_MAP = new WeakHashMap<>();
@ -274,7 +274,7 @@ public final class PacketUtils {
private static final class ViewableStorage {
private final Viewable viewable;
private final Map<PlayerConnection, List<IntIntPair>> entityIdMap = new HashMap<>();
private final BinaryBuffer buffer = BinaryBuffer.ofSize(Server.SOCKET_BUFFER_SIZE);
private final BinaryBuffer buffer = BinaryBuffer.ofSize(Server.SOCKET_SEND_BUFFER_SIZE);
private ViewableStorage(Viewable viewable) {
this.viewable = viewable;