multithreading - Better approach for having two or more threads listening on same port -
dears,
i'm working on network server application. plan have 1 thread each server's core handling clients connections in order better use of server's resources , faster responses, avoid blocking, etc.
from know, there 2 ways of doing it:
1) parent process opens listening socket , each thread monitors (epoll, kqueue, etc.) new connections , accept()
them;
2) each thread opens own listener socket on same port , address (possible so_reuseport , so_reuseaddr), monitor new connections , accept()
them.
i'm not sure how works behind scenes, suppose doing #2 delegate kernel networking section task of distributing client connections on threads. correct?
is there significant difference between 2 approaches? there can go wrong in way of doing whereas doesn't happens in other? better results (less resources usage, less latency, etc.) doing in specific way instead of another?
i think way see difference between 2 approaches comparison generating huge amount of connections, poor computer can't deal it. fall on experience , knowledge answer question. in advance help.
1) parent process opens listening socket , each thread monitors (epoll, kqueue, etc.) new connections , accept() them;
you can that, there's not lot of benefit on having single accept()
thread , thread pool. , have races between accepting threads 1 of them win @ time (the 'thundering herd' problem).
2) each thread opens own listener socket on same port , address (possible so_reuseport , so_reuseaddr), monitor new connections ,
accept()
them.
you can't tcp unless on windows, semantics far can tell undefined.
Comments
Post a Comment