Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize long Link in performance Test of Netty NIO Framework

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail how to achieve long links in the performance test of the Netty NIO framework. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Pressure test preparation

Ulimit-n needs to be enlarged, otherwise the nio link will not be open.

Prepare 4 machines (1 netty server, 3 pressure measuring machines)

Using ab of apache as a pressure testing tool

Get to work.

Stress test code:

Package org.dueam.sample.netty;package org.dueam.sample.netty; import java.io.BufferedReader;import java.io.InputStreamReader;import java.net.InetSocketAddress;import java.util.HashMap;import java.util.Map;import java.util.Random;import java.util.concurrent.Executors; import org.jboss.netty.bootstrap.ServerBootstrap;import org.jboss.netty.buffer.ChannelBuffer;import org.jboss.netty.buffer.DynamicChannelBuffer;import org.jboss.netty.channel.Channel;import org.jboss.netty.channel.ChannelFactory Import org.jboss.netty.channel.ChannelHandlerContext;import org.jboss.netty.channel.ChannelPipeline;import org.jboss.netty.channel.ChannelStateEvent;import org.jboss.netty.channel.ExceptionEvent;import org.jboss.netty.channel.MessageEvent;import org.jboss.netty.channel.SimpleChannelHandler;import org.jboss.netty.channel.ChannelHandler.Sharable;import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory Public class ChatServer {public static void main (String [] args) throws Exception {if (args.length 70) {ChannelBuffer cb = new DynamicChannelBuffer; cb.writeBytes ("Hey! Someone is here to see you! ".getBytes (); s.write (cb);}} sleep (500) } catch (InterruptedException e) {}} final static Map channel = new HashMap (); static void log (String message) {System.out.println (message) @ Sharable static class ChatServerHandler extends SimpleChannelHandler {@ Override public void channelConnected (ChannelHandlerContext ctx, ChannelStateEvent e) {Channel ch = e.getChannel (); ChannelBuffer cb = new DynamicChannelBuffer (256); cb.writeBytes ("Hell! There you are! ".getBytes (); ch.write (cb); channel.put (e.getChannel (). GetId (), e.getChannel ()) } @ Override public void messageReceived (ChannelHandlerContext ctx, MessageEvent e) {} @ Override public void exceptionCaught (ChannelHandlerContext ctx, ExceptionEvent e) {e.getCause () .printStackTrace (); channel.remove (e.getChannel () .getId ()) Log ("remove channel by exception! Id: "+ e.getChannel () .getId (); e.getChannel () .close ();} @ Override public void channelDisconnected (ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {channel.remove (e.getChannel () .getId ()) Log ("remove channel by exception! Id: "+ e.getChannel () .getId ();}}

Pressure test mode:

# increase timeout and concurrency, and use keep-alive to keep the port. / ab-n 20000-c 20000-k-t 999999999-r http://192.168.216.30:9876/ stress test results

Memory depletion:

[root@cap216030] # free-k-t-s 10 color-original memory total used free shared buffers cachedMem: 4149076 189828 3959248 0 13196 95484 Muhammad + buffers/cache: 81148 4067928Swap: 2096472 2020 2096264Total: 6245548 190036 6055512-total used after chat server execution Free shared buffers cachedMem: 4149076 207236 3941840 0 13216 96244 4051300Swap: 97776 4051300Swap: 209647208 2096264Total: 6245548 207446038104-59471 after nio connection total used free shared buffers cachedMem: 4149076 474244 3674832 01332896132 + buffers/cache: 364784 3784292Swap: 2096472 2082096264Total: 6245548 474452 5771096

Conclusion:

Netty nio can easily open links to 6W, and each thread can damage about 5k of the system memory.

Follow-up pressure test scheme

Write Java client to do real-time two-way push of content

1000 threads per machine are used to simulate the client for stress testing.

On "Netty NIO framework performance test how to achieve long links" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report