Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Will these functions for use with Storable properly lock my file?

by bliako (Monsignor)
on Aug 03, 2021 at 15:26 UTC ( [id://11135581]=note: print w/replies, xml ) Need Help??


in reply to Will these functions for use with Storable properly lock my file?

Possibly, another solution could be to use a memory-mapped file, especially if your data can easily fit in your RAM. I am still confused on the exact way to do this. On the one hand, there is :mmap of PerlIO, something like this, but I don't know how to lock this:

my $fh; if( ! open($fh, '>>:mmap', 'file.txt') ){ die "error opening, $!" } select $fh; $| = 1; my $i; while($i++<10){ print $fh "hello $$ at $i\n"; sleep 1; } close $fh;

There is also File::Map which offers locking but from its documentation is not clear to me how to even append to the file and locking blocks. Very likely I am doing something wrong.

If you manage to get this right then it seems to me it will be faster. There are lots of other modules which use a shared-memory space to share data, like Cache::FastMmap

bw, bliako

Log In?
Username:
Password:

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

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

    No recent polls found