diff --git a/CraftBukkit-Patches/0104-Implement-Threaded-Bulk-Chunk-Compression.patch b/CraftBukkit-Patches/0104-Implement-Threaded-Bulk-Chunk-Compression.patch index 05ab06a9d1..515083ada3 100644 --- a/CraftBukkit-Patches/0104-Implement-Threaded-Bulk-Chunk-Compression.patch +++ b/CraftBukkit-Patches/0104-Implement-Threaded-Bulk-Chunk-Compression.patch @@ -1,4 +1,4 @@ -From 47f5faa5d3e3a74e8b85100c244001e7d1b8df0f Mon Sep 17 00:00:00 2001 +From d44a0d5bd59d7bd85e365791a64fd49abc6d8dcc Mon Sep 17 00:00:00 2001 From: md_5 Date: Tue, 28 Jan 2014 20:32:07 +1100 Subject: [PATCH] Implement Threaded Bulk Chunk Compression @@ -27,31 +27,61 @@ index 30bf8a7..178a4ba 100644 packetdataserializer.writeInt(this.size); packetdataserializer.writeBoolean(this.h); diff --git a/src/main/java/net/minecraft/server/ServerConnectionChannel.java b/src/main/java/net/minecraft/server/ServerConnectionChannel.java -index fb95be4..b18944e 100644 +index fb95be4..2875c94 100644 --- a/src/main/java/net/minecraft/server/ServerConnectionChannel.java +++ b/src/main/java/net/minecraft/server/ServerConnectionChannel.java -@@ -27,7 +27,8 @@ class ServerConnectionChannel extends ChannelInitializer { +@@ -1,15 +1,26 @@ + package net.minecraft.server; + ++import com.google.common.util.concurrent.ThreadFactoryBuilder; // Spigot + import net.minecraft.util.io.netty.channel.Channel; + import net.minecraft.util.io.netty.channel.ChannelException; + import net.minecraft.util.io.netty.channel.ChannelInitializer; + import net.minecraft.util.io.netty.channel.ChannelOption; + import net.minecraft.util.io.netty.handler.timeout.ReadTimeoutHandler; ++// Spigot Start ++import net.minecraft.util.io.netty.util.concurrent.DefaultEventExecutorGroup; ++import net.minecraft.util.io.netty.util.concurrent.EventExecutorGroup; ++import org.spigotmc.ChunkCompressor; ++import org.spigotmc.SpigotConfig; ++// Spigot End + + class ServerConnectionChannel extends ChannelInitializer { + + final ServerConnection a; +- ++ // Spigot Start ++ private static final EventExecutorGroup threadPool = new DefaultEventExecutorGroup( SpigotConfig.compressionThreads, new ThreadFactoryBuilder().setNameFormat( "Chunk Compressor #%d" ).setDaemon( true ).build() ); ++ private static final ChunkCompressor chunkCompressor = new ChunkCompressor(); ++ // Spigot End ++ + ServerConnectionChannel(ServerConnection serverconnection) { + this.a = serverconnection; + } +@@ -27,7 +38,8 @@ class ServerConnectionChannel extends ChannelInitializer { ; } - channel.pipeline().addLast("timeout", new ReadTimeoutHandler(30)).addLast("legacy_query", new LegacyPingHandler(this.a)).addLast("splitter", new PacketSplitter()).addLast("decoder", new PacketDecoder()).addLast("prepender", new PacketPrepender()).addLast("encoder", new PacketEncoder()); + channel.pipeline().addLast("timeout", new ReadTimeoutHandler(30)).addLast("legacy_query", new LegacyPingHandler(this.a)).addLast("splitter", new PacketSplitter()).addLast("decoder", new PacketDecoder()).addLast("prepender", new PacketPrepender()).addLast("encoder", new PacketEncoder()) -+ .addLast( new net.minecraft.util.io.netty.util.concurrent.DefaultEventExecutorGroup( org.spigotmc.SpigotConfig.compressionThreads, new com.google.common.util.concurrent.ThreadFactoryBuilder().setNameFormat( "Chunk Compressor #%d" ).setDaemon( true ).build() ), "compressor", new org.spigotmc.ChunkCompressor() ); // Spigot ++ .addLast( threadPool, "compressor", chunkCompressor ); // Spigot NetworkManager networkmanager = new NetworkManager(false); ServerConnection.a(this.a).add(networkmanager); diff --git a/src/main/java/org/spigotmc/ChunkCompressor.java b/src/main/java/org/spigotmc/ChunkCompressor.java new file mode 100644 -index 0000000..71fcea6 +index 0000000..50485d0 --- /dev/null +++ b/src/main/java/org/spigotmc/ChunkCompressor.java @@ -0,0 +1,21 @@ +package org.spigotmc; + ++import net.minecraft.util.io.netty.channel.ChannelHandler; +import net.minecraft.util.io.netty.channel.ChannelHandlerContext; +import net.minecraft.util.io.netty.channel.ChannelOutboundHandlerAdapter; +import net.minecraft.util.io.netty.channel.ChannelPromise; + ++@ChannelHandler.Sharable +public class ChunkCompressor extends ChannelOutboundHandlerAdapter +{ + @@ -60,9 +90,7 @@ index 0000000..71fcea6 + { + if ( msg instanceof Compressible ) + { -+ long start = System.currentTimeMillis(); + ( (Compressible) msg ).compress(); // TODO: Caching! -+ System.out.println( "Took: " + ( System.currentTimeMillis() - start ) + "ms to compress" ); + } + super.write( ctx, msg, promise ); + }