|Just another Perl shrine|
Postpone garbage collection during a child process run?by flexvault (Prior)
|on Oct 06, 2010 at 14:27 UTC||Need Help??|
flexvault has asked for the
wisdom of the Perl Monks concerning the following question:
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:
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.
"Well done is better than well said." - Benjamin Franklin
Upon testing with Perl 5.12.2, this problem no longer exists!