geforkt von Mirrors/Velocity
Use Netty thread factory to take advantage of FastThreadLocal
This should reduce CPU usage slightly.
Dieser Commit ist enthalten in:
Ursprung
c0becce276
Commit
dab9c9a382
@ -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;
|
||||||
|
@ -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() {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren