Java的Grizzly为缓冲区占用了大量内存?

时间:2011-03-14 17:50:08

标签: java memory-management grizzly

作为减少应用程序内存负载的努力的一部分,我们收集了一份hprof报告。该报告包括以下内容:

          percent          live          alloc'ed  stack class
 rank   self  accum     bytes objs     bytes  objs trace name
    1  9.42%  9.42%  57414792  219  57414792   219 373093 byte[]
    2  6.45% 15.87%  39328800  300  39328800   300 367689 byte[]
    8  1.74% 30.92%  10618776   81  39328800   300 367958 byte[]

相应的痕迹是:

TRACE 373093:
    java.nio.HeapByteBuffer.(HeapByteBuffer.java:39)
    java.nio.ByteBuffer.allocate(ByteBuffer.java:312)
    com.sun.enterprise.web.connector.grizzly.SocketChannelOutputBuffer.realWriteBytes(SocketChannelOutputBuffer.java:153)
    com.sun.enterprise.web.connector.grizzly.SocketChannelOutputBuffer$NIOOutputStream.write(SocketChannelOutputBuffer.java:240)

TRACE 367689:
    java.nio.HeapByteBuffer.(HeapByteBuffer.java:39)
    java.nio.ByteBuffer.allocate(ByteBuffer.java:312)
    com.sun.enterprise.web.connector.grizzly.SocketChannelOutputBuffer.(SocketChannelOutputBuffer.java:100)
    com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.initialize(DefaultProcessorTask.java:436)

TRACE 367958:
    java.nio.HeapByteBuffer.(HeapByteBuffer.java:39)
    java.nio.ByteBuffer.allocate(ByteBuffer.java:312)
    com.sun.enterprise.web.connector.grizzly.SocketChannelOutputBuffer.(SocketChannelOutputBuffer.java:100)
    com.sun.enterprise.web.connector.grizzly.ssl.SSLOutputBuffer.(SSLOutputBuffer.java:59)

任何人都知道Grizzly为何如此......呃......饿了?

谢谢!

1 个答案:

答案 0 :(得分:0)

这些缓冲区用于从通道读/写。读缓冲区默认为8192字节。有一个输出缓冲区,其默认大小为16倍。这些尺寸可根据您的需求进行调整,但多年来一般都是相当不错的默认值。