Edge Triggered (ET) mode is an operational mode of epoll under Linux, as opposed to Level Triggered (LT) mode. Its primary purpose is to enhance event handling efficiency, minimize the number of system calls, and improve overall system performance.
In Level Triggered mode, as long as the monitored file descriptor remains in a readable or writable state, epoll_wait() continuously returns it, requiring the program to repeatedly call epoll_wait() to check the file descriptor's status. This can result in numerous unnecessary system calls.
In Edge Triggered mode, epoll_wait() returns the file descriptor only when its state changes (from unreadable/unwritable to readable/writable). Upon notification, the program should process all available data (e.g., reading until EAGAIN is returned) until no more data can be processed. This significantly reduces the number of epoll_wait() calls, thereby lowering resource consumption and improving efficiency.
Example
Consider developing a high-concurrency network server that needs to handle thousands of concurrent TCP connections. If using Level Triggered mode, the server may need to repeatedly inspect each connection to determine if data can be read or written, leading to numerous system calls. If using Edge Triggered mode, epoll_wait() only notifies the server when the TCP connection state changes (e.g., new data arrives), allowing the server to process as much data as possible in each notification, reducing the number of system calls and improving processing efficiency.
In summary, Edge Triggered mode notifies the application only when a substantive change occurs in I/O state, enabling the application to handle I/O events more efficiently, particularly when managing a large number of concurrent connections. This advantage is especially evident in such scenarios. This mode requires developers to exercise greater control over their code, correctly handling EAGAIN errors, and ensuring data is fully read or written.