perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Peters <mpet...@plusthree.com>
Subject Re: share use vars?
Date Fri, 17 Jul 2009 18:53:48 GMT
Brad Van Sickle wrote:
> I'm also wondering why this needs to be shared between processes... but 
> if it is required, you can share variables between mod_perl processes by 
> caching them on server startup, assuming that they are read only.

Calling this variable "shared" is a little misleading. If you're using a system 
with copy-on-write memory, then yes the physical memory is shared by the 
processes, but that's invisible to the users and the variable is not logically 
shared. Also, there are lots of things that could happen to make that page in 
memory "dirty" which would cause the physical RAM to become unshared. You don't 
have to actually change the variable for this to happen.

But the sentiment is right and this is a great way to fake the sharing of a lot 
of read only data.

I didn't recommend this technique because there is a big caveat: file handles. I 
don't know the implementation details of Geo::IP but it does pull it's data from 
data files. If it slurps it all at once into memory and then just uses that data 
afterwards then you're ok. Or if it opens a new filehandle every time it wants 
data and then closes it you're also ok. But if it opens a filehandle and then 
keeps it around you can't share it. All sorts of bad and weird things can and 
will happen in very unpredictable ways when inherited filehandles are used by 
forked children.

-- 
Michael Peters
Plus Three, LP


Mime
View raw message