Easydarwin Open Source Media server Change Select to Epoll method

Source: Internet
Author: User
Tags epoll

This article comes from Easydarwin Team Fantasy (Fantasy (at) easydarwin.org)

I. Introduction to the EASYDARWIN network model

Eventcontext is responsible for monitoring all network read and write events. Eventcontext::requestevent each time a listener event is inserted into the
Listener list (select File descriptor set), Eventthread::entry () The dead loop listens for all the files that are added to the Fd_set description descriptor
Event. Entry ()->select_waitevent () returns the next event node to be processed each time, containing the hash key of the event-handling object and the event type.

The task queue is then posted to one thread in the thread pool. Note here is that each thread maintains its own task queue.
Related code,processevent->signal (). In this paper, a simple equalization algorithm is implemented to decide which thread to post to the task queue. Eventcontext Each event is processed, it deletes the listener's descriptive descriptor. After execution, the requestevent () is called again and inserted into the listener list. and activate the listener (to the pipe to write the data). taskthread::entry () is responsible for handling the tasks posted above and executing virtual method run (). Related code. thetimeout = Thetask->run (). All network modules inherit and implement the Run () method of the task class.

Two. The difference between select and Epoll

Select Kernel Implementation,

sys_select()->do_select(){    for(;;)    {        循环遍历FD_SET看是否有事件发生,    }}

Select maximum supports only 1024 file descriptive descriptors. Reason # define __fd_setsize 1024, which defines more than 1024 will cause a decrease in processing performance;

Epoll Kernel Implementation,

网络事件中断中调用ep_poll_callback(),将网络事件加入到epoll队列。这样,epoll_wait()等待的时候,就不会像select循环,由于队列中的每个事件都是有效的。

As a result, epoll is more efficient than select and the queue is unrestricted. can be arbitrarily sized.

But assuming that the probability of a select hit to a valid time is also high, the efficiency is almost the same.

Three. Replace the Easydarwin network model with the Epoll

The implementation process is relatively simple. Follow the interfaces provided by the previous select to implement them one at a time. Then put the call place to the operating system type macro switch, compatible with the compilation of Windows.

After implementation, debugging took a long time, just started to find that the thread pool in the insertion of monitoring events will appear in the resource competition, the program has been executed for some time after the exception, do not read the data pushed. After review code discovery should be no lock caused by the time of the resource competition, and some did not insert successfully, so the event is not monitored. After the lock after debugging, to avoid some deadlock problems, stable execution for several days without failure.

After nearly 2 months of development and stable commissioning, testing. Easydarwin Open Source Media server finally successfully optimizes the underlying select network model churn to the Epoll network model. The Easydarwin streaming server in the network processing efficiency has been raised to a level (here to thank Easydarwin Open Source team member fantasy selfless contribution, is he sacrificed precious spare time to rest, the night fight development and debugging. Ability to achieve Easydarwin bottom-level transformation results).

As we all know, the Select model has some bottlenecks in dealing with large concurrent network requests. By default, the number of network connections that can be processed at the same time on Linux is fd_setsize to 1024, although you can change the fd_setsize definition size, but at fd_setsize greater than 1024. Due to the congenital causes of the Select model. The network events can not be timely and accurate positioning. The processing performance is not improved synchronously, so it is the bottleneck of the whole streaming media server in concurrency, and after the change into the Epoll network model, the processing performance of the network event is improved, plus the advantage of Easydarwin architecture, the thread pool is adopted. The task queue and reactor technology enable network events to be perceived and processed efficiently (the task queue also involves a lock-free queue optimization, which will be analyzed in detail in a possible blog), thus enabling the entire Easydarwin streaming server to have very efficient event handling capabilities. And after a long period of testing. The stability is very good!

It is necessary to note that the Easydarwin is in the Windows side of the Select network model. Judging from the present situation. Most of the projects with large concurrency requirements are deployed on Linux systems, and Windows Easydarwin as a small-scale or research-oriented project that can meet the needs completely. Therefore, the EASYDARWIN+IOCP will be included in the future development plan;

Epoll model Basic code on Easydarwin GitHub, folder location in: Https://github.com/EasyDarwin/EasyDarwin/tree/master/CommonUtilitiesLib. The main documents are: EpollEvent.h and EpollEvent.cpp

Easydarwin Open Source Media Server project is also continuously optimized for higher performance, project address: Https://github.com/EasyDarwin

Get a lot of other information

Email:[email protected]

WEB:www.EasyDarwin.org

Copyright? Easydarwin.org 2013-2016

Easydarwin Open Source Media server Change Select to Epoll method

Related Article

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.