in reply to When to use forks, when to use threads ...?
after trying for days to overcome a memory-leak problem
Care to expand on that ? You are aware that Perl maintains its own heap, and doesn't release memory once it acquires it from the runtime heap ? Which, from external monitoring apps, may make it appear that you've got a memory leak, when in fact Perl is just doing its thing.
That said, when doing big load jobs into DBMS's, there are any number of potential concurrency pitfalls, some of which will occur in both forked and threaded environments (possibly because they occur in the DBMS itself). YMMV.
Perl Contrarian & SQL fanboy
Re^2: When to use forks, when to use threads ...?
by zentara (Cardinal) on Sep 04, 2008 at 18:13 UTC
|
Ah... I just posted a node about Perl releasing memory back to the system when using threads... see OS memory reclamation with threads on linux From my previous experimentation, it was almost certain that Perl would hold onto the memory, but that may have been because I was testing at a "sweet spot" where Perl's calculations of free memory-vs-it's use allowed it to retain the memory. But when it is very high mem usage, Perl will release it.
It's a crap shoot, and may depend on Perl versions, thread versions, and even the kernel.But the gist is, Perl will release large memory chunks if it's in a thread. And the c guru said that top and ps cannot always be trusted as an accurate measure of mem use. So I would ask, as your memory climbed, did the system slowdown, or did things keep running normally.
| [reply] |
|
So I would ask, as your memory climbed, did the system slowdown, or did things keep running normally.
I watched the RES column from ps's output, first via top, then also using a code snippet taken out from Process::MaxSize like
[...]
my $size;
open PIPE, "/bin/ps wwaxo 'pid,rss' |";
while(<PIPE>) {
next unless /^\s*$$\s/;
s/^\s+//g;
chomp;
$size = (split(' ', $_))[1];
}
close PIPE;
return $size;
}
I didn't wait to let the system really slowdown, but stopped when it became obvious that swapping would have to start.
| [reply] [d/l] |
Re^2: When to use forks, when to use threads ...?
by Krambambuli (Curate) on Sep 05, 2008 at 08:03 UTC
|
Care to expand on that ?
Well, I'm not sure how to do that efficiently, it's a rather convoluted story - my baseline so far is that I will avoid for now and the near future to try using threads for parallelizing conditional-insert-or-updates into Oracle.
The base problem is something like 'given a (rather big) amount of new data, add it to the existent tables that are holding it, inserting or updating if similar records are already there. Speed up the process so that it gets done as fast as possible.'
What I seem to have so far is that Oracle's libclntsh.so in conjunction with Perl threads will loose 4 or 8 bytes on every thread-switch. Which thread to use depends on the input record.
| [reply] |
|
| [reply] |
|
|