Ah I get it. You're letting the threads die after handling a request and starting a new thread per request.

If you're concerned about performance, the general advice is to have a persistent thread pool, with the number of threads proportional to the number of execution cores on your system.

There appears to be a CPAN module, Thread::Pool which automates this process. If you did this, then you'll just require the modules in-thread and they'll only be loaded once per thread. Looking at the docs, you'll want max == min so that threads don't die off.

There are performance tradeoffs here. Using a pool should reduce mean latency (since you don't have to start a new perl thread before handling the request) but may introduce unpredictably to the latency, since the pool may be at max when a new request comes in. An appropriately-sized pool should increase the throughput (ops/second) since less work is being done per op (you aren't starting a whole new thread).


In reply to Re^3: Share symbol table between threads by jbert
in thread Share symbol table between threads by jwu

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.