最近看netty发现发送并发请求数总是多于接受到的请求数而且数字不固定,请大神帮忙? 400 报错
看了一下网上的例子自己做了一下然后使用jmeter 测试了一下发现测试总是不对查资料有说系统问题的有说是java虚拟机内存小的设置以后问题也没有得到解决。
EchoServer.java
package com.gmbsh.Server; import io.netty.bootstrap.ServerBootstrap; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.codec.DelimiterBasedFrameDecoder; import io.netty.handler.codec.string.StringDecoder; public class EchoServer { public void bind(int port) throws Exception{ EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup wordGroup = new NioEventLoopGroup(); try { ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(bossGroup,wordGroup) .channel(NioServerSocketChannel.class) // .option(ChannelOption.SO_BACKLOG, 100) // .childOption(ChannelOption.SO_KEEPALIVE, true) // .childOption(ChannelOption.SO_REUSEADDR, true) // .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel arg0) throws Exception { // TODO Auto-generated method stub ByteBuf bytebuf = Unpooled.copiedBuffer("$_".getBytes());//定义一个分隔符进行区分信息的条数 arg0.pipeline().addLast(new DelimiterBasedFrameDecoder(1024, bytebuf));//加载格式识别信息 // arg0.pipeline().addLast("readTimeoutHanlder",new ReadTimeoutHandler(50));//加载格式识别信息 arg0.pipeline().addLast(new StringDecoder());//自动将信息转换成字符串 arg0.pipeline().addLast(new EchoServerHandler());//自定义解码 } }); ChannelFuture f = bootstrap.bind(port).sync();//绑定端口同步等待成功 f.channel().closeFuture().sync();//等待服务端口关闭 } finally{ bossGroup.shutdownGracefully(); wordGroup.shutdownGracefully(); } } public static void main(String[] args) { // TODO Auto-generated method stub int port = 9000; try { new EchoServer().bind(port); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
package com.gmbsh.Server; import java.net.InetSocketAddress; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelHandlerAdapter; import io.netty.channel.ChannelHandlerContext; public class EchoServerHandler extends ChannelHandlerAdapter{ static int counter=1; static int contentco=1; static int closeCount = 1; @Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { // TODO Auto-generated method stub System.out.println("链接数量:"+ counter++); } @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { System.out.println("收到数据数量:"+ contentco++); // TODO Auto-generated method stub } @Override public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { // TODO Auto-generated method stub System.out.println("ChannelHandlerContext flush"); ctx.flush(); } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { // TODO Auto-generated method stub System.out.println("ChannelHandlerContext is close:"+ ++closeCount); cause.printStackTrace(); ctx.close();//发生异常关闭链路 } }
你把数据贴出来啊
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。