I'm definitly not trying to read the entire database into memory. That would take about 40GB, and we don't have that much available for each apache process!
The system is a 3 tier system, with an apache frontend (written using Apache::ASP, handling the formatting of data, session handling etc), a set of application servers (communicating with apache using CORBA through the COPE modules), and the database (about 40 GB of data in ~800 table, the largest containg >130mill rows, access using DBI, DBD::Ingres {which I wrote} etc) - all on different machines. The database contains very sensitive data, so security is important.

We have some (about 50-100) table that contain things like eg zip-code, department addresses, typecodes, and so on ad nauseam. Some are small, some are big, others huge - it varies.

In the frontend code (on apache) we eg. need to create selectboxes, that let the user choose between different options, based on the content of the constant tables.

A possibility would be to fetch the data everytime it is needed:

my $zip = $zip_server->get_zip_codes(); print "selectbox-header"; for (@$zip) { print "selectbox line"; } print "selectbox-end";
or something like that.

This will take quite a while and soon you discover the need for caching the data. So you try something like:

...in common initialisation code... our $zip; $zip=$zip_server->get_zip_codes(); ...where the zip-code is needed... print "selectbox-header"; for (@$zip) { print "selectbox line"; } print "selectbox-end"

This is fast, but it takes more and more memory as the number of constants rise. So the next version could be something like:

...in the common initialisation code... our $zip; sub zip_init { $zip = $zip_server->get_zip_codes() unless $zip; } ...at every use... zip_init(); print "selectbox-header"; for (@$zip) { print "selectbox line"; } print "selectbox-end";
That is fast, easy and does not comsume unnessacry amounts of memory. the downside is that you have to remember to call the zip_init before you use $zip.
Sometimes you forget, and spend an excessive amount of time scratching your head and trying to fathom what went wrong.

So I would like something like:

...in initialisation section... our $zip; tie $zip .... # magic here sub ZIP::TIE::FETCH { # smoke and mirrors here $zip = $zip_server->get_zip_codes(); untie $zip; # and leave the data in $zip } ..and where we use it... print "selectbox-header"; for (@$zip) { print "selectbox line"; } print "selectbox-end";
Note no zip_init, fetch calls. Just the plain ordinary access to a variable.

At the first reference to the variable the tie magic clicks in and retrieves the data, and removes the magic, leaving the 'naked' variable.
Giving

Did that clarify what I need?


In reply to Re: Re: Using tie to initialize large datastructures by htoug
in thread Using tie to initialize large datastructures by htoug

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.