第12章 Netty高性能并发调优

展开阅读全文

netty并发快速响应

12-08

现业务是接收http post请求并必须在15毫秒内返回, 我的实现思路: 1:首先netty接收完数据,验证contenttype等header信息再将post的数据protobuf反序列化成对象(必须), 2:然后将对象传入到某个方法, 3:该方法必须定时10毫秒完成,如果没有完成就直接返回null和请求的header 具体实现是: netty 主线程接收完数据转成request对象传到1号线程池里面,1号线程池验证对象和反序列化,传给2号线程池并wait10毫秒然后直接得到2号线程池的返回对象,有就有,没有就是null,然后再channel返回。2号线程池主要处理业务生成对象供1号线程池调用。 Linux version 2.6.32-431.11.25.el6.ucloud.x86_64 gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) Mem: 16G CPU(s): 8 sysctl.conf: net.ipv4.ip_forward = 0 net.ipv4.conf.default.rp_filter = 1 net.ipv4.conf.default.accept_source_route = 0 kernel.core_uses_pid = 1 net.ipv4.tcp_syncookies = 1 net.bridge.bridge-nf-call-ip6tables = 0 net.bridge.bridge-nf-call-iptables = 0 net.bridge.bridge-nf-call-arptables = 0 kernel.msgmnb = 65536 kernel.msgmax = 65536 kernel.shmmax = 68719476736 kernel.shmall = 4294967296 net.netfilter.nf_conntrack_max = 1000000 kernel.unknown_nmi_panic = 0 kernel.sysrq = 1 fs.file-max = 1000000 vm.swappiness = 10 fs.inotify.max_user_watches = 10000000 net.core.wmem_max = 67108864 net.core.rmem_max = 67108864 net.ipv4.conf.all.send_redirects = 0 net.ipv4.conf.default.send_redirects = 0 net.ipv4.conf.all.secure_redirects = 0 net.ipv4.conf.default.secure_redirects = 0 net.ipv4.conf.all.accept_redirects = 0 net.ipv4.conf.default.accept_redirects = 0 fs.notify.max_queued_events = 3276792 net.ipv4.neigh.default.gc_thresh1 = 2048 net.ipv4.neigh.default.gc_thresh2 = 4096 net.ipv4.neigh.default.gc_thresh3 = 8192 net.ipv6.conf.all.disable_ipv6 = 1 ############## net.ipv4.tcp_max_tw_buckets = 6000 net.ipv4.ip_local_port_range = 1024 65000 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_syncookies = 1 net.core.somaxconn = 262144 net.core.netdev_max_backlog = 262144 net.ipv4.tcp_max_orphans = 262144 net.ipv4.tcp_max_syn_backlog = 262144 net.ipv4.tcp_synack_retries = 1 net.ipv4.tcp_syn_retries = 1 net.ipv4.tcp_fin_timeout = 1 net.ipv4.tcp_keepalive_time = 30 #### net.ipv4.tcp_rmem = 4096 87380 67108864 net.ipv4.tcp_wmem = 4096 65536 67108864 net.core.netdev_max_backlog = 250000 net.ipv4.tcp_mtu_probing=1 net.ipv4.tcp_congestion_control=hybla jdk 1.8 现用tomcat同样配置执行是4000qps,超时率为4%; netty是1000qps,超时率为5%; netty: cpu使用10%左右 java -Xms10g -Xmx10g -XX:NewSize=7098m -XX:SurvivorRatio=16 -XX:+DisableExplicitGC -XX:+CMSScavengeBeforeRemark -XX:+UseConcMarkSweepGC -XX:+UParNewGC S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT 403776.0 403776.0 25637.9 0.0 6460800.0 5273672.7 3217408.0 0.0 27928.0 25782.3 3352.0 2883.6 2 0.042 2 1.411 1.453 netstat -apn | grep TIME_WAIT | wl -h 5733 现需要qps达到1w以上。希望收到你的回答或demo。谢谢 ps: akka ,但觉得个人写future和他差不多吧。 问答

netty测试高并发的问题

05-10

先上代码,大家帮忙看下。 服务端: package Server; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioServerSocketChannel; public class HelloServer { private static final int port = 7878; public void start() throws InterruptedException { EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workGroup = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workGroup); b.channel(NioServerSocketChannel.class); b.option(ChannelOption.SO_BACKLOG, 1024); b.childHandler(new SCCHandler()); // 绑定端口 ChannelFuture f = b.bind(port).sync(); // 等待服务端监听端口关闭 f.channel().closeFuture().sync(); } finally { // 优雅的退出 bossGroup.shutdownGracefully(); workGroup.shutdownGracefully(); } } public static void main(String[] args) { try { new HelloServer().start(); } catch (InterruptedException e) { e.printStackTrace(); } } } 客户端测试高并发的DEMO: package Client; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioSocketChannel; public class HelloClient { public static void main(String[] args) throws Exception { ScheduledExecutorService scheduledThreadPool = Executors .newScheduledThreadPool(3000); for (int i = 0; i < 3000; i++) { scheduledThreadPool.schedule(new Runnable() { public void run() { try { System.out.println("go"); new HelloClient("192.168.2.88", 7878).start(); } catch (Exception e) { System.out.println("压力测试失败->" + e.toString()); } } }, 200, TimeUnit.MILLISECONDS); } System.out.println("压力测试提交完成"); } private final String host; private final int port; public HelloClient(String host, int port) { this.host = host; this.port = port; } public void start() throws Exception { System.out.println("链接服务器开始"); EventLoopGroup group = new NioEventLoopGroup(); try { Bootstrap b = new Bootstrap(); b.group(group); b.channel(NioSocketChannel.class); // b.remoteAddress(new InetSocketAddress(host, port)); b.option(ChannelOption.TCP_NODELAY, true); b.handler(new ClientCCHandler()); // ChannelFuture f = b.connect().sync(); ChannelFuture f = b.connect(host, port); f.channel().closeFuture().sync(); } finally { group.shutdownGracefully(); } } } 到5000以上就就会出现无法连接的状态了……求解!! 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览