Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

One big fat memory resident variable reachable by other scripts

by DreamT (Pilgrim)
on Oct 12, 2009 at 17:26 UTC ( #800759=perlquestion: print w/ replies, xml ) Need Help??
DreamT has asked for the wisdom of the Perl Monks concerning the following question:

Hi!
I might be asking for something impossible here, but...
I want to store a big pile of data, preferably stored as a hash, resident in memory so that it can be reached by other scripts. The variable is to contain phrases in different languages, so when I supply an ID and a language code (for example 'phrase005'and 'EN'), the resulting data would be the value for the keys 'phrase005' and 'EN'.

So, script 1 is supposed to create the var. in memory and fill it with data, and to destroy it if necessary.
Script 2 is supposed to read and use the data.
Is it even possible to work like this in Perl?
FastCGI and databases aren't options.
UPDATE: Thank you for all your answers! I will have a look into each of the solutions listed below.
The "database out of question" question is because that the scripts themselves are quite db-intensive. But I guess, it's an option too, since it's about storing it in memory using a quite small db engine...

Comment on One big fat memory resident variable reachable by other scripts
Re: One big fat memory resident variable reachable by other scripts
by linuxer (Deacon) on Oct 12, 2009 at 17:53 UTC

    Is a Server/Client architecture an option?

    You could write a server program, which loads your data into memory and that listens for clients to connect.

    Then you write the client applications, which connect to the server and requests the data from the running server program.

    I think, perlipc is a good place to start to look for information how processes are able to interact.

Re: One big fat memory resident variable reachable by other scripts
by almut (Canon) on Oct 12, 2009 at 18:01 UTC

    In theory, you could use POSIX shared memory, but I wouldn't recommend it: there are some gotchas to it, it's cumbersome to use and not necessarily as fast to be worth the trouble.  Why not use a daemon process (service) that provides access to the data via a socket? Or simply use a database file like BerkeleyDB, which is fast, too, as the data is indexed (accessible like a hash)...

Re: One big fat memory resident variable reachable by other scripts
by Illuminatus (Curate) on Oct 12, 2009 at 18:07 UTC
    Is this *nix, or Windows? Did you look at IPC::MMA? Why is a database out of the question? You could create a ramfs to hold an SQLite database, and access the data via SQL instead of hash. All of this is going to require root permissions, so if this is the underlying limitation, sharing is going to be out of the question, at least between processes...
Re: One big fat memory resident variable reachable by other scripts
by ctilmes (Priest) on Oct 12, 2009 at 20:19 UTC
    memcached can do this. It can even span machines if you need more memory.

    There are several good Perl interfaces to it on cpan.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2014-12-29 13:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (187 votes), past polls