in reply to multiple threads with different "timers"
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
|
|---|