Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

thread-safe mmap module ?

by jdd (Acolyte)
on Feb 21, 2009 at 21:47 UTC ( #745565=perlquestion: print w/ replies, xml ) Need Help??
jdd has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I am doing mod_perl on linux and win32, and would like to have a mmap cache for the mpm_winnt apache - but Cache::Fastmmap and its WithWin32 extension is not thread-safe AFAIK - I am wondering if there exist a certified thread-safe module for shared memory ? In CPAN, nowhere is mentionned the thread-safety -; Thanks !

Comment on thread-safe mmap module ?
Re: thread-safe mmap module ?
by kennethk (Monsignor) on Feb 21, 2009 at 21:58 UTC
    Never used them myself, but a CPAN search for shared cache brings up a number of promising looking modules, including IPC::SharedCache and Cache::FastMmap. The documentation from Cache::FastMmap says:
    It uses fcntl locking to ensure multiple processes can safely access the cache at the same time.
    so it should certainly be thread-safe.
      There is a concern with the win32 support and Cache::FastMmap warns:

      Cache::FastMmap ./.. will not work on Windows or Win32 like environments.

      and a google search on IPC::SharedCache says something similar ! Unfortunate, I guess I can fall back to a Tie::Cache or a DB backend module for win32 -; Thanks for your answer btw!
        Another result that came up on that page is Cache::FastMmap::WithWin32, which "is a fork of Cache::FastMmap by Rob Mueller to include the Win32 port by Ash Berlin". Once again, never used them, but maybe this would fit your bill?
      I don't recommend using IPC::SharedCache. It's slow, and the author himself (samtregar) suggest using something else these days, as you can see in the reviews.
      It uses fcntl locking to ensure multiple processes can safely access the cache at the same time.
      so it should certainly be thread-safe.

      I'm sorry but why? Aren't fcntl locks shared between threads?

Re: thread-safe mmap module ?
by perrin (Chancellor) on Feb 22, 2009 at 00:56 UTC
    Why don't you use a standard hash shared between the threads? Do you need it to be persistent when you shut down apache?
      Indeed persistency isn't necessary, although supported; you have a point. I see in CPAN the very promising threads-shared module - its .xs clearly proves the win32 support, and in addition it works in non-threaded environments - great suggestion - thank you -;
        You're welcome. There are some other tricks for getting good thread performance with mod_perl, mostly to do with when you load things. If you need more help and suggestions, come visit us on the mod_perl list.
      Indeed.... thats why threads are used .... to facilitate sharing between threads....otherwise just fork. Fork and shared memory are an alternative to threads and threads::shared.

      There may be an advantage to using shared memory in threads, notably it is the fastest IPC out there; but there are glitches....like how would you control simultaneous concurrent access to the mmap region from different threads? You are risking data corruption.


      I'm not really a human, but I play one on earth My Petition to the Great Cosmic Conciousness
        threads:::shared offers a lock() method that is released outside of the {} scope where it is. To try -;
Re: thread-safe mmap module ?
by renodino (Curate) on Feb 22, 2009 at 17:30 UTC
    Based on other comments, you may not really need process-shared memory, but if you still do, you might check IPC::Mmap. It was developed in part to assist in creating a threads-friendly Perl debugger, so it should be thread safe.

    (Hmm, looks like the docs have gotten lost in CPAN's new restriction on package content, you'll have to scroll back to older versions to read the docs)


    Perl Contrarian & SQL fanboy

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://745565]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2014-09-18 09:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (109 votes), past polls