Hi, I'm seeking advice on the following task: in the linux/apache/mod_perl setting, my app needs to get a single record from a rather large database table with a pretty complicated query, and update that record upon user's action, the requirement is that each request should get a different record.

My first version was very simple: just run the query each time, and return the first row. This has two problems: it's slow, and two request can get the same result back if accessed simultenously.

My second version built an cache (an array of records) in shared memory using IPC::Shareable, so each time I just shift the array, and query once when the cache is empty. This has been working fine for awhile. But I didn't like the shared memory solution, one reason is that my test script always run out of semaphores (ok in deployment since there were only a few apache processes), the other reason is that I'd like to have other apps, probably from a different machine, to have access to the same data.

So I'm working on my third solution: to create a separate TCP server, that serves as a global cache. I'm avoiding using SOAP-like mechanism, since that's not fast enough for me. I'd like a client (say the web app) to keep the TCP connection open. This seems to be working fine now, based on my limited test scripts.

I guess my question is to ask your thoughts/comments on the whole task/solution, and whether there already exists such a solution there (too late for that? I'm willing to throw my code anytime there is a better one!) Thanks.


In reply to A database caching scheme by johnnywang

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.