You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "Trustin Lee (JIRA)" <ji...@apache.org> on 2007/02/02 15:42:06 UTC

[jira] Updated: (DIRMINA-346) huge memory impact on receiving big packets (about 1MByte) due to CumulativeProtocolDecoder.storeRemainingInSession behaviour

     [ https://issues.apache.org/jira/browse/DIRMINA-346?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Trustin Lee updated DIRMINA-346:
--------------------------------

    Component/s:     (was: Core)
                 Filter

> huge memory impact on receiving big packets (about 1MByte) due to CumulativeProtocolDecoder.storeRemainingInSession behaviour
> -----------------------------------------------------------------------------------------------------------------------------
>
>                 Key: DIRMINA-346
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-346
>             Project: MINA
>          Issue Type: Improvement
>          Components: Filter
>    Affects Versions: 1.0.1
>         Environment: Windows XP Sp2
> Java 1.5.0_10
> Client / Server VM
>            Reporter: andrea sillari
>         Assigned To: Trustin Lee
>             Fix For: 1.0.2
>
>
> When receiving big TCP packets (about 1Mbyte or more) the current behavior of CumulativeProtocolDecoder.storeRemainingInSession implies that the session buffer is duplicated (and data copied) even if there is room for receiving another chunk of data from the socket (i.e. buf.limit() < buf.capacity()). In this situation there are spikes of memory consumption due to the fact that 1Mbyte / 8k (== session.getReadBufferSize())  = 128 buffers of increasing size are required for reading the entire packet.
> The attached patch prevents this, by explicitly checking if there is at least session.getReadBufferSize() space in the buffer, before requesting the allocation of a new buffer.
> The method session.getReadBufferSize() has been added to the IOSession Interface.
>     private void storeRemainingInSession(ByteBuffer buf, IoSession session)
>     {
>     	if (buf.limit() + session.getReadBufferSize() < buf.capacity()) // reuse the buffer
>     	{
>     		buf.position(buf.limit());
>     		buf.limit(buf.capacity());
>     		
>     		ByteBuffer sessBuff = (ByteBuffer) session.getAttribute(BUFFER);
>     		if (sessBuff != buf) // this should happens only the first time when sessBuff is null
>     		{
>     			session.setAttribute( BUFFER, buf );
>     			buf.acquire();
>     		}
>     	}
>     	else // old behavior
>     	{
> 	        ByteBuffer remainingBuf = ByteBuffer.allocate( buf.remaining() );
> 	        remainingBuf.setAutoExpand( true );
> 	        remainingBuf.put( buf );
> 	        session.setAttribute( BUFFER, remainingBuf );
>     	}
>     }    

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.