You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Differentiated Software Solutions Pvt. Ltd" <di...@vsnl.com> on 2000/11/06 11:47:40 UTC

Sharing vars across httpds

Hi,

We want to share a variable across different httpd processes.
Our requirement is as follows :

1. We want to define one variable (which is a large hash).
2. Every httpd should be able to access this variable (read-only).
3. Periodically (every hour) we would like to have another mod_perl program to refresh/recreate this large hash with new values
4. After this, we want the new values in the hash to be available across httpds

How do we do this ??
Thanks for helping us.

Regards,

Murali

Differentiated Software Solutions Pvt. Ltd.
176, Ground Floor, 6th Main,
2nd Block, RT Nagar
Bangalore - 560032
Phone : 91 80 3431470
www.diffs-india.com

Re: Sharing vars across httpds

Posted by Perrin Harkins <pe...@primenet.com>.
Greg Cope wrote:
> Have you benchmarked this vs IPC::ShareLite ?

Sorry, I don't have numbers for ShareLite vs. files.  However, this is
from DeWitt Clinton's File::Cache module docs:

   File::Cache implements an object store where data is persisted across 
   processes in the filesystem.  It was written to compliment
IPC::Cache.
   Where IPC::Cache is faster for small numbers of simple objects, 
   File::Cache tends towards being more performant when caching large
   numbers of complex objects.

He posted some info to the list which you can find in the archive. 
IPC::Cache uses ShareLite.

- Perrin

Re: Sharing vars across httpds

Posted by Greg Cope <gr...@rubberplant.freeserve.co.uk>.
Perrin Harkins wrote:
> 
> On Mon, 6 Nov 2000, Differentiated Software Solutions Pvt. Ltd wrote:
> > We want to share a variable across different httpd processes.
> > Our requirement is as follows :
> >
> > 1. We want to define one variable (which is a large hash).
> > 2. Every httpd should be able to access this variable (read-only).
> > 3. Periodically (every hour) we would like to have another mod_perl program to refresh/recreate this large hash with new values
> > 4. After this, we want the new values in the hash to be available across httpds
> 
> If that's all you want to do, I would stay away from the notoriously slow
> and sometimes tricky IPC modules.  My dirt simple approach is to put the
> data in a file and then read it into each httpd.  (No point in trying to
> load it before forking if you're going to refresh it in an hour
> anyway.)  You can use Storable for your data format, which is compact and
> fast.  To check for an update, just stat the file and reload the data if
> it has a newer mtime.  If you don't like doing the stat every time, put a
> counter in a global variable and just stat once every 10 requests or
> something, like Apache::SizeLimit does.  If your data is too big to pull
> into memory, you can use a dbm file instead.
> 
> - Perrin

Have you benchmarked this vs IPC::ShareLite ?

I've heard similar rumours about IPC being slow - but is this using
Shareable (a pure perl implementation) or ShareLite (C / XS
implentation).

I would be interested in any results / ideas on how to do it.

Greg



Re: Sharing vars across httpds

Posted by Perrin Harkins <pe...@primenet.com>.
On Mon, 6 Nov 2000, Differentiated Software Solutions Pvt. Ltd wrote:
> We want to share a variable across different httpd processes.
> Our requirement is as follows :
> 
> 1. We want to define one variable (which is a large hash).
> 2. Every httpd should be able to access this variable (read-only).
> 3. Periodically (every hour) we would like to have another mod_perl program to refresh/recreate this large hash with new values
> 4. After this, we want the new values in the hash to be available across httpds

If that's all you want to do, I would stay away from the notoriously slow
and sometimes tricky IPC modules.  My dirt simple approach is to put the
data in a file and then read it into each httpd.  (No point in trying to
load it before forking if you're going to refresh it in an hour
anyway.)  You can use Storable for your data format, which is compact and
fast.  To check for an update, just stat the file and reload the data if
it has a newer mtime.  If you don't like doing the stat every time, put a
counter in a global variable and just stat once every 10 requests or
something, like Apache::SizeLimit does.  If your data is too big to pull
into memory, you can use a dbm file instead.

- Perrin


Re: Sharing vars across httpds

Posted by Steven Cotton <st...@cotton.dk>.
On Mon, 6 Nov 2000, Differentiated Software Solutions Pvt. Ltd wrote:

> Hi,
> 
> We want to share a variable across different httpd processes.
> Our requirement is as follows :

Look at the IPC::* modules, IPC::ShareLite will do exactly what you
need.

-- 
steven