On 5/30/11 2:39 AM, Luciano Greiner wrote:
Hello.
Hi,
I developed a telnet server application using Apache Mina. The
clients are character (barcode reader) terminals. Recently the
customer has complained about the high CPU usage of server application
process.
It's kind weird, but after some research, i found that the CPU usage
was highly increasing because some of keyboard key getting stuck on a
terminal, and then the server keeps receiving tons of keys (chars)
constantly.
I can't control all the user actions, but i dont want my application
to hang all the time because of a bad terminal (or a bad user). I am
thinking to write a filter to detect this abnormal input and kick the
client.
Does anyone have a thought on how could it be implemented?
The base idea is that you should store on the server a counter. The
session is the best place to store such counter. You can also use more
than one counter (one per command, for instance), but still gather all
those counters in one data structure that is stored into the session.
FYI, a session stores <Key,Value> attributes which lasts for the session
duration, or until you discard the key.
In your filter, you can control the command counter, and 'kill' the
session when this counter is too high. Of course, this should be
combined with a duration window : the maximum number of commands is only
pertinent if it's reached in, say, 10 seconds. That also means you
should keep a track of the time each command is received.
That should not be too complex to implement as a filter *after* the
protocol filter. All in all, beside the obvious MINA technical parts
(Filter interface implementation, session Attributes management, closing
the session when needed), everything else is totally in your hands.
Hope it helps.
Disclaimer : if you have a full implementation, it would be interesting
to offer it to the project, as a dedicated filter, for anyone who will
be interested of using it to be able to just add the filter provided by
MINA. It's up to you ...
--
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com