Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Re: 3 weeks wasted? - will threads help?

by Limbic~Region (Chancellor)
on Jan 27, 2003 at 22:35 UTC ( [id://230382]=note: print w/replies, xml ) Need Help??


in reply to Re: 3 weeks wasted? - will threads help?
in thread 3 weeks wasted? - will threads help?

Fair enough....

In my readmore tags - I explained that each copy works on a different directory - each directory is very transient and that is a race condition beyond my control

The extra memory overhead is coming from the Perl intrepreter - not the code itself (or at least that is my belief) - see below:

#!/usr/bin/perl -w use strict; while (1) { print "I am only printing and sleeping\n"; sleep 1; }

The above code shows up in ps -el with almost the same sz as the code in my readmore tags

Forking will not buy me anything as I understand it since I will be making an exact duplicate (memory and all). I was thinking threads may help, but as I understand them - each thread gets its own copy of the intrpreter - no memory savings either

So my question stated more clearly is:

Given a piece of code to parse a single directory, how can I parse multiple directories concurrently (or very nearly) without the memory overhead of each piece requiring its own intrepreter?
Concatenating the files in each directory into one long list isn't feasible either.

I freely admit that I may be asking to get something for nothing, but it seems like an awful waste not to be able to use the Perl code and continue using the shell script :-(

Cheers - L~R

Replies are listed 'Best First'.
Re: Re: Re: 3 weeks wasted? - will threads help?
by perrin (Chancellor) on Jan 27, 2003 at 22:57 UTC
    Actually, forking will buy you a lot. You are not understanding what I said about copy-on-write. On a modern OS, when you fork the memory is not actually copied. Only pages that get changed are copied, and the rest is shared between processes. It makes a huge difference and is something that is widely used with mod_perl to reduce the memory overhead of multiple Perl interpreters.
      Ok - so maybe it is the ps command that I am not understanding

      I set up a little program to fork two copies of itself up at the top and then in the main body, do nothing more than

      while (1) { print "I am only printing and sleeping\n"; sleep 1; }

      Performing a ps -el showed each processes' sz as though I had executed each one separately. Maybe I am using the wrong tool to determine how much total memory each process is taking away from the system.

      I am going to look into POE as was suggested by adrianh, but it seems forking would be a whole lot easier. Is there a way for me to benchmark the difference in total process memory utilization between:

    • Launching each process individually with two separate args
    • Having one program fork itself with the two separate args
    • Re-writing with POE to only have one process do all the work

      Thanks for the insight and cheers - L~R

        If you look at the SHARE column in top (it may be there in your ps as well), you will see how much of that size is actually shared. More info is available here.
Re^3: 3 weeks wasted? - will threads help?
by adrianh (Chancellor) on Jan 27, 2003 at 22:49 UTC
    Given a piece of code to parse a single directory, how can I parse multiple directories concurrently (or very nearly) without the memory overhead of each piece requiring its own intrepreter? Concatenating the files in each directory into one long list isn't feasible either.

    I'd probably switch to an event-based model - maybe use POE. Threads are probably not what you want in this instance. At the moment Perl's threads are fairly heavy and slow - more like wet string :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://230382]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-03-29 01:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found