Kimbo wrote:
Hi all, first of all, sorry for my english :P
im writing a proxy server that at one side has a very fast tcp connection
(it receives many xml messages per second) and at the other side, a slower
client that receives these messages and does some db operations.
The proxy works fine for a day or two, but then it crashes with a "out of
memory (Java heap space)" error in the mina acceptor. I think the problem is
that the "slow" client isnt fast enough to consume incoming messages (that
the proxy forwards with "session.write") and so mina has to keep more and
more data in a "waiting-for-send" buffer.
Am i right?
In this case, how to monitor this buffer (so i can discard some message if
it is too big)? Or, how to manage this "speed" difference between the two
sides? Thx in advance.
Mirko
In MINA trunk (the future 2.0 version) there is a WriteThrottleFilter I
guess you could use. If you're using MINA 1 you would have to backport
it or use the approach described below.
For MINA 1 you could use the traffic mask to prevent the fast writer to
send messages on a session if the proxy cannot write to the client with
the same speed. The simplest but probably quite inefficient way would be
to always disable reads from the fast side in the proxy while the data
is being written to the slow side:
void messageReceived(fastSession, data) {
// Data received from the "fast" tcp connection
// Disable reads from the fastSession
fastSession.suspendRead();
// write the data to the slow client
slowSession.write(data);
}
void messageSent(slowSession, data) {
// The data has been sent to the slow client
// Enable reads from the fastSession
fastSession.resumeRead();
}
HTH
--
Niklas Therning
www.spamdrain.net