I have a web site with lots of perl code that does various common things such as generate html using a templating system and append user-supplied data to text files. I've been doing this the obvious way, for example a typical script may:

open a template file, read from the file, close the file, open a data file, read from the file, append to the file, close the file.

While going through a general code rewrite, I thought of setting up a file client/server based approach in which I create a server that reads the data and template files upon startup then binds to a port. The web code then acts as a client, requesting data or sending updates to the server as the case may be. Thus, template files only need to be read once. It seems that this is better than storing it all in shared Apache memory because then every Apache process doesn't need to know every file for every script/module.

I coded a test client and server using Net::EasyTCP and it works well. Bashing it with apache bench gives a worse median response time but a better mean response time than the original non-client/server version of the code.

My questions are:

  1. Is this a good idea? (It seems so to me, but am I missing something.)
  2. Am I re-inventing the wheel?
  3. Unix sockets vs. TCP? (My attempts at writing unix socket code met with failure and Net::EasyTCP made writing the server and client code very easy, so I just went with that.)

In reply to File Server for cgi scripts by genecutl

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.