I am in the process of writing a statistics gathering daemon for a number of systems, and I have some concerns about my approach. Basically, each daemon starts, connects to a central postgresql database and grabs info about what data it is supposed to gather and at what interval, then creates one thread per datasource. Each of the threads gathers its data, sleeps for it's particular duration, gathers data, sleeps and so on. The main reason for this was to be able to gather data from sources at completely different intervals..some every 2 seconds, some every 20 min, etc.

My concerns stem from the fact that with each thread, the memory usage increases by ~2MB, so for 7 datasource threads plus the main thread, I use up around 16MB of memory. I don't consider this to be wrong(is it?), but it does seem a bit inefficient. I originally hoped that each datasource thread would be called, then finish, rather than sitting on the memory perpetually. However, I could not get multiple "timers" to run independently of one another without either forking or threading them off from the main. Of course there may be a way, but I don't know it. :)

So, the questions are: Is there a way to run independent timers without one persistent thread for each? Even if there was, would the memory they use just stay allocated to the main process and not get released back to the OS anyway? Is there a better way, generally speaking, of handling a threading situation like this?

Thanks very much in advance. Hope it wasn't all too vague.

mike


In reply to 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.