Am I correct to say that it's wrong to tie the dbm file in startup.pl and
than share it across the children? 

>From now on I'm talking about read-only accesses and no locking is
used. (and even if it was used for shared locks, the behavior won't
change)

If you do this in the child

 use vars qw(%dbm);
 tie %btree , 'DB_File', 'foo', ...
     unless tied %dbm;

you will tie only once for the whole child's life and thus save the tie
overhead for all other requests to come.

However if you do the tie in startup.pl:

  package My::Tied;
  tie %My::Tied::btree, 'DB_File', 'foo',  ...

and then in the handler's code:

  use My::Tied;
  $bar = $My::Tied::btree{foo};

I think that unexpected things may happen since %My::Tied::btree has only
one file descriptor, and different processes accessing the dbm file at the
same time will mess it up, since the dbm iterator (or think of it as
seek() ) will jump wildly to satisfy requests from different processes and
wrecking havoc with methods like keys(), each() and similar...

Am I correct here? If so there is a bad suggestion in the guide which
should be corrected :(

Thanks!

_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide 
mailto:[EMAIL PROTECTED]   http://apachetoday.com http://logilune.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/  


Reply via email to