Re: Class data preloading modules

2001-11-27 Thread Perrin Harkins

 * initialize everything in the parent Apache, just make sure to create
   new DBI connections in the children.

That's what I would do.  It increases the amount of shared memory.
Disconnect the DBI connection when you're done with it.  Apache::DBI
doesn't cache connections during startup, so this shouldn't be a
problem.
- Perrin




Class data preloading modules

2001-11-23 Thread Adriano Nagelschmidt Rodrigues

Hi,

I have some modules that use the idiom

package Foo;

use Bar;

{
  my $bar = Bar-new(args);
  sub bar { return $bar }
}

which works fine until one tries to preload them in startup.pl.

I realized that, by preloading, I was innocently sharing the same DBI
object between Apache children (nothing strange happened during
testing, but I guess it was only a question of time  stress).

I also happen to have Foo subclasses that need the DBI connection to
produce otherwise shareable (read only) class data.

My question is about good programming practice in this case. I guess
I have three options:

(init once per MaxRequestsPerChild)

* initialize the class data externally, from within a method.

* do something like

  {
my $bar;

sub bar {
  $bar = BAR-new(args) unless $bar; # too ugly? performance loss small?
  return $bar;
}
  }

(init only once)

* initialize everything in the parent Apache, just make sure to create
  new DBI connections in the children.


What do you think?

Thanks,

--
Adriano