首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

Netty内存储器泄露

2012-07-23 
Netty内存泄露转于自己在公司的Blog:http://pt.alibaba-inc.com/wp/experience_1348/netty-nio-direct-mem

Netty内存泄露
转于自己在公司的Blog:
http://pt.alibaba-inc.com/wp/experience_1348/netty-nio-direct-memory-leak.html

在测试中发现,当不停的开关Netty的NioClientSocketChannelFactory(比如大量连接失败重连等情况下),存在Direct Memory泄露。
测试代码:

for (int i = 0; i < Integer.MAX_VALUE; i ++) {    ChannelFactory channelFactory = new NioClientSocketChannelFactory(            Executors.newCachedThreadPool(), Executors.newCachedThreadPool());    Bootstrap bootstrap = new ClientBootstrap(channelFactory);    bootstrap.setPipelineFactory(new ChannelPipelineFactory() { ... });    ChannelFuture future = bootstrap.connect(serverAddress);    future.await(); // or future.addListener(new ChannelFutureListener() { ... });     Channel channel = future.getChannel();    channel.close();    // FIXME NioClientSocketChannelFactory direct buffer memory leak    channelFactory.releaseExternalResources(); // or bootstrap.releaseExternalResources();}

抛出的异常信息:
Caused by: java.lang.OutOfMemoryError: Direct buffer memoryat java.nio.Bits.reserveMemory(Bits.java:633)at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:95)at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:288)at org.jboss.netty.channel.socket.nio.SocketSendBufferPool$Preallocation.<init>(SocketSendBufferPool.java:159)at org.jboss.netty.channel.socket.nio.SocketSendBufferPool.<init>(SocketSendBufferPool.java:46)at org.jboss.netty.channel.socket.nio.NioWorker.<init>(NioWorker.java:84)at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.<init>(NioClientSocketPipelineSink.java:74)at org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory.<init>(NioClientSocketChannelFactory.java:135)


询问了Netty的作者Trustin Lee:
private static final NioClientSocketChannelFactory channelFactory = ...;

热点排行