kafka multiplexing mechanism used reactor
The traditional mechanism, a connecting thread: when a large number of connections, corresponding to the number of processing threads is also a great server inevitably overwhelmed. If there is a million connections, then the corresponding ten thousand threads to deal with.
reactor mechanisms:
1. acceptor consists of a thread monitor establishing a connection, the connection is established, the thread delivered to the process;
2.process threads, have a plurality, each process thread corresponding to some of the connections (similar to a database, a film was obtained in a manner of id sub-table);
3.process receiving the connection thread, delivered to the unified "request queue", the pending;
4. The thread pool real process, the consumer will take the initiative to "request queue", the consumption is completed, the response will throw "response queue" in;
5. eventually, process will get a response from their own "response queue" sent back to the client.
If there are ten thousand connections, use the reactor mechanism, requires only one acceptor thread threads +100 + 10 process threads (thread pool thread processing, step 4). The number of threads can plummet from 10000-100 this level.
Summary: kafka the reactor mechanism, saving the number of threads, the number of connections is constant.