mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mark (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (DIRMINA-1061) When AbstractPollingIoProcessor read nothing, free the temporary buffer should be better
Date Sat, 17 Dec 2016 02:38:58 GMT

    [ https://issues.apache.org/jira/browse/DIRMINA-1061?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15756133#comment-15756133
] 

Mark commented on DIRMINA-1061:
-------------------------------

Thanks for your quickly and detail reply. (y)

But I think IoBuffer.free() is important to a IoBufferAllocator implementation. As you described,
we implemented a simple IoBufferAllocator, it can allocate a extension IoBuffer from pool,
in the extension IoBuffer, we override the free() method to return itself to buffer pool.


In inbound flow, processor read bytes from channel and fill in buffer, but do not responsible
for recycling, we will call IoBuffer.free() in Decoder or Handler after we don't need it.
In outbound flow, processor will call IoBuffer.free() after written.

It works well, we use this way reduced the allocate and copy overhead. 

Because IoBuffer.allocate() use a static global allocator, so in piece of codes I point out,
the temporary IoBuffer will waste a buffer if not call free(), one closed session waste one
buffer.

Anyway, to keep the integrity of logic, call buf.free() if readBytes==0 is not a bad thing,
right?


> When AbstractPollingIoProcessor read nothing, free the temporary buffer should be better
> ----------------------------------------------------------------------------------------
>
>                 Key: DIRMINA-1061
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-1061
>             Project: MINA
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 2.0.16
>            Reporter: Mark
>            Priority: Minor
>
> {code:title=org.apache.mina.core.polling.AbstractPollingIoProcessor.java|borderStyle=solid}
> private void read(S session) {
>         IoSessionConfig config = session.getConfig();
>         int bufferSize = config.getReadBufferSize();
>         IoBuffer buf = IoBuffer.allocate(bufferSize);
> //...
> //...
>             if (readBytes > 0) {
>                 IoFilterChain filterChain = session.getFilterChain();
>                 filterChain.fireMessageReceived(buf);
>                 buf = null;
>                 if (hasFragmentation) {
>                     if (readBytes << 1 < config.getReadBufferSize()) {
>                         session.decreaseReadBufferSize();
>                     } else if (readBytes == config.getReadBufferSize()) {
>                         session.increaseReadBufferSize();
>                     }
>                 }
>             }
> {code}
> it seems that this method will be called when session closing.
> it'll better to call buf.free() if readBytes==0, to help allocator recycle this buffer,
thx!



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message