Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: 3 weeks wasted? - will threads help?

by perrin (Chancellor)
on Jan 27, 2003 at 22:11 UTC ( [id://230366]=note: print w/replies, xml ) Need Help??


in reply to 3 weeks wasted? - will threads help?

I really don't understand your statement about needing to run 20 copies of the script because of a race condition, but if you want to save memory you should try starting up one script and forking rather than starting 20 different copies of Perl. The copy-on-write nature of memory handling in modern OSes will save you quite a bit of RAM.
  • Comment on Re: 3 weeks wasted? - will threads help?

Replies are listed 'Best First'.
Re: Re: 3 weeks wasted? - will threads help?
by Limbic~Region (Chancellor) on Jan 27, 2003 at 22:35 UTC
    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

      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

      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://230366]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-19 04:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found