user1920949
user1920949

Reputation: 53

architecture of high performance an tcp server

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

Answers (4)

Jakub M.
Jakub M.

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

cmeerw
cmeerw

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

baklarz2048
baklarz2048

Reputation: 10938

There is no simple answer. What type of server do you want ?

  1. many parallel short connections (standard www)
  2. many parallel quite long connections (small to medium uploads)
  3. mix of 1 and 2
  4. very long heavy connections (big uploads)

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

kmkaplan
kmkaplan

Reputation: 18960

A very good resource on the subject is The C10K problem.

Upvotes: 1

Related Questions