out of DirectMemory
See original GitHub issueExpected behavior
netty httpServer Accept the request DirectMemory
Actual behavior
DirectMemory distribution of the, netty httpServer not Accept the request IO thread and Accept thread waiting for the network events ` at sun.nio.ch.EPollArrayWrapper.epollWait(Native Method) at sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:269)
`
Steps to reproduce
The server 8cpu memory 8G
Each request 10 bytes, 20 bytes response, Every 5000 TPS
nohup java -server -Xms2G -Xmx2G -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:MaxDirectMemorySize=2G
Minimal yet complete reproducer code (or URL to code)
` public void start( ) throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup( 2 ); EventLoopGroup workerGroup = new NioEventLoopGroup( 8 ); try { ServerBootstrap b = new ServerBootstrap( ); b.group( bossGroup , workerGroup ).channel( NioServerSocketChannel.class ) .option( ChannelOption.SO_BACKLOG , 1024 ) .childOption( ChannelOption.SO_KEEPALIVE , true ) .childHandler( new ChannelInitializer< SocketChannel >( ) {
@Override
protected void initChannel( SocketChannel ch ) throws Exception {
ChannelPipeline p = ch.pipeline( );
p.addLast( new HttpServerCodec( ) );
p.addLast( new HttpObjectAggregator( 65536 ) );
p.addLast( new ChunkedWriteHandler( ) );
p.addLast( new HttpServerExpectContinueHandler( ) );
p.addLast( new NettyHttpInboundHandle( httpPerfrom ) );
}
} );
ChannelFuture f = b.bind( port ).sync( );
f.channel( ).closeFuture( ).sync( );
} finally {
bossGroup.shutdownGracefully( );
workerGroup.shutdownGracefully( );
}
}
@Slf4j
public class NettyHttpInboundHandle extends ChannelInboundHandlerAdapter {
private static final AsciiString CONTENT_TYPE = new AsciiString("Content-Type");
private static final AsciiString CONTENT_LENGTH = new AsciiString("Content-Length");
private static final AsciiString CONNECTION = new AsciiString("Connection");
private static final AsciiString KEEP_ALIVE = new AsciiString("keep-alive");
HttpPerfrom< Object > httpPerfrom;
public NettyHttpInboundHandle(HttpPerfrom< Object > httpPerfrom ) {
this.httpPerfrom = httpPerfrom;
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) {
ctx.flush();
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
FullHttpRequest req = null;
ByteBuf by = null;
try{
if (msg instanceof FullHttpMessage) {
req = (FullHttpRequest) msg;
String uri = req.uri( );
Object sequenceInfo = null;
if(req.method( ) == HttpMethod.GET){
}else{
by = req.content( );
by.resetReaderIndex( );
byte[] byArray = new byte[by.writerIndex( )];
by.readBytes( byArray );
sequenceInfo = JSON.parseObject( byArray , httpPerfrom.getSerializationClass( ) );
}
String requestMappingMethods = uri.substring( uri.lastIndexOf( '/' )+1, uri.length( ));
sequenceInfo = httpPerfrom.perform(requestMappingMethods , sequenceInfo );
BasicResponse basicResponse= new BasicResponse().setReturnCode( 1000 ).setDataInfo( sequenceInfo );
boolean keepAlive = HttpUtil.isKeepAlive(req);
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(JSON.toJSONBytes( basicResponse )));
response.headers().set(CONTENT_TYPE, "application/json");
response.headers().setInt(CONTENT_LENGTH, response.content().readableBytes());
if(log.isDebugEnabled( )){
log.debug( response.toString( ) );
}
//!keepAlive
if (!keepAlive) {
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
} else {
response.headers().set(CONNECTION, KEEP_ALIVE);
ctx.writeAndFlush(response);
}
}
}catch(Exception e){
log.error( e.getMessage( ) , e );
}finally{
ReferenceCountUtil.release(msg);
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
cause.printStackTrace();
ctx.close();
}
} `
Netty version
4.1.17
JVM version (e.g. java -version
)
java version “1.8.0_111” Java™ SE Runtime Environment (build 1.8.0_111-b14) Java HotSpot™ 64-Bit Server VM (build 25.111-b14, mixed mode)
OS version (e.g. uname -a
)
Linux localhost.localdomain 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (2 by maintainers)
Top GitHub Comments
Ok, no problem.English is very bad, cannot be described in English.Will use the code and flow chart.Now work, life is a little busy.Didn’t have time next week.I’m very sorry
Can you add the details what the problem was and how you solved it?