Solved

Hash of Hashes Shared Across Parallel Forks Orphans Memory

Posted on 2003-11-04
6
1,646 Views
Last Modified: 2012-06-27
I have a simplified example of a problem I'm trying to solve (below).  Up
until recently, I have had much success with the IPC::Shareable module for
sharing variables across parallel forks.

Unfortunately, when I use a hash of hashes with IPC::Shareable, I get
orphaned shared memory segments.  If I remove the line that says
$hash{'test'}{'test'} = 'test', then the script runs without orphaning
memory...  The maintainer of the module no longer lives at the listed email
address, and if I could get a hash of hashes to share across parallel
forks, it would reduce my run-times dramatically...

Any thoughts for another way short of Open2, udp datagrams, or any other
such ugliness?

Broken code below:
---
!/usr/bin/perl -w

use lib 'site_perl';
use IPC::Shareable(':all');
use Parallel::ForkManager;

my $forkman = new Parallel::ForkManager(1);

my $key;
my %hash;
my %options = (
                 create => 'yes',
                 mode => 0644,
                 exclusive => 0,
                 destroy => 'yes'
               );
my $index;

my $HANDLE = tie %hash, 'IPC::Shareable', 'data', { %options };

for($index=1; $index <= 7; $index++) {

    print "Spawning process: $index\n";

    $forkman->start and next;
    do_this($index);
    $forkman->finish;

}

$forkman->wait_all_children;

print "All children are done\n";

foreach $key (sort keys %hash) {

    print "PID of process $key = $hash{$key}\n";

}


sub do_this {
    my $index = $_[0];

    $HANDLE->shlock();
    $hash{$index} = "PID: $$";
    $hash{'test'}{'test'} = 'test';
    $HANDLE->shunlock();

    return 0;

}
0
Comment
Question by:ventolin
6 Comments
 
LVL 2

Author Comment

by:ventolin
ID: 9681709
See the man pages for 'ipcs' and 'ipcrm' for more info.
0
 
LVL 2

Expert Comment

by:icrf
ID: 9835297
Did you ever get this one figured out? I found it and started playing today and didn't make much headway.

If I manually "tie %{$hash{'test'}}" before forking, it doesn't leak, but according to the docs, it's supposed to automagically tie references. If I let it automagically create it and then I manually destroy it "(tied %{$hash{test}})->remove" when it's all over, it doesn't leak. It sounds like the destory option isn't recursing through the tree as it should, but even calling clean_up or clean_up_all doesn't help, and they're supposed to destroy everything the current process created or encoutered.

Unless I'm implementing wrong, there's some serious issues with that module cleaning up after itself. Granted, it's designed for interprocess communication and it leaves the variables available for future processes to use, but they should go when implicitly told.
0
 
LVL 20

Expert Comment

by:jmcg
ID: 10093645
Nothing has happened on this question in more than 6 weeks. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by icrf [grade B] (advice but not a solution).

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 2

Author Comment

by:ventolin
ID: 10097154
You guys can go ahead an clean this up, but it still hasn't been answered to my satisfaction.
0
 
LVL 20

Expert Comment

by:jmcg
ID: 10097263
Ventolin,

You have the option of requesting the question be closed (I'd recommend as a PAQ) and your points refunded. Just post a 0-point question in Community Support and a moderator will take a look.

I agree that you haven't been given a fully satisfactory answer, but after looking at the documentation myself and reading about icrm's experiments, I judged that he had done some work worth rewarding. I generally recommend a B grade on "answers" that are only steps along the road to an apparent solution. You, as the asker, can certainly disagree and the moderators are likely to give your desires more weight than my recommendation.

You might also like to try asking again, perhaps with more details. There has been a recent influx of new experts who might be interested in your problem.
0
 

Accepted Solution

by:
PashaMod earned 0 total points
ID: 10099030
PAQed, with points refunded (500)

PashaMod
Community Support Moderator
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question