Epoll et and Lt Modes

Source: Internet
Author: User
Tags epoll
Epoll et and Lt Modes
Recently I continue to learn about the epoll working mode. This will be basically clear, so I wrote this document to describe it. Here is an online Introduction:
Epoll event distribution systems can run in two modes: edge triggered (ET) and level triggered (LT ).
Lt is the default working method, and supports both block and no-block socket. In this way, the kernel tells you whether a file descriptor is ready, then you can perform Io operations on the ready FD. If you do not perform any operation, the kernel will continue to inform you, so the possibility of programming errors in this mode is lower. The traditional select/poll model is representative of this model.
Et only supports no-block socket. In this mode, when the descriptor is never ready, the kernel tells you through epoll. Then it will assume that you know that the file descriptor is ready and no more ready notifications will be sent for that file descriptor, until you do some operations, the file descriptor is no longer ready. However, please note that the kernel will not send more notifications if I/O operations are not performed on this FD all the time, which may cause it to become idle again.
The following is what I want to talk about. Since the et mode is a high-speed mode, we must use it for server development, I have not found the method for setting the et mode. How can I set and use it? Through repeated tests, I finally figured out that "epollet" is the et mode setting. Maybe I am too stupid to be confused for so long. The following is the association of TCP socket hsocket and epoll. Code :
Struct epoll_event struevent;
Struevent. Events = epollin | epollout | epollet;
Struevent. Data. FD = hsocket;
Epoll_ctl (m_hepoll, epoll_ctl_add, hsocket, & struevent );
If you associate the listening socket m_hlistensocket with epoll, the Code is as follows:
Struct epoll_event struevent;
Struevent. Events = epollin | epollet;
Struevent. Data. FD = m_hlistensocket;
Epoll_ctl (m_hepoll, epoll_ctl_add, m_hlistensocket, & struevent );
If you want to use the <mode, you can directly change the event value to the following. Maybe this is the default value.
Struevent. Events = epollin | epollout; // user TCP socket
Struevent. Events = epollin; // listens to TCP sockets
However, according to my tests, the performance gap between the two modes is still very large, which can be up to 10 times. The stress tests for 100 connections are the same in other environments. The CPU consumption in the LT mode is 99%, and the et mode is 15%.

 

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.