[concurrency-interest] Frequently canceled timers
Mike Edwards
mike_edwards at uk.ibm.com
Fri Jan 25 08:05:57 EST 2008
> Date: Thu, 24 Jan 2008 09:42:23 -0800
> From: "Joe Bowbeer" <joe.bowbeer at gmail.com>
> Subject: Re: [concurrency-interest] Frequently canceled timers
> To: concurrency-interest <concurrency-interest at cs.oswego.edu>
> Message-ID:
> <31f2a7bd0801240942m44a915c2te0fb342c2fac963f at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> It should be more efficient to call executor.purge() periodically than
> to call remove() frequently. Will this work in your case?
>
> On Jan 24, 2008 8:20 AM, Richard Johns wrote:
> > I have an application that retransmits messages when they don't get a
> > timely response . Usually, of course, that's not necessary and their
> > timers are canceled. This is a traffic generator so message rate is
> > high and we need to remove the canceled timers.
> >
> > Is there a timer implementation that efficiently cleans up canceled
> > timers? DelayQueue uses a binary heap so it's very fast otherwise,
but
> > it uses a sequential search for remove(). ScheduledThreadPoolExecutor
> > uses DelayQueue, and Timer also uses a binary heap.
> >
> > --
> > Rick
> Date: Thu, 24 Jan 2008 15:19:17 -0800
> From: "Joe Bowbeer" <joe.bowbeer at gmail.com>
> Subject: Re: [concurrency-interest] Frequently canceled timers
> To: concurrency-interest <concurrency-interest at cs.oswego.edu>
> Message-ID:
> <31f2a7bd0801241519j3d9ca827s9e4fd850b9c1346 at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> > Richard Johns wrote:
> >
> > I have an application that retransmits messages when they don't get a
> > timely response . Usually, of course, that's not necessary and their
> > timers are canceled. This is a traffic generator so message rate is
> > high and we need to remove the canceled timers.
> >
> > Is there a timer implementation that efficiently cleans up canceled
> > timers? DelayQueue uses a binary heap so it's very fast otherwise, but
> > it uses a sequential search for remove(). ScheduledThreadPoolExecutor
> > uses DelayQueue, and Timer also uses a binary heap.
> >
> > Joe Bowbeer wrote:
> >
> > It should be more efficient to call executor.purge() periodically than
> > to call remove() frequently. Will this work in your case?
> >
> > Richard Johns wrote:
> >
> > No, ThreadPoolExecutor.purge() just gets the queue and calls remove()
for
> > each canceled Future. That would be worse, it would take the hit all
at
> > once.
>
> Now I see.
>
> TPE.purge() iterates through the queue and calls iterator.remove() at
> the appropriate times.
>
> However, DelayQueue's Iterator implementation re-walks the queue
> (again) for each item that is removed.
>
> So I no longer think that ScheduledThreadPoolExecutor.purge() is more
> efficient than removing each item separately -- and I'm unhappy.
>
> --Joe
Folks,
When I implemented the AIO4J async IO package, I ran into the same problem
concerning cancelled Timers - I/O operations having a timeout applied
would
in general complete before the Timer expired, requiring the Timer to be
cancelled in 99.99% of cases. The standard Timer implementation in the
JRE
doesn't handle high rates of allocation/cancellation of Timers at all
well,
resulting in the heap filling with cancelled Timer objects.
The way I got around this was to reimplement the Timer related classes
providing for immediate removal of a Timer object from its related holder
structure and enabling efficient garbage collection. This required a fast
remove operation and to achieve this I implemented the holder structure
based on a skip list permitting both efficient insertion and removal of
Timer objects.
Once this was done, the code could sustain very high rates of async I/O
method calls, where each call had a timeout and as a result an associated
Timer object.
Yours, Mike.
Strategist - Emerging Technologies, SCA & SDO.
Co Chair OASIS SCA Assembly TC.
IBM Hursley Park, Mail Point 146, Winchester, SO21 2JN, Great Britain.
Phone & FAX: +44-1962-818014 Mobile: +44-7802-467431
Email: mike_edwards at uk.ibm.com
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number
741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20080125/79bee17c/attachment.html
More information about the Concurrency-interest
mailing list