0
回答
基于 netty SSL socket服务器,很慢,而且内存不释放
华为云实践训练营,热门技术免费实践!>>>   

请教大家一个问题,我最近写了一个基于netty的socket 服务器,现在发一个问题如果直接是socket不加ssl跑的很快,负载能力也很强。但是加了SSL就慢得如蜗牛,而且会有JVM崩溃,内存释放不了问题。请有此开发经验的同学指导一下。


系统环境:JAVA

java version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)

netty-4.1.0.CR3

运行参数:

-Xmx30720M -Xms30720M -Xss1M -XX:HeapDumpPath=/root/netty_srv_dir/dumps/ -XX:+HeapDumpOnOutOfMemoryError

----------------------------代码片段--------------------------------------------------


 SelfSignedCertificate ssc = new SelfSignedCertificate();
 SslContext sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()) .build();



private class DevChildChannelHandler extends ChannelInitializer<SocketChannel> {

        private final SslContext sslCtx;

        public DevChildChannelHandler(SslContext sslCtx) {
            this.sslCtx = sslCtx;
        }

        @Override
        protected void initChannel(SocketChannel arg0) throws Exception {
            ChannelPipeline pipeline = arg0.pipeline();
           // pipeline.addLast(sslCtx.newHandler(arg0.alloc()));  注释一行,就非常快
            ByteBuf delimiter = Unpooled.copiedBuffer("\r\n\r\n".getBytes());
            pipeline.addLast(new DelimiterBasedFrameDecoder(2048, delimiter));
            pipeline.addLast(new StringDecoder());
            pipeline.addLast(new DeviceHandler(dc));
        }
    }

举报
顶部