3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-12-24 15:20:35 +01:00

Use Netty thread factory to take advantage of FastThreadLocal

This should reduce CPU usage slightly.
Dieser Commit ist enthalten in:
Andrew Steinborn 2019-07-02 02:19:52 -04:00
Ursprung c0becce276
Commit dab9c9a382
2 geänderte Dateien mit 9 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -4,6 +4,7 @@ import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.util.concurrent.FastThreadLocal;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import javax.crypto.Cipher; import javax.crypto.Cipher;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
@ -24,8 +25,12 @@ public class JavaVelocityCipher implements VelocityCipher {
} }
}; };
private static final int INITIAL_BUFFER_SIZE = 1024 * 8; private static final int INITIAL_BUFFER_SIZE = 1024 * 8;
private static final ThreadLocal<byte[]> inBufLocal = ThreadLocal.withInitial( private static final FastThreadLocal<byte[]> inBufLocal = new FastThreadLocal<byte[]>() {
() -> new byte[INITIAL_BUFFER_SIZE]); @Override
protected byte[] initialValue() {
return new byte[INITIAL_BUFFER_SIZE];
}
};
private final Cipher cipher; private final Cipher cipher;
private boolean disposed = false; private boolean disposed = false;

Datei anzeigen

@ -19,6 +19,7 @@ import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioDatagramChannel; import io.netty.channel.socket.nio.NioDatagramChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.util.concurrent.DefaultThreadFactory;
import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadFactory;
import java.util.function.BiFunction; import java.util.function.BiFunction;
@ -60,10 +61,7 @@ enum TransportType {
} }
private static ThreadFactory createThreadFactory(final String name, final Type type) { private static ThreadFactory createThreadFactory(final String name, final Type type) {
return new ThreadFactoryBuilder() return new DefaultThreadFactory("Netty " + name + ' ' + type.toString(), false);
.setNameFormat("Netty " + name + ' ' + type.toString() + " #%d")
.setDaemon(true)
.build();
} }
public static TransportType bestType() { public static TransportType bestType() {