question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

out of DirectMemory

See original GitHub issue

Expected 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:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
githublaohucommented, Dec 18, 2017

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

0reactions
normanmaurercommented, Dec 16, 2017

Can you add the details what the problem was and how you solved it?

Am 16.12.2017 um 17:12 schrieb githublaohu notifications@github.com:

Closed #7505.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix java.lang.OufOfMemoryError: Direct Buffer Memory
lang.OutOfMemoryError: Direct buffer memory is increasing JVM default memory limit. By default, JVM allows 64MB for direct buffer memory, you can increase it ......
Read more >
Troubleshooting OutOfMemoryError: Direct buffer memory
As we said, the Direct Buffers are allocated to native memory space outside of the JVM's established heap/perm gens. If this memory space ......
Read more >
Direct buffer memory - java - Stack Overflow
The actual memory buffers managed by DirectByteBuffer are not allocated in the heap. They are allocated using Unsafe.
Read more >
ERROR: java.lang.OutOfMemoryError: DIrect buffer memory
OOM error occurs when the DSE process is consuming too much heap. There are many root causes which can cause Java out of...
Read more >
[Known Issue] Out of direct memory error may occur during ...
If you read or write very large blocks from a large number of threads, the result is a memory error that looks like...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found