Return-Path: Delivered-To: apmail-perl-modperl-archive@www.apache.org Received: (qmail 64081 invoked from network); 29 Oct 2009 13:10:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 29 Oct 2009 13:10:35 -0000 Received: (qmail 57466 invoked by uid 500); 29 Oct 2009 13:10:33 -0000 Delivered-To: apmail-perl-modperl-archive@perl.apache.org Received: (qmail 57445 invoked by uid 500); 29 Oct 2009 13:10:33 -0000 Mailing-List: contact modperl-help@perl.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list modperl@perl.apache.org Received: (qmail 57437 invoked by uid 99); 29 Oct 2009 13:10:33 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 29 Oct 2009 13:10:33 +0000 X-ASF-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00 X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of torsten.foertsch@gmx.net designates 213.165.64.20 as permitted sender) Received: from [213.165.64.20] (HELO mail.gmx.net) (213.165.64.20) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 29 Oct 2009 13:10:31 +0000 Received: (qmail invoked by alias); 29 Oct 2009 13:10:09 -0000 Received: from p57A5F9A6.dip.t-dialin.net (EHLO opi.home) [87.165.249.166] by mail.gmx.net (mp048) with SMTP; 29 Oct 2009 14:10:09 +0100 X-Authenticated: #1700068 X-Provags-ID: V01U2FsdGVkX1/qRhd4hOrqAv3S0j+kx6d8E1p7OnmV9+iF1IFu8q 9yVdMg4RN48xMK From: Torsten Foertsch To: modperl@perl.apache.org Subject: Re: Storing config values in-memory between sessions Date: Thu, 29 Oct 2009 15:10:06 +0200 User-Agent: KMail/1.9.10 Cc: Mahesh Khambadkone References: <654c8ea40910282113x1c9cfcecs6cfd4f5f9aff3f73@mail.gmail.com> In-Reply-To: <654c8ea40910282113x1c9cfcecs6cfd4f5f9aff3f73@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200910291410.06930.torsten.foertsch@gmx.net> X-Y-GMX-Trusted: 0 X-FuHaFi: 0.48 On Thu 29 Oct 2009, Mahesh Khambadkone wrote: > As it seldom changes, we dont want to use a database for these > 'config values', yet need a way to retain in memory and dirty its' > value from time to time. Have a look at MMapDB which I have just uploaded to CPAN. I wrote this module some time ago exactly for that case: configuration data that seldom changes. Before I have used BerkeleyDB. But that is a bit touchy when it comes to sudden process death. I wanted something simple, stable and fast. So an MMapDB database cannot be modified by a connected process because it is mapped read-only. Changing data means rewriting the database file and reconnect the new one. This also means the whole database is shared memory between all connected processes. There is a tie() based interface. So, even dumping human readable data is simple: perl -MMMapDB -MData::Dumper -e ' print Dumper(MMapDB->new(filename=>shift)->start->main_index); ' /etc/opt/TRANSCONFIG/transconfig.mmdb And a more complicated but faster interface: perl -MMMapDB -le ' # open the DB my $db=MMapDB->new(filename=>shift)->start; # get data record positions my @pos=$db->index_lookup($db->mainidx, qw!actn opi /svn!); # fetch a data item print $db->data_record($pos[0])->[2]; ' /etc/opt/TRANSCONFIG/transconfig.mmdb One even can store large values there and pass references to them around and thus avoid copying and mallocing that happens normally when you do $x=$y: perl -MMMapDB -MDevel::Peek -e ' my $db=MMapDB->new(filename=>shift)->start; my @pos=$db->index_lookup($db->mainidx, qw!actn opi /svn!); # get a reference to the data item to avoid copying my $v=\$db->data_record($pos[0])->[2]; print $$v, "\n"; Dump $$v ' /etc/opt/TRANSCONFIG/transconfig.mmdb File: '/opt/svnbook'.$MATCHED_PATH_INFO SV = PV(0x9d4b50) at 0x7c9248 REFCNT = 1 FLAGS = (POK,READONLY,pPOK) PV = 0x7f956388d240 "File: '/opt/svnbook'.$MATCHED_PATH_INFO" CUR = 39 LEN = 0 You see $v points to a read-only variable. The PV pointer of this variable references the string inside the read-only mapped database file. Now you can do $x=$v and only the reference is copied. Torsten -- Need professional mod_perl support? Just hire me: torsten.foertsch@gmx.net