My final pass has me separating each MySQL query into a separate perl process spawned by system(). (Yes, I could have fork()ed, but this is easier and more maintainable.)
It might be easier (if you don't grok fork()) but I doubt it's more maintainable. With system() you have to keep track of the path to the programs to run in sub-processes. With fork() everything stays in one script and you don't need to track a dependency.
Krang uses fork() to deal with a similar problem - memory usage in large publishing jobs. It's definitely a technique that every *nix hacker should have in his toolbox.
-sam
| [reply] |
Even when you undefine variables, the memory used is not returned to the operating system until the process terminates
I'm not a FreeBSD user (so this may or may not be true), but usually the OS can reclaim memory that's munmap'ed. Of course you'd also need a special version of perl that used mmap instead of malloc, and each variable would take a VM page of storage (4k on x86), but that's another story.
| [reply] |
I believe if you use the system malloc(3) on FreeBSD rather than Perl's then memory does get returned to the OS when free(3) gets called.
Update: Well, it's not working on my FreeBSD 5.0 box but it does on a Tiger box; both have usemymalloc='n'. Strange . . .
| [reply] |
Why did my memory usage go over the top?
Because of a race condition in MySQL on BSD.
| [reply] |