It is I, the poster. It's been a while since I visited perlmonks, and I must have forgotten. I have never gotten a set of more helpful, relevant and informative replies to a posting anywhere. MEGA kudos to all of you.

Anyway, I rewrote the core to work based on one big timer, with only a few threads. Basically, I build a hash of unique keys representing each "plugin", with the value set to the next execution time. I run a time checking subroutine to increment the first execution time by 1+ seconds as necessary to prevent hitting two execution calls in any one second. This might slow the first execution by a few seconds, but the intervals are proper after that. The execution time for each "plugin" (I really need to decide on some words here, heh) increments each time it is run.

Next, since I found that having several calls scheduled for only a few seconds apart each made it quite difficult to not have simultaneous calls despite the check, so I added a "freshness" check, split off two worker threads, divided the tasks into organizational classes and divided the load between threads and everything is working perfectly.

My cpu time is actually lower than before and I run steady at about 4-6MB of mem regardless of how many scheduled tasks I have running. This way I can also kill off a thread if the data gathering hangs or anything gets weird, without losing the whole daemon.

I love the idea of the UDP triggers, but I was really trying to avoid having anything listening on the network, I'll probably use that later. I'm also researching POE and Sys::AlarmCall, they seem very relevant. I need to memorize CPAN, heh.

Thanks again for all the great info, you guys rock :)

mike


In reply to Re: multiple threads with different "timers" by Anonymous Monk
in thread multiple threads with different "timers" by Anonymous Monk

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.