Messages in this thread | | | From | "Darius S. Naqvi" <> | Subject | Re: Linus on Linux, Apache and Threads | Date | Sun, 25 Apr 1999 02:02:31 -0600 (MDT) |
| |
> > On Fri, 23 Apr 1999, Ian D Romanick wrote: > > > Huh? It's not that hard of a problem. You have one (or several) thread > > > that just reads from network sockets. They package up the requests and put > > > them on the end of a queue. The other threads just pull requests off the > > > head of the queue. > > > > i wasn't trying to suggest it was hard to code or understand. my question > > is how to do this efficiently. has anyone compared the performance of > > this model with the performance of the same application implemented > > using NT's completion ports? > > > > every Unix model i've seen that uses the "single thread waits for event > > and wakes up worker threads" has suffered from a variety of problems that > > can cripple its performance, like: > > > > how does the event waiter thread determine whether there is a > > suitable/idle worker thread to awaken? > > > > > The trick is all in waking up the sleeping threads when > > > the queue becomes non-empty without having the "thundering herd" problem. > > > > agreed! any ideas? > > It could be done several ways. Does Linux have Tanenbaum style up/down > semaphores? If not, it shouldn't be too hard to do using pthread_mutex. > Each time an element is put on the event queue, you up the semaphore. > Before getting the dequeue lock on the queue, the thread would down the > semaphore. >
Yes, pthreads, including the Linux implementation thereof, has POSIX semaphores, which are "up/down" in style. Create with sem_init(), down with sem_wait(), up with sem_post(). So when there is nothing in the queue, all worker threads will be blocked in sem_wait(), and when a single element is put on the event queue, you call sem_post(), which should wake up exactly one worker thread.
-- Darius S. Naqvi email(home): dsn@scrap.myrias.com email(work): dsn@myrias.com
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |