in reply to Re: Threads, Forks, or Nothing?
in thread Threads, Forks, or Nothing?

One reader and multiple writers is exactly what I am trying to do. The idea with threads was to have one thread as the reader and another thread to control the writers using a shared memory space. What you suggested is essentially what I am doing now...
in pseudo code while (1) if accept (non blocking) initialize writer add Ptr to writer hash if %writer read_cell (atm cells) foreach connection %writer if lifetime of writer exceeded undef $writer{connection} next write cell and then back through the loop.
The problem is that initializing a writer takes a non zero amount of time. During this period we can't read any cells off the interface and at OC3 and OC12 speeds (which is what we are dealing with) it can be a significant bit of data lost. So the ideal solution would be to off load the writer initialization and handling to another thread so that existing writers wouldn't have the data flow interrupted.

The goal is to have a server that can gracefully handle gigabit speeds and more than 5 writers at a time.

Also, as I stated, I do not think forking can work. I can only have one reader on an interface at a time. If there is some way to only fork a subroutine I'm all ears (eyes, whatever).

Replies are listed 'Best First'.
(Jepri)Re: Threads, Forks, or Nothing?
by jepri (Parson) on Aug 16, 2001 at 14:11 UTC
    The trick there is to have your children ready before you accept. Basically you fork multiple times, then the parent sits on the socket. The moment you get a connection you just start writing to the children. In this case you would probably just have the children blocking on reads from the pipe to the parent.

    The Apache webserver does this to improve it's response times to connections. If you look at the process table while apache is running, you will see MAX_SERVERS + 1 processes. That's the parent with MAX_SERVERS children standing by.

    ____________________
    Jeremy
    I didn't believe in evil until I dated it.