Best communication method to thousand childs?

This is a discussion on Best communication method to thousand childs? within the C Programming forums, part of the General Programming Boards category; I am doing a project in which i have a father, that can have several children. From time to time ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    35

    Best communication method to thousand childs?

    I am doing a project in which i have a father, that can have several children. From time to time i have to send a command to one of the children.

    I can do this in several ways, but i want to learn a bit more, so i want to do it a way which is efficient, even if there are thousands of children.

    Method 1: One pipe to each child. Very fast, but takes up resources (and seems to me limited to 510 pipes)

    Method 2: Shared memory in which i place the child name. father unlocks a semaphore, and all children read from shared memory, the one that finds it's name in the memory segment executes the command also placed in the memory. Very low constant memory usage (only one shared memory segment), but a peak in memory usage because all the children will try to access the memory at the same time.

    Method 3: One pipe to whom's exit is available to all the children. when father puts a message in the pipe it sends a signal to the child it is intended for, so that that child and only that one reads from the pipe. Very low constant memory usage, but i fear that if the messages are to many it slows down the computer because of to many signals beeing sent(my interpretation of signals is that they almost freeze to computer, so sending the in rapid succession takes up lot's of resources).

    I am mostly divided between Method 1 and 3. It seems 1 is better if there are many commands, while 3 is better for larger number of children and not so many commands.

    I would like opinions, as to my conclusions are correct or not, and which method you would use if there were thousands of children .

    Thank You
    Last edited by Ironic; 11-07-2008 at 09:53 AM.

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    I would guess a combination of both method 1 and 3. I don't know to give exact numbers, but if lets say 20 pipes isn't consider a lot of resourses, then you can use 20 pipes and give every 50 children a pipe. All or nothing wouldn't be the best option

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,687
    IMO, if you've got that many child processes, you've got bigger things to worry about.

    It's called "Re-arranging the deck chairs on the Titanic".
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    35
    What do you mean?

    In my pc it creates about 8000 children. It's slow but it works.

    But the point of this, is what would be more efficient for larger numbers, and with a lot more powerful computer.

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,680
    You could just use signals. kill() can send a signal to an individual process ID or process group ID.

    gg

  6. #6
    Registered User
    Join Date
    Oct 2008
    Posts
    35
    the problem is that signals are slow , because they generate interrupts. if i had to send many commands i would slow down a lot.

  7. #7
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Signals require less resources than pipes and if I am not mistaken they are not any slower than pipes.

  8. #8
    Registered User
    Join Date
    Oct 2008
    Posts
    35
    the use of signals is good because they dont take up any resources like a pipe when it is not beiing used.
    but the problem is that a signal generates an interrupt. it halts current execution, variables have to be saved, and execution jumps to signal handler and etc . that is why i think that sending a message via a pipe is faster them sending and handling a signal

  9. #9
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,680
    http://www.linuxjournal.com/article/3985

    Signals aren't as slow as you think they are.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 05-05-2009, 04:53 PM
  2. on method pointers and inheritance
    By BrownB in forum C++ Programming
    Replies: 2
    Last Post: 03-02-2009, 06:50 PM
  3. C# method
    By siten0308 in forum C# Programming
    Replies: 6
    Last Post: 07-15-2008, 07:01 AM
  4. Delegate Calling a method that Calls a delegate.
    By xddxogm3 in forum C# Programming
    Replies: 2
    Last Post: 05-05-2008, 12:59 AM
  5. help with threads communication
    By BrownB in forum C++ Programming
    Replies: 3
    Last Post: 05-23-2006, 03:37 AM

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