Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Cache :: FastMmap (threads)

by tye (Sage)
on Aug 19, 2015 at 04:50 UTC ( [id://1139118]=note: print w/replies, xml ) Need Help??


in reply to Re: Cache :: FastMmap
in thread Cache :: FastMmap

Some person says:

Never used them myself, but [....] Cache::FastMmap says:
[...] ensure multiple processes [...]
so it should certainly be thread-safe.

Meanwhile, Cache::FastMmap itself reports:

Cache::FastMmap does not support threads.

Which source do you think is most likely to be correct? :)

To add some context and/or clarity... Looking at the source code, FastMmap.pm, one finds:

sub CLONE { die "Cache::FastMmap does not support threads sorry"; }

Searching perlmod for "CLONE" we find that this sub is called after a Perl thread is created.

So Cache::FastMmap clearly declares itself to not support Perl threads and that error message appearing as reported seems to indicate that Perl inside of Apache is actually creating Perl threads.

My experience is that Apache doesn't create Perl threads by default nor in the vast majority of configurations of Apache that I've run into.

So my guess at a possible short route to resolving the problem would be to modify the Apache configuration to tell it to stop spawning threads.

[ Aside:

It has been a long time since I looked at mixing Apache, Perl, and threads. But I recall finding that Apache threading made use of Perl threads. That matches a pattern I had seen elsewhere when embedding Perl into a program that uses threads. I still believe that this pattern comes about from an understandable (unless you expect people to read and understands the docs) but unfortunate misunderstanding.

If I were to embed Perl into a program that uses threads, I would very much not make use of Perl's threads. I'd certainly be at least tempted to build Perl w/o "thread support". "But how can you use Perl from threads if you build it without support for threads?" you ask.

Building Perl with support for threads is about making it possible for Perl to create threads. Using Perl from threads doesn't require that at all. When embedding Perl for use from threads, you have two choices:

First, you can use a single Perl interpreter instance (per process) and access that instance from as many threads as you like so long as only one thread at a time uses it.

Second, you can build Perl with "MUTLIPLICITY" (see perlguts) and have as many instances of the Perl interpreter as you want in your process and each can be used from any threads so long as only one thread at a time uses it. You could choose to bind each instance of the interpreter to a specific thread. That means you don't have to worry about having locks barring simultaneous use of each interpreter instance, but that also means that each thread must pay the penalty of the memory required for a full instance of Perl. For some use cases, that will make sense.

(In the first case, I would probably build Perl w/o MULTIPLICITY, though it should work even w/ MULTIPLICITY so long as you always pass in the same "context".)

Note that even a Perl module that doesn't "support threads" would likely work fine in multiple Apache threads if Apache had not made the mistake of using Perl threads. Now, there are a few things that a Perl module could do that could break in such a scenario, but I find those things to be rather unlikely in a Perl module, especially one embedded in Apache.

But fixing Apache threads to not use Perl threads is likely no small endeavor (not even counting the significant political/social tasks required). So this aside isn't particularly useful. Though, I hope some small number of people find it, to some extent, informative.

]

- tye        

Replies are listed 'Best First'.
Re^3: Cache :: FastMmap (threads)
by BrowserUk (Patriarch) on Aug 19, 2015 at 06:55 UTC
    My experience is that Apache doesn't create Perl threads by default nor in the vast majority of configurations of Apache that I've run into.

    You're probably right tye. I attempted to set up Apache once a long time ago and gave up almost immediately.

    It was late (2:30am) and the author is someone I associate with correct information; so I passed on the link to allow the OP to make up his own mind whether the information the thread contained was useful to him.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.
    I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1139118]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2024-04-18 20:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found