Re: help with huge memory consumption??
- From: Chris Friesen <cbf123@xxxxxxxxxxxxx>
- Date: Fri, 09 Mar 2007 17:57:25 -0600
David Schwartz wrote:
...thread creation is in no way analogous to process creation.
There is no case where you think, "hmm, I could create a thread or a
process, I wonder which is cheaper". So it's nonsensical to compare
their costs.
Sure there is. Given a parallel task that can be done with threads, there is almost always an equivalent way to do that task using separate processes with shared memory, unix sockets, etc.
It means that you need to create a thread when, and only when, you
need more threads than you have already created. However, you need to
create a process not just when you need more processes but when you
need different processes.
While POSIX has defined threads and processes in a particular way, from an implementation level in linux they are fundamentally a schedulable entity that shares various amounts of data with other schedulable entities. Threads share almost everything, processes share almost nothing. You can create wierd hybrids that are partway in between.
As a trivial example, consider a thread pool versus a 'fork after
accept' server. The thread pool server will create some maximum number
of threads over its life and will reuse them. The cost of a thread
creation per client is effectively nearly zero. A 'fork after accept'
server will create one process for each client it handles. The cost of
a process creation is a per connection cost.
As has been mentioned in another post, there is nothing stopping you from creating a "process pool" equivalent. From the other direction, there is nothing stopping you from making a "pthread_create after accept" version.
So it makes no sense whatsoever to compare the cost of one to the cost
of the other. There is essentially no actual circumstance where one
has the choice to do one or do the other the same number of times.
Sure there are.
Suppose you want to simultaneously issue statfs() calls for each filesystem on the machine. One method would be to set up a shared memory mapping for the results and fork() one process for each filesystem. Alternately, you could pthread_create() one thread for each filesystem. The two are equivalent. There is slightly more overhead involved in the fork() version, but the result is the same.
Alternately, suppose you have a long-running compute process, which updates a display periodically. This could be implemented as two threads, one for the compute and the other driving the GUI. Alternately, it could be done via two separate processes communicating via sockets.
Chris
.
- Follow-Ups:
- Re: help with huge memory consumption??
- From: phil-news-nospam
- Re: help with huge memory consumption??
- From: David Schwartz
- Re: help with huge memory consumption??
- References:
- help with huge memory consumption??
- From: Dan Miller
- Re: help with huge memory consumption??
- From: Robert Redelmeier
- Re: help with huge memory consumption??
- From: Rainer Weikusat
- Re: help with huge memory consumption??
- From: Robert Redelmeier
- Re: help with huge memory consumption??
- From: Rainer Weikusat
- Re: help with huge memory consumption??
- From: Robert Redelmeier
- Re: help with huge memory consumption??
- From: Rainer Weikusat
- Re: help with huge memory consumption??
- From: Robert Redelmeier
- Re: help with huge memory consumption??
- From: Michel Talon
- Re: help with huge memory consumption??
- From: phil-news-nospam
- Re: help with huge memory consumption??
- From: David Schwartz
- Re: help with huge memory consumption??
- From: phil-news-nospam
- Re: help with huge memory consumption??
- From: David Schwartz
- Re: help with huge memory consumption??
- From: Rainer Weikusat
- Re: help with huge memory consumption??
- From: David Schwartz
- Re: help with huge memory consumption??
- From: Rainer Weikusat
- Re: help with huge memory consumption??
- From: David Schwartz
- help with huge memory consumption??
- Prev by Date: Re: help with huge memory consumption??
- Next by Date: Re: help with huge memory consumption??
- Previous by thread: Re: help with huge memory consumption??
- Next by thread: Re: help with huge memory consumption??
- Index(es):
Relevant Pages
|