Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: TCP Socket, Forking, Memory exhaustion

by BrowserUk (Patriarch)
on Nov 07, 2007 at 11:03 UTC ( #649453=note: print w/replies, xml ) Need Help??


in reply to TCP Socket, Forking, Memory exhaustion

Are you sure that forking a script doubles your memory usage?

I thought that on most systems running a second copy of a program, perl in this case, would only increase overall memory usage by the size of the read-write data area only. As the readonly data and code memory would be shared by the processes. Ditto for all subsequent copies.

If you're using something like top or PS to assess the memory usage, it may be telling you porkies. Try starting one copy and then record the total free memory figure. Then start a second copy and record the total free memory figure again. The difference will be your actual per process consumption, which in many cases will be far less that the figure suggested by ps/top.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re: TCP Socket, Forking, Memory exhaustion

Replies are listed 'Best First'.
Re^2: TCP Socket, Forking, Memory exhaustion
by oha (Friar) on Nov 07, 2007 at 16:48 UTC
    it's called copy on write. all the pages used by process are marked this way, whenever one of the process forked try to write to that page a trap is raised and the OS copy the page.

    Oha

      Yes I know. (On Unix that is. They are just "shared memory segments" on Win32 for example).

      But it's not as beneficial as people think for perl processes, because "compiled" Perl code and Perl program data, are both RW memory to the perl executable. And even read references to perl variables can caused write accesses (and therefore COW) to the memory that holds them.

      But the main point of my post is that ps/top will often, if not always, count the shared, readonly memory (the perl executable's code and RO data) against each process that shares it, which may be giving the OP a false impression of how much memory is consumed by his existing forking solution.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2022-05-16 22:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (63 votes). Check out past polls.

    Notices?