What kind of system are you on, Excalibor? If it's a *NIX box, using a daemon that runs your checking loops is the way to go. Since each is a multiple of its smaller brethren, you have the daemon wake up once every 25 seconds (~) to perform phase_1 cleanup. After doing that, it checks a pair of countdown counters to see if 10 cycles of phase_1 have passed and it's time for a phase_2 sweep, and if 100 phase_1 cycles (or ten sets of phase_2) have passed and it's time for a phase_3 sweep. The daemon will remain resident, so you don't need persistent storage for the counter variables; just check them when you wake up.

It's a mistake to try to use many timers in a situation like this. Far better to use one timer and a couple of counters to accomplish the goal.

The one caution I'd give is that the time required to actually do the GC is a variable amount, depending on how many things need to be GCed. It might be appropriate to have the phase_2 and phase_3 cleanups launched as separate processes from the daemon, and use renice to adjust their system resource priority. In any event, you want to have the daemon waking up more often than you need it to to make sure that you do not overrun your interval.

In reply to Re: Multialarm loop by samizdat
in thread Multialarm loop by Excalibor

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.