mirror of
https://github.com/Minestom/Minestom.git
synced 2024-10-27 22:10:21 +01:00
Small optimizations to netty.
This commit is contained in:
parent
4e11b16ee1
commit
926c02b7f5
@ -606,7 +606,7 @@ public final class MinecraftServer {
|
|||||||
*
|
*
|
||||||
* @return should process netty errors
|
* @return should process netty errors
|
||||||
*/
|
*/
|
||||||
public static boolean processingNettyErrors() {
|
public static boolean shouldProcessNettyErrors() {
|
||||||
return processNettyErrors;
|
return processNettyErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.minestom.server.network.netty;
|
package net.minestom.server.network.netty;
|
||||||
|
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
|
import io.netty.buffer.ByteBufAllocator;
|
||||||
import io.netty.channel.*;
|
import io.netty.channel.*;
|
||||||
import io.netty.channel.epoll.Epoll;
|
import io.netty.channel.epoll.Epoll;
|
||||||
import io.netty.channel.epoll.EpollEventLoopGroup;
|
import io.netty.channel.epoll.EpollEventLoopGroup;
|
||||||
@ -100,6 +101,7 @@ public final class NettyServer {
|
|||||||
ChannelConfig config = ch.config();
|
ChannelConfig config = ch.config();
|
||||||
config.setOption(ChannelOption.TCP_NODELAY, true);
|
config.setOption(ChannelOption.TCP_NODELAY, true);
|
||||||
config.setOption(ChannelOption.SO_SNDBUF, 1_000_000);
|
config.setOption(ChannelOption.SO_SNDBUF, 1_000_000);
|
||||||
|
config.setAllocator(ByteBufAllocator.DEFAULT);
|
||||||
|
|
||||||
ChannelPipeline pipeline = ch.pipeline();
|
ChannelPipeline pipeline = ch.pipeline();
|
||||||
|
|
||||||
|
@ -65,8 +65,10 @@ public class ClientChannel extends SimpleChannelInboundHandler<InboundPacket> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||||
LOGGER.info(cause.getMessage());
|
if (MinecraftServer.shouldProcessNettyErrors()) {
|
||||||
cause.printStackTrace();
|
LOGGER.info(cause.getMessage());
|
||||||
|
cause.printStackTrace();
|
||||||
|
}
|
||||||
ctx.close();
|
ctx.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,9 +10,22 @@ public class GroupedPacketHandler extends MessageToByteEncoder<FramedPacket> {
|
|||||||
@Override
|
@Override
|
||||||
protected void encode(ChannelHandlerContext ctx, FramedPacket msg, ByteBuf out) {
|
protected void encode(ChannelHandlerContext ctx, FramedPacket msg, ByteBuf out) {
|
||||||
final ByteBuf packet = msg.body;
|
final ByteBuf packet = msg.body;
|
||||||
out.writeBytes(packet.duplicate());
|
|
||||||
|
out.setBytes(0, packet, 0, packet.writerIndex());
|
||||||
|
out.writerIndex(packet.writerIndex());
|
||||||
|
|
||||||
if (msg.releaseBuf) {
|
if (msg.releaseBuf) {
|
||||||
packet.release();
|
packet.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ByteBuf allocateBuffer(ChannelHandlerContext ctx, FramedPacket msg, boolean preferDirect) {
|
||||||
|
if (preferDirect) {
|
||||||
|
return ctx.alloc().ioBuffer(msg.body.writerIndex());
|
||||||
|
} else {
|
||||||
|
return ctx.alloc().heapBuffer(msg.body.writerIndex());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ public class NettyPlayerConnection extends PlayerConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void write(Object message) {
|
public void write(Object message) {
|
||||||
if (MinecraftServer.processingNettyErrors())
|
if (MinecraftServer.shouldProcessNettyErrors())
|
||||||
channel.write(message).addListener(future -> {
|
channel.write(message).addListener(future -> {
|
||||||
if (!future.isSuccess()) {
|
if (!future.isSuccess()) {
|
||||||
future.cause().printStackTrace();
|
future.cause().printStackTrace();
|
||||||
@ -154,7 +154,7 @@ public class NettyPlayerConnection extends PlayerConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void writeAndFlush(Object message) {
|
public void writeAndFlush(Object message) {
|
||||||
if (MinecraftServer.processingNettyErrors())
|
if (MinecraftServer.shouldProcessNettyErrors())
|
||||||
channel.writeAndFlush(message).addListener(future -> {
|
channel.writeAndFlush(message).addListener(future -> {
|
||||||
if (!future.isSuccess()) {
|
if (!future.isSuccess()) {
|
||||||
future.cause().printStackTrace();
|
future.cause().printStackTrace();
|
||||||
|
@ -49,11 +49,11 @@ public class PlayerInit {
|
|||||||
instanceContainer.setChunkGenerator(noiseTestGenerator);
|
instanceContainer.setChunkGenerator(noiseTestGenerator);
|
||||||
|
|
||||||
// Load some chunks beforehand
|
// Load some chunks beforehand
|
||||||
final int loopStart = -32;
|
final int loopStart = -16;
|
||||||
final int loopEnd = 32;
|
final int loopEnd = 16;
|
||||||
for (int x = loopStart; x < loopEnd; x++)
|
for (int x = loopStart; x < loopEnd; x++)
|
||||||
for (int z = loopStart; z < loopEnd; z++) {
|
for (int z = loopStart; z < loopEnd; z++) {
|
||||||
instanceContainer.loadChunk(x, z);
|
//instanceContainer.loadChunk(x, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
inventory = new Inventory(InventoryType.CHEST_1_ROW, "Test inventory");
|
inventory = new Inventory(InventoryType.CHEST_1_ROW, "Test inventory");
|
||||||
@ -172,9 +172,9 @@ public class PlayerInit {
|
|||||||
player.addEventCallback(PlayerLoginEvent.class, event -> {
|
player.addEventCallback(PlayerLoginEvent.class, event -> {
|
||||||
|
|
||||||
event.setSpawningInstance(instanceContainer);
|
event.setSpawningInstance(instanceContainer);
|
||||||
int x = Math.abs(ThreadLocalRandom.current().nextInt()) % 1000 + 500;
|
int x = Math.abs(ThreadLocalRandom.current().nextInt()) % 2000 - 1000;
|
||||||
int z = Math.abs(ThreadLocalRandom.current().nextInt()) % 1000 + 500;
|
int z = Math.abs(ThreadLocalRandom.current().nextInt()) % 2000 - 1000;
|
||||||
player.setRespawnPoint(new Position(0, 70f, 0));
|
player.setRespawnPoint(new Position(x, 70f, z));
|
||||||
|
|
||||||
/*player.getInventory().addInventoryCondition((p, slot, clickType, inventoryConditionResult) -> {
|
/*player.getInventory().addInventoryCondition((p, slot, clickType, inventoryConditionResult) -> {
|
||||||
if (slot == -999)
|
if (slot == -999)
|
||||||
|
Loading…
Reference in New Issue
Block a user