You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Patrick Galbraith <pa...@patg.net> on 2003/07/20 21:47:38 UTC

caching questions

Today I just looked at Apache::Session, and just realised I spent the
last couple weeks coding what it does, more or less. I'm not sure If I
should use what I wrote, or it.

One thing that my code does is check to see if it's cache has been
updated to the db, which I wish I could really have some sort of cache
that's in one place in memory (as opposed to each child process).

I know there's IPC, and also memcached. I've used IPC::Shareable before,
but don't know if that's the route I'd wanna go.

Has anyone implemented a good caching system that sets up a global cache
that you don't have to check constantly because you happen to have been
served out by a child that doesn't have the latest cache from DB? One
single memory object?

I hope what I'm asking makes sense ;)

thanks much...
-- 
----------------------
Patrick Galbraith
Senior Software Developer
patg@patg.net capttofu@slashdot.org
pgalbraith@classmates.com
206.719.2461


Re: caching questions

Posted by Peter Haworth <pm...@edison.ioppublishing.com>.
On Tue, 22 Jul 2003 13:05:00 +0300, Stas Bekman wrote:
> Peter Haworth wrote:
> > Cache::Mmap (which I wrote) isn't threadsafe, but should work OK in a
> > forking MPM. If anyone wants to contribute code to make it threadsafe
> > (preferably without impacting single-threaded performance too much),
> > I'll be very grateful. I'd do it myself, but I've never used threads, so
> > I'm bound to get it wrong.
>
> I haven't looked at the module's implementation, but if you have a C-level
> thread-safety issues, you may consider using libapr which provides a
> thread-safe mmap API.

No, it's perl-level stuff at the point that matters. Currently, it uses fine
grained file locking to prevent concurrent accesses from other processes,
but as far as I understand it, this won't prevent concurrent accesses from
other threads in the same process.

-- 
	Peter Haworth	pmh@edison.ioppublishing.com
"Do you expect me to implement it?"
"No, Mister Schwern, I expect you to DIE!"
		-- Michael G Schwern in p5p

Re: caching questions

Posted by Stas Bekman <st...@stason.org>.
Peter Haworth wrote:
> On 22 Jul 2003 08:13:43 +0200, Tom Schindl wrote:
> 
>>Am Mon, 2003-07-21 um 21.45 schrieb Perrin Harkins:
>>
>>>On Sun, 2003-07-20 at 15:47, Patrick Galbraith wrote:
>>>
>>>>I know there's IPC, and also memcached. I've used IPC::Shareable
>>>>before, but don't know if that's the route I'd wanna go.
>>>
>>>It's not. IPC::Shareable is very slow. If you want to share data, use
>>>Cache::FileCache, Cache::Mmap, MLDBM::Sync, or IPC::MM.
>>
>>Sorry to step in here, but could I use any of the caching modules you
>>mentionned in mod_perl2?
> 
> 
> Cache::Mmap (which I wrote) isn't threadsafe, but should work OK in a
> forking MPM. If anyone wants to contribute code to make it threadsafe
> (preferably without impacting single-threaded performance too much), I'll be
> very grateful. I'd do it myself, but I've never used threads, so I'm bound
> to get it wrong.

I haven't looked at the module's implementation, but if you have a C-level 
thread-safety issues, you may consider using libapr which provides a 
thread-safe mmap API.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: caching questions

Posted by Peter Haworth <pm...@edison.ioppublishing.com>.
On 22 Jul 2003 08:13:43 +0200, Tom Schindl wrote:
> Am Mon, 2003-07-21 um 21.45 schrieb Perrin Harkins:
> > On Sun, 2003-07-20 at 15:47, Patrick Galbraith wrote:
> > > I know there's IPC, and also memcached. I've used IPC::Shareable
> > > before, but don't know if that's the route I'd wanna go.
> >
> > It's not. IPC::Shareable is very slow. If you want to share data, use
> > Cache::FileCache, Cache::Mmap, MLDBM::Sync, or IPC::MM.
>
> Sorry to step in here, but could I use any of the caching modules you
> mentionned in mod_perl2?

Cache::Mmap (which I wrote) isn't threadsafe, but should work OK in a
forking MPM. If anyone wants to contribute code to make it threadsafe
(preferably without impacting single-threaded performance too much), I'll be
very grateful. I'd do it myself, but I've never used threads, so I'm bound
to get it wrong.

-- 
	Peter Haworth	pmh@edison.ioppublishing.com
"[That sentence] occupied the table running through the middle of the middle
room in a half-way house. It was so equidistant that it managed to find a patch
of gravitic stability, a Lagrange of Reason, within which it set up a giant
tubular space station of the type that NASA were hoping to build by 2010."
		-- Ashley Pomeroy

Re: caching questions

Posted by Perrin Harkins <pe...@elem.com>.
On Tue, 2003-07-22 at 02:13, Tom Schindl wrote:
> Sorry to step in here, but could I use any of the caching modules you
> mentionned in mod_perl2?

I can't vouch for the thread safety of these modules, but all of them
should work in prefork mode.

- Perrin

Re: caching questions

Posted by Tom Schindl <to...@gmx.at>.
Sorry to step in here, but could I use any of the caching modules you
mentionned in mod_perl2?

thx

tom

Am Mon, 2003-07-21 um 21.45 schrieb Perrin Harkins:
> On Sun, 2003-07-20 at 15:47, Patrick Galbraith wrote:
> > One thing that my code does is check to see if it's cache has been
> > updated to the db, which I wish I could really have some sort of cache
> > that's in one place in memory (as opposed to each child process).
> 
> Well, you can't, unless you use threads.
> 
> > I know there's IPC, and also memcached. I've used IPC::Shareable before,
> > but don't know if that's the route I'd wanna go.
> 
> It's not.  IPC::Shareable is very slow.  If you want to share data, use
> Cache::FileCache, Cache::Mmap, MLDBM::Sync, or IPC::MM.
> 
> > Has anyone implemented a good caching system that sets up a global cache
> > that you don't have to check constantly because you happen to have been
> > served out by a child that doesn't have the latest cache from DB? One
> > single memory object?
> 
> The systems I listed above all use a shared cache that will have the
> same data regardless of which process accesses it.
> 
> - Perrin
> 


Re: caching questions

Posted by Perrin Harkins <pe...@elem.com>.
On Sun, 2003-07-20 at 15:47, Patrick Galbraith wrote:
> One thing that my code does is check to see if it's cache has been
> updated to the db, which I wish I could really have some sort of cache
> that's in one place in memory (as opposed to each child process).

Well, you can't, unless you use threads.

> I know there's IPC, and also memcached. I've used IPC::Shareable before,
> but don't know if that's the route I'd wanna go.

It's not.  IPC::Shareable is very slow.  If you want to share data, use
Cache::FileCache, Cache::Mmap, MLDBM::Sync, or IPC::MM.

> Has anyone implemented a good caching system that sets up a global cache
> that you don't have to check constantly because you happen to have been
> served out by a child that doesn't have the latest cache from DB? One
> single memory object?

The systems I listed above all use a shared cache that will have the
same data regardless of which process accesses it.

- Perrin