Multiplexed Server Model

Source: Internet
Author: User
Tags epoll

Select Module function: Select System call is used to detect multiple file description state changes, the program will always wait in the select until the time-out or the monitored file descriptor in one or more state changes.

Select function: Select (Rlist,wlist,xlist[,timeout]), return value: (rlist,wlist,xlist)

Rlist: Read the socket list to determine if there is a readable socket;

Wlist: Write the socket list to determine if there is a socket that can be written;

Xlist: Abnormal socket list, to determine if there is an abnormal socket;

If a socket can be read, writable, or abnormal, select returns the corresponding socket list

Select how to determine the readable:

    1. Add the detected socket to the rlist, and then call Select to wait for the data;
    2. If there is a client connection or data, then select will return immediately;
    3. If it is a new link call accept accepts a new socket and counts the socket into rlist or wlist;
    4. If there is data, then receive the data;

Select how to determine what can be written:

    1. The detected socket is added to the wlist, and the select Wait is called;
    2. If the socket can be written, return the list of sockets that can be written;
    3. Call the Send method to send the data;

Select how to determine the exception:

    1. The detected socket is added to the xlist, and the select Wait is called;
    2. If the socket has an exception, the Xlist list of exceptions is returned;
    3. handle abnormal sockets;

Select Multiplexing server Advantages and disadvantages:

Advantages:

    1. There is no need to create and destroy processes and threads frequently, which saves the overhead and burden of the system.
    2. Select uses rotation method to process the data, processing efficiency is higher than multi-process and multi-threading model;

Disadvantages:

    1. Maximum file descriptor for a process monitor (system default of 1024)
    2. Need to maintain a list of file descriptors
    3. The scan for file descriptors is linear, and the time is increased each time the structure is scanned
    4. The kernel notifies the user space of the file descriptor message to be copied;

Epoll mode

    1. is an enhanced version of the Select/poll MUX IO interface in Linux
    2. The maximum number of files that can be opened is the upper limit of the file descriptors it supports
    3. Epoll only operates on "active" sockets and does not result in a linear decrease in efficiency due to the increase in file descriptors
    4. Epoll is implemented by the kernel in the user space mmap the same piece of memory, using MMAP to accelerate the kernel and user space message delivery;

Multiplexed Server Model

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.