A high-performance server, it is necessary to solve the problem of IO multiplexing and multi-threaded services, this article in the study of "pattern-oriented software architecture-concurrent and networked object mode" after a little experience.
1.i/o multiplexing Mode:
Implemented using Select or poll or Epoll system-level functions in conventional I/O multiplexing, the multiplexed patterns formed based on these functions are reactor and proactor patterns. The implementation mechanism of this pattern is to register the event in reactor, and when the resource required for the event is ready reactor will go back to the function that was registered to reactor, without polling all the event sources, or blocking any single event source indefinitely. Can handle multiple synchronization events from multiple event sources. Through the implementation mechanism of reactor, we can see that the problem solved by reactor is to distribute the multi-user large concurrent access back-end service, and distribute it to the various service threads on the backend.
2. Multithreaded service mode:
The above mentioned multiplexing of Io, that is, multi-user high concurrent access to the service side of the distribution mode, when the client's request distribution to the backend service thread to its processing, multi-threaded service mode is mainly: semi-synchronous semi-asynchronous mode, leader/follower mode. These two modes mainly solve the multi-threaded mechanism of their respective operation.
3. Three technology evolution of multi-concurrency service model
First, the basic socket programming is blocking/synchronizing (the APIs such as accept, read, and write are blocked by default), and each operation is returned unless it is completed or an error occurs, so that for each request, a thread or a separate process is used to process the system resources cannot support a large number of requests. Second, the API to set the socket is asynchronous, using a blocking system function Select or poll to detect whether the handle FD is read/write at the same time, but because it uses polling to determine if an FD becomes active, the efficiency is not high O (n). The third type of system invocation, based on asynchronous/callback, such as the IOCP of the Linux Epoll,bsd kqueue,windows. Because of the support at the kernel level, it is possible to find the active FD in the Efficiency of O (1).
4. Excerpt from Chapter 4.1 of Sun Weichen, editor-in-chief, "Java Network programming Refinement":
Refer to: 1. Socket programming pattern understanding and contrast 2.http://www.yeolar.com/note/2012/12/15/high-performance-io-design-patterns/