You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Alex Burmester <ad...@plushpix.com> on 2005/07/15 01:01:24 UTC

Suggestions on implementing timeouts?

Hi all, 

I have a protocol router built on top of mina.  One thing I am having 
issues with is my timeout cleanup code causing the occasional 
ConcurrentModificationException when under heavy load.

I have a hash of connections and each has a hash of outstanding messages.
Every so often a synchronized cleanup method is run that iterates over all 
the connections and all the outstanding messages and cleans up any stale 
messages.  I think the issue is that even though the individual HashMaps 
are wrapped as synchronizedMaps (I probably should update to 
ConcurrentHashMap) However I think I missed something because it appears 
that under load, once in a while one of the maps is still able to get 
modified by another thread while the cleanup iterators are open.

I'm thinking maybe it might be best to change my timeout strategy.  
Perhaps I should be registering a timeout event with an event queue
for each message, although this seems like a lot of overhead for something 
that is supposed to be quick and lite.  

Anyone have any suggestions for implementing timeouts without blocking all 
other threads during the cleanup scans?

Thanks,

Alex.


Re: Suggestions on implementing timeouts?

Posted by Trustin Lee <tr...@gmail.com>.
Ah, I see. I implemented that when I was working for a telco company. You 
can simply use java.util.Timer. Just schedule timeout TimerTasks for each 
messages. Timer will automatically call your TimerTask.run() so that you can 
process timeout event. Of course you'll have to cancel the task whenever you 
get a response.

I guess this approach doesn't have much overload comparing to the time taken 
by transactions. I have been using this techinique for sending about 30 SMSs 
a second.

Trustin

2005/7/20, Alex Burmester <ad...@plushpix.com>:
> 
> My server has to keep incomming connections open to a third party
> and route multiple messages over the same channel using transaction ids
> to keep track of which messages are outstanding. I need a way to time out
> these transactions. Currently every half second I scan my outstanding
> message queues and remove any messages that are older than the timeout. My
> issue with this is that the cleanup method has to lock the whole complex
> datastructure of connections and outstanding messages during the scan.
> Doesn't seem to be a problem yet but I'm concerned that under higher load 
> it
> will become the main bottleneck. I was thinking about putting in an event
> queue and firing timeout events for each message but I'm not sure if the 
> overhead
> of registering and deregistering each timeout event for each successful
> message is worth it. Just wondering if there is a pattern that I'm not
> thinking of that gets around these issues.
> 

Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/

Re: Suggestions on implementing timeouts?

Posted by Alex Burmester <ad...@plushpix.com>.
My server has to keep incomming connections open to a third party
and route multiple messages over the same channel using transaction ids 
to keep track of which messages are outstanding.  I need a way to time out 
these transactions.  Currently every half second I scan my outstanding 
message queues and remove any messages that are older than the timeout. My 
issue with this is that the cleanup method has to lock the whole complex 
datastructure of connections and outstanding messages during the scan.  
Doesn't seem to be a problem yet but I'm concerned that under higher load it 
will become the main bottleneck.  I was thinking about putting in an event 
queue and firing timeout events for each message but I'm not sure if the overhead 
of registering and deregistering each timeout event for each successful 
message is worth it.  Just wondering if there is a pattern that I'm not 
thinking of that gets around these issues.

Thanks,

Alex.

On Tue, 19 Jul 2005, Trustin Lee wrote:

> Hi Alex,
> 
> MINA supports reader/writer idleness detection and write timeout out of the 
> box. Please take a look at IoSessionConfig and SocketSessionConfig and let 
> us know if those configuration parameters are not sufficient.
> 
> Trustin
> 


Re: Suggestions on implementing timeouts?

Posted by Trustin Lee <tr...@gmail.com>.
Hi Alex,

MINA supports reader/writer idleness detection and write timeout out of the 
box. Please take a look at IoSessionConfig and SocketSessionConfig and let 
us know if those configuration parameters are not sufficient.

Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/