He's my naive understanding of your concerns, someone here may have to correct me:
On Mar 15, 2005, at 6:26 PM, André Warnier wrote:
I have previously gone though a lot of perl and mod_perl documentation, and perl module descriptions, and I never seemed to find a clear answer about wether yes or no it was possible to share in-memory data between 2 perl processes (or threads) running under Apache.It's not. Its part of the forking model and design. That's why people suggested the use of DBs and caching systems such as memcached -- you can store your data into a foreign object -- either a db or a memory agent -- and then let separate processes or machines access it. Anything you want to do can easily be handled by either a memory cache or a db cache.
How come no-one has come up yet with some scheme to "hijack" one of these bucket brigades (or some other internal Apache memory area) to provide such a capability ?it sounds like you want to defeat the design of the forking model -- something like what you want would be more of a standalone daemon, and not Apache.
Also, for instance, the DBI module and it's companion Apache::DBI provide persistent connections to databases. And to my knowledge, they are available under Unix as well as Windows. For doing this, there must be some form of memory sharing at work, isn't it so ?If you instantiate a DBI handle before the fork, then that handle is shared to all the children. If you instantiate the handle after the fork, the handle belongs to only that child , and shared across the requests of that child. So, if you get a handle, then spawn 12 children, they will each share the single handle. If your code creates a handle after the fork, then you will have 12 handles. There's a section on 'shared memory' in both mod_perl books that explains it better than my attempt -- there's also a section on using startup scripts to preload all the info.
At first, the forking model is strange, its aggravating, and sometimes I wanted to kick it – it took a while for me to get used to it, and see why it makes sense. I still wish there were some ways to easier share data between children (maybe there are, and I no one on this list has answered my hopes yet) -- but I've found using a db pretty damn good -- and memcached supports sharing data between machines too.