http://www.perlmonks.org?node_id=863796

flexvault has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

Is there a way to prevent garbage collection in a process until the process finishes it's current work. I can block signals at the start of the process, and then enable them at completion of the cycle, and then wait for more work. Is there anything similar for garbage collection?

Most of our processes work for .11 to .25 seconds, so they are persistent but not working for a long time. Enabling the garbage collection just before the 'accept' and disabling while working would prevent losing information during the process.

Background: Originally I did something like this:

my %Account = (); my $accptr = \%Account; my $work = $input ## Whatever needed to be done my $ret = &GetAccount($accptr); my $html = &CallChildToWork($accptr,\$work);

Obviously, a lot of the work is missing and subroutine 'CallChildToWork' will call other subroutines, and that's where we got problems. It worked 100% in testing. But in production, after some random time '$accptr' would be lost in a subroutine and then return in the caller routine. We verified this with 'syslog' by logging '$accptr' on subroutine entrance and again on return. It would be there on entrance and gone on return. This never cause a failure, just missing results. Here, just a guess, that it had to do with scope and garbage collection.

We solved this by making '%Account' global, and subroutines copy between '%Account' and '%TAccount'. This works 100% in production, but requires locking and unlocking the copy process. Since a second is finite, we are limiting the number of processes and cores that can be used in production.

Thank you

"Well done is better than well said." - Benjamin Franklin


Update: Resolved!

Upon testing with Perl 5.12.2, this problem no longer exists!