mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Swen Moczarski <m...@swenmoc.de>
Subject Re: OutOfMemory when using ReadThrottleFilter
Date Tue, 30 Jan 2007 22:44:30 GMT
Hi Trustin,

thanks a lot for your response.

Trustin Lee wrote:
> Hi Swen,
> On 1/4/07, Swen Moczarski <mail@swenmoc.de> wrote:
>> Hi, I have done some performance tests. A client is sending a lot of 
>> small
>> messages over a connection to a server. In
>> spite of the read-throttle-filter (
>> org.apache.mina.filter.ReadThrottleFilterBuilder) the server will be
>> overloaded and I
>> get out-of-memory exceptions.
>> Before the message will be forwarded to the ExecutionFilter, the
>> ReadThrottleFilter makes use of ByteBuffer.remaining()
>> for increasing the calculated size of the connection buffer. But after
>> passing the ExecutionFilter the method
>> ByteBuffer.capacity() is used to decrease the size. Is that behaviour
>> intended?
>> When I'm patching the ReadThrottleFilterBuilder to use 
>> ByteBuffer.capacity()
>> for both cases the performance test works
>> absolutely fine, there are no longer out-of-memory exceptions. BTW, in 
>> the
>> SVN-history I have seen that the first
>> version uses ByteBuffer.capacity() for both cases.
> It seems like there was a mistake.  Could you try to change both capacity()
> calls to remaining()?  I think it's a correct fix than using capacity().

When I'm using the remaining() calls, I still get an out-of-memory error. But when I'm using
capacity() it looks ok.
Maybe, this becomes only a problem when a lot of small messages are stored in bigger ByteBuffers.
But I think it would
be safer to prevent overloading when the ReadThrottleFilter tracks the memory allocated by
the ByteBuffers (capacity())
instead of the received bytes. WDYT?

Here is my simple stess-test:

public class Test {

    private final static int PORT = 8056;

    public static void main(String[] args) throws Exception {
       IoHandler handler = new IoHandlerAdapter() {

          public void exceptionCaught(IoSession session, Throwable cause) throws Exception
          public void sessionCreated(IoSession session) throws Exception {
             ReadThrottleFilterBuilder throttleFilter = new ReadThrottleFilterBuilder();
       SocketAcceptor acceptor = new SocketAcceptor();
       acceptor.bind(new InetSocketAddress(PORT), handler);

       Socket socket = new Socket("localhost", PORT);
       Writer writer = new OutputStreamWriter(socket.getOutputStream());

       while (true) {

I have tried the test with version 1.0.1 and the current trunk (with the current trunk it
takes longer until the memory 
error occures).
Should I attach the test to https://issues.apache.org/jira/browse/DIRMINA-338 and reopen the


View raw message