I/O multiplexing mode vs. thread concurrency mode

Source: Internet
Author: User

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.