Reputation: 53
I am working on a project to develop an high performance tcp server and I decided to use epoll and multi-threading. But I find it difficult in designing server and now I am quite puzzled with this two designs:
one dispatcher, some workers, the dispatcher listen on all connections using epoll and dispatches incoming datas to workers, workers handle no IO event.
one listener, only deal with listening event, and when a new connection is coming, it accepts it and dispatch it to a worker, every worker has an epoll fd and then listen to this new socket.
witch one is better, or any better designs ?
thanks!
Upvotes: 3
Views: 1682
Reputation: 33817
libevent will be very useful here. It was born to solve your problem. Build a proof of concept, feed it with maximum load you expect and measure where is the real bottleneck. Then optimize - "Premature optimization is the root of all evil"
Upvotes: 2
Reputation: 7346
In general it's very difficult to come up with a high performance architecture that doesn't make too many assumptions about the connections.
I have tried to some work in that area and some information is available at http://nginetd.cmeerw.org
Basically, I am using a single epoll
fd (in edge-triggered mode) with a single thread pool. That means that each thread can do any work (accepting new connections, reading data, processing requests, sending replies) and therefore no additional thread context switches are needed. The main challenge with this architecture is to get synchronization just about right so you minimize contention, but still don't get any race conditions.
Upvotes: 2
Reputation: 10938
There is no simple answer. What type of server do you want ?
What server(machine) will you use (128 x weak cpu/8 x powerful cpu ) ?
More universal is: one dispatcher, some workers, the dispatcher listen on all connections using epoll and dispatches incoming datas to workers, workers handle no IO event
Upvotes: 4