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
- no need the remember the initialisation incantations (we all forget things too often)
- no performance overhead
Did that clarify what I need? |