rdfield has asked for the wisdom of the Perl Monks concerning the following question:
To set the scene: I have a large database (several dozen million rows) and a web (Apache/mod_perl) based application that allows the user to define and select their own views of the data. Some operations take several minutes to complete to creation of the data structure that underlies the view. Some changes to the view do not require that the data structure be rebuilt, just parsed in a different way to produce to user selected view. In this case I thought that using one of the serialisation modules would help - and they did until the number of rows returned from the database exceeded about 20000, which would have been OK, but the result sets could involve several hundred thousand rows. After 20000 rows it becomes quicker to rebuild the data structure from scratch.
After a bit of head scratching I tried to use SOAP::Lite for the job, but again became bogged down by the fact the the data of the object is serialised and sent to the client. Hence the kludge I have been working on. The following code actually works (i.e. the data is retained across different runs of the client process, simulating multiple web requests), but (and here's the question...) it all looks a bit, well, inelegant - does any monk with more experience of object caching have any ideas/observations that they're willing to share?
The Demo package: #!perl -w package Demo; use strict; my @handle; sub new { my $class = shift; my $id = shift; $handle[$id] = bless {string => shift},$class; print "new $handle[$id]->{string}"; return $id; } sub string{ my $self = shift; my $id = shift; print "id = $id, handle string = $handle[$id]->{string}\n"; if (@_) { $handle[$id]->{string} = shift; } return $handle[$id]->{string}; } sub get{ my $self=shift; my $id = shift; if ($handle[$id] == undef) { print "not defined!"; $self->new($id,"undefined"); } return $id; } 1; The server: #!perl -w use SOAP::Transport::HTTP; use Demo; use strict; my $daemon = SOAP::Transport::HTTP::Daemon -> new (LocalPort => 90) -> dispatch_to('Demo') ; print "Contact to SOAP server at ", $daemon->url, "\n"; $daemon->handle; The first client: #!perl -w use strict; use SOAP::Lite +autodispatch => uri => 'Demo', proxy => ('http://localhost:90/soap/server.pl'); my $demo = Demo->new(1,"test1a"); print Demo->string(1) . "\n"; Demo->string(1,"test1b"); print Demo->string(1) . "\n"; and the second client that demonstates that the data has benn cached: #!perl -w use strict; use SOAP::Lite +autodispatch => uri => 'Demo', proxy => ('http://localhost:90/soap/server.pl'); my $demo = Demo->get(1); print Demo->string(1) . "\n"; Demo->string(1,"test 2"); print Demo->string(1) . "\n";
rdfield
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Large datastructure caching
by robartes (Priest) on Nov 16, 2002 at 11:56 UTC | |
by rdfield (Priest) on Nov 18, 2002 at 10:01 UTC | |
by rdfield (Priest) on Nov 16, 2002 at 15:14 UTC | |
|
Re: Large datastructure caching
by rdfield (Priest) on Nov 16, 2002 at 10:03 UTC |