All,

Will start by saying that this is more philosophical than code/pseudo-code. I'm also in the "early stages" of learning threads with Perl. Have written a couple threaded apps for file operations, but now looking to expand that knowledge.

After many hours of searching, reading and trying to establish "an optimal method" - looking for opinion/guidance/suggestion/etc.

  • Suspect Boss/Worker(s) is the correct solution for my paradigm
  • Based on Boss/Worker, the items below expresses "desirable" end-state.
  • Queues via Thread::Queue
  • Boss:
  • Waits for <STDIN>
  • Appends manipulated input to $TXQUEUE->enqueue()
  • Monitor $RXQUEUE and <STDIN> - simultaneously???
  • Sends <STDOUT> while(my $RESULT=$RXQUEUE->dequeue_nb()), until $RXQUEUE is empty. $RESULT is sent "AS-IS"
  • Worker(s):
  • Obtain next queue item from $TXQUEUE->dequeue_nb()
  • Interact with data engines to derive answer
  • Append result(s) to $RXQUEUE->enqueue()
  • Monitor $TXQUEUE
  • Errata:
  • Right now to bridge the gap, there may be as many as 50 instances of this "middleware" between the data engines and the application.
  • Each middleware instance (upon instantiation) creates connections to the data engines, for the life of the process, to avoid connection overhead.
  • Currently using a while(my $INPUT=<STDIN>) - it's simple text artifacts being prefaced by a transaction ID.
  • At the moment, the transaction rate can vary from zero to +/- 50 at any given moment. May go minutes without a transaction or may sustain an average between 30-42 per second for 45-90 seconds.
  • Does not run and exit. Kept open by application, until application is shutdown
  • Most examples seen appear to be something that passes the socket to worker to complete vs. activity to worker and then obtain worker result to provide response -or- appear to run until complete and exit vs. keeping thread(s) idle/monitoring for next transaction(s). (May have missed a superb example out there?)
  • Questions:
  • Have seen a lot of posts about not using Perl library 'X' for pools/etc. For 5.24 (or better) is that still the prevailing perspective? (eg: no better mouse trap)
  • Have seen the use of "usleep", is that the best method for "idling" a worker thread?
  • Is there a way to achieve the benefit of the while loop (avoid CPU cycle consumption while idle), but then issue of providing results to <STDOUT> the moment (or very close to when) they are available?
  • Thanks!


    In reply to Threading with a twist by scorpion7

    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.