mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Emmanuel Lecharny (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (DIRMINA-1039) Response messages queue up on the server side waiting to be written to socket, while the server continues to read more request messages, causing out of heap memory
Date Wed, 06 Jul 2016 13:19:11 GMT

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

Emmanuel Lecharny resolved DIRMINA-1039.
----------------------------------------
    Resolution: Not A Problem

This is not a bug, this is an implementation error.

You have to understand that MINA is built on top of an asynchronous system, where you are
in charge of controlling what's going on.

Typically, if you face a slow client (ie, a client that does not read fast enough the message
your server is producing), and don't miitgate that, you are going to be in big trouble.

The only way to manage such a situation is *not* to write anything back to your client unless
the last message have already been sent. There is a {{message_sent}} event that is generated
in such a case, and you should process it in your {{IoHandler}} implementation.

In other words, if you have no pending message, then write the response in the {{messageReceived}}
method, and put a flag in your context to remember that a message is being sent. When you
get a new message from your client, and want to send back a response, you just have to wait
for the flag in your context to be flipped. At the same time, in the {{messageSent}} method,
flip the flag so that the next message can be written.

Now, if your client is a fast writer and a slow reader, it will be quickly blocked because
its buffer will be full on its side.

Note that it's just a possible solution. 

> Response messages queue up on the server side waiting to be written to socket, while
the server continues to read more request messages, causing out of heap memory
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: DIRMINA-1039
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-1039
>             Project: MINA
>          Issue Type: Bug
>          Components: Core
>            Reporter: Maria Petridean
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> One case in which this bug reproduces is by using a client which generates a heavy request-load.
The mina thread which processes both reads and writes - exits the write cycle after processing
every empty marker (the WriteRequest which wraps an empty buffer, acting as a message marker).
This will result in the thread resuming the read cycle, hence reading more client request
messages. After a few minutes, the number of read messages is much larger than the number
of written response messages, even though the responses are waiting in the queue, ready to
be written to socket.
> To solve this, the sever shouldn't exit the write cycle after processing every marker
WriteRequest. This way the ratio between the read and written messages will be more balanced;
this will avoid the heap memory getting full and causing server degradation.
> Also, an improvement can be considered here to avoid using the same single thread for
both reads and writes.



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

Mime
View raw message