Suppose a application level protocol is implemented via UDP. Client timeout is required, thus server need to keep state of each client it talks to.
Also suppose select is used.
-
Is it always the best to implement multi-threading server? I figure a link-list will do the same, where server timeout
time=Earliest Timeout of a client- CurrentTime. A link-list will have the same function as keeping client’s states, while avoiding the overhead of creating new threads(though introducing some complexity for server to maintain client-specific timeout). -
If multi-threading is chosen, then onward, is it the best to invoke new socket for new client? This will introduce system resource overhead. But I figure the default server socket (
bindwith server well-known port) will do the same since it got buffer (well..maybe not long enough for scalable num of clients..)
Thanks!
I’m not going to suggest anything new that isn’t in the answer by Aidan Cully, however, take a look at the theory behind Apache’s Multi Processing Modules: http://www.linuxquestions.org/linux/answers/Networking/Multi_Processing_Module_in_Apache
In essence, the server is split into multiple modules and threads/processes are created to manage connections, depending on need and configuration options – it sounds like the balance described in Aidan’s answer although the Apache implementation may differ slightly.