Mutiple processes and threads: Why?

This is a discussion on Mutiple processes and threads: Why? within the Tech Board forums, part of the Community Boards category; A lot of daemons like to run separate processes to handle a lot of the same thing (like HTTP requests, ...

  1. #1
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,605

    Mutiple processes and threads: Why?

    A lot of daemons like to run separate processes to handle a lot of the same thing (like HTTP requests, for example), the same with threads, only I know each thread can handle more than one request at a time (event driven).

    So why? If one thread, let alone one process, can handle multiple requests (and running a single thread for each request is considered bad), why even have more than one of each? Couldn't you theoretically just pump up the given CPU time of your thread to match that of several normal threads and/or other processes, and just do it all through there?
    Why so split up, and yet not completely split up?
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Because it's often better to complete 10 tasks concurrently than sequentially (eg, with HTTP requests, and jail sentences). This way, everybody gets a consistent stream of packets rather than in erratic bursts. Under severe load, this could be the difference between a slow connection and no connection.
    Last edited by MK27; 02-26-2010 at 05:55 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    412
    It's also for scalability. Not everyone is running a single cpu desktop computer.
    Imagine trying to run for example apache on a 64 cpu computer if apache were a single-thread single-process application.. Now you'd basically have 63 wasted cpus

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    As others said, a single process can't utilize all the cores available, even if it multiplexes many clients. A situation with lots of clients is a situation where you want all cores to be in use.

    On most OS's, there is a limit on the number of open file descriptors a process can have. Depending on the threading model, this limit might be shared between threads. So multiple real processes might be required.

    Also, operating system's facilities for multiplexing IO requests (the infamous "select()" and "poll()" functions) do not always scale very well when handling hundreds or thousands of connections.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using Multi-threading and/or Multi-process
    By lehe in forum C++ Programming
    Replies: 5
    Last Post: 07-14-2009, 11:43 AM
  2. threads and Real-time processes
    By inhahe in forum Windows Programming
    Replies: 5
    Last Post: 05-14-2008, 04:17 PM
  3. Replies: 1
    Last Post: 10-24-2005, 06:35 AM
  4. Threads and Processes
    By Draco in forum Tech Board
    Replies: 3
    Last Post: 11-09-2003, 02:48 AM
  5. 5158 handles, 300 threads, and 23 processes
    By Invincible in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 06-06-2002, 04:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21