winlin

for bug #194, disable the srs fd poll.

@@ -26,152 +26,31 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -26,152 +26,31 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 #include <srs_kernel_error.hpp> 26 #include <srs_kernel_error.hpp>
27 #include <srs_kernel_log.hpp> 27 #include <srs_kernel_log.hpp>
28 28
29 -// the interval in us to refresh the poll for all fds.  
30 -// for performance refine, @see: https://github.com/winlinvip/simple-rtmp-server/issues/194  
31 -#define SRS_POLL_CYCLE_INTERVAL 10 * 1000 * 1000  
32 -  
33 SrsPoll::SrsPoll() 29 SrsPoll::SrsPoll()
34 { 30 {
35 - _pds = NULL;  
36 - pthread = new SrsThread(this, 0, false);  
37 -}  
38 -  
39 -SrsPoll::~SrsPoll()  
40 -{  
41 - srs_freep(_pds);  
42 - srs_freep(pthread);  
43 - fds.clear();  
44 -}  
45 -  
46 -int SrsPoll::start()  
47 -{  
48 - return pthread->start();  
49 -}  
50 -  
51 -int SrsPoll::cycle()  
52 -{  
53 - int ret = ERROR_SUCCESS;  
54 -  
55 - if (fds.size() == 0) {  
56 - st_usleep(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US);  
57 - return ret;  
58 - }  
59 -  
60 - int nb_pds = (int)fds.size();  
61 -  
62 - // TODO: FIXME: use more efficient way for the poll.  
63 - srs_freep(_pds);  
64 - _pds = new pollfd[nb_pds];  
65 -  
66 - if (true) {  
67 - int index = 0;  
68 -  
69 - std::map<int, SrsPollFD*>::iterator it;  
70 - for (it = fds.begin(); it != fds.end(); ++it) {  
71 - int fd = it->first;  
72 -  
73 - pollfd& pfd = _pds[index++];  
74 - pfd.fd = fd;  
75 - pfd.events = POLLIN;  
76 - pfd.revents = 0;  
77 - }  
78 -  
79 - srs_assert(index == (int)fds.size());  
80 - }  
81 -  
82 - // Upon successful completion, a non-negative value is returned.  
83 - // A positive value indicates the total number of OS file descriptors in pds that have events.  
84 - // A value of 0 indicates that the call timed out.  
85 - if (st_poll(_pds, nb_pds, SRS_POLL_CYCLE_INTERVAL) < 0) {  
86 - srs_warn("ignore st_poll failed, size=%d", nb_pds);  
87 - return ret;  
88 - }  
89 -  
90 - for (int i = 0; i < nb_pds; i++) {  
91 - if (!(_pds[i].revents & POLLIN)) {  
92 - continue;  
93 - }  
94 -  
95 - int fd = _pds[i].fd;  
96 - if (fds.find(fd) == fds.end()) {  
97 - continue;  
98 - }  
99 -  
100 - SrsPollFD* owner = fds[fd];  
101 - owner->set_active(true);  
102 - }  
103 -  
104 - return ret;  
105 -}  
106 -  
107 -int SrsPoll::add(st_netfd_t stfd, SrsPollFD* owner)  
108 -{  
109 - int ret = ERROR_SUCCESS;  
110 -  
111 - int fd = st_netfd_fileno(stfd);  
112 - if (fds.find(fd) != fds.end()) {  
113 - ret = ERROR_RTMP_POLL_FD_DUPLICATED;  
114 - srs_error("fd exists, fd=%d, ret=%d", fd, ret);  
115 - return ret;  
116 - }  
117 -  
118 - fds[fd] = owner;  
119 -  
120 - return ret;  
121 -}  
122 -  
123 -void SrsPoll::remove(st_netfd_t stfd, SrsPollFD* owner)  
124 -{  
125 - std::map<int, SrsPollFD*>::iterator it;  
126 -  
127 - int fd = st_netfd_fileno(stfd);  
128 - if ((it = fds.find(fd)) != fds.end()) {  
129 - fds.erase(it);  
130 - }  
131 -}  
132 -  
133 -SrsPoll* SrsPoll::_instance = new SrsPoll();  
134 -  
135 -SrsPoll* SrsPoll::instance()  
136 -{  
137 - return _instance;  
138 -}  
139 -  
140 -SrsPollFD::SrsPollFD()  
141 -{  
142 _stfd = NULL; 31 _stfd = NULL;
143 _active = false; 32 _active = false;
144 } 33 }
145 34
146 -SrsPollFD::~SrsPollFD() 35 +SrsPoll::~SrsPoll()
147 { 36 {
148 - if (_stfd) {  
149 - SrsPoll* poll = SrsPoll::instance();  
150 - poll->remove(_stfd, this);  
151 - }  
152 } 37 }
153 38
154 -int SrsPollFD::initialize(st_netfd_t stfd) 39 +int SrsPoll::initialize(st_netfd_t stfd)
155 { 40 {
156 int ret = ERROR_SUCCESS; 41 int ret = ERROR_SUCCESS;
157 42
158 _stfd = stfd; 43 _stfd = stfd;
159 44
160 - SrsPoll* poll = SrsPoll::instance();  
161 - if ((ret = poll->add(stfd, this)) != ERROR_SUCCESS) {  
162 - srs_error("add fd to poll failed. ret=%d", ret);  
163 - return ret;  
164 - }  
165 -  
166 return ret; 45 return ret;
167 } 46 }
168 47
169 -bool SrsPollFD::active() 48 +bool SrsPoll::active()
170 { 49 {
171 return _active; 50 return _active;
172 } 51 }
173 52
174 -void SrsPollFD::set_active(bool v) 53 +void SrsPoll::set_active(bool v)
175 { 54 {
176 _active = v; 55 _active = v;
177 } 56 }
@@ -35,59 +35,20 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -35,59 +35,20 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 #include <srs_app_st.hpp> 35 #include <srs_app_st.hpp>
36 #include <srs_app_thread.hpp> 36 #include <srs_app_thread.hpp>
37 37
38 -class SrsPollFD;  
39 -  
40 -/**  
41 -* the poll for all play clients to finger the active fd out.  
42 -* for performance issue, @see: https://github.com/winlinvip/simple-rtmp-server/issues/194  
43 -* the poll is shared by all SrsPollFD, and we start an isolate thread to finger the active fds.  
44 -*/  
45 -class SrsPoll : public ISrsThreadHandler  
46 -{  
47 -private:  
48 - SrsThread* pthread;  
49 - pollfd* _pds;  
50 - std::map<int, SrsPollFD*> fds;  
51 -public:  
52 - SrsPoll();  
53 - virtual ~SrsPoll();  
54 -public:  
55 - /**  
56 - * start the poll thread.  
57 - */  
58 - virtual int start();  
59 - /**  
60 - * start an cycle thread.  
61 - */  
62 - virtual int cycle();  
63 -public:  
64 - /**  
65 - * add the fd to poll.  
66 - */  
67 - virtual int add(st_netfd_t stfd, SrsPollFD* owner);  
68 - /**  
69 - * remove the fd to poll, ignore any error.  
70 - */  
71 - virtual void remove(st_netfd_t stfd, SrsPollFD* owner);  
72 -// singleton  
73 -private:  
74 - static SrsPoll* _instance;  
75 -public:  
76 - static SrsPoll* instance();  
77 -};  
78 -  
79 /** 38 /**
80 * the poll fd to check whether the specified fd is active. 39 * the poll fd to check whether the specified fd is active.
  40 +* we start new thread to covert the fd status to async.
  41 +* for performance issue, @see: https://github.com/winlinvip/simple-rtmp-server/issues/194
81 */ 42 */
82 -class SrsPollFD 43 +class SrsPoll
83 { 44 {
84 private: 45 private:
85 st_netfd_t _stfd; 46 st_netfd_t _stfd;
86 // whether current fd is active. 47 // whether current fd is active.
87 bool _active; 48 bool _active;
88 public: 49 public:
89 - SrsPollFD();  
90 - virtual ~SrsPollFD(); 50 + SrsPoll();
  51 + virtual ~SrsPoll();
91 public: 52 public:
92 /** 53 /**
93 * initialize the poll. 54 * initialize the poll.
@@ -518,7 +518,7 @@ int SrsRtmpConn::playing(SrsSource* source) @@ -518,7 +518,7 @@ int SrsRtmpConn::playing(SrsSource* source)
518 srs_verbose("consumer created success."); 518 srs_verbose("consumer created success.");
519 519
520 // use poll fd to manage the connection, read when active. 520 // use poll fd to manage the connection, read when active.
521 - SrsPollFD poll_fd; 521 + SrsPoll poll_fd;
522 if ((ret = poll_fd.initialize(stfd)) != ERROR_SUCCESS) { 522 if ((ret = poll_fd.initialize(stfd)) != ERROR_SUCCESS) {
523 return ret; 523 return ret;
524 } 524 }
@@ -44,7 +44,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -44,7 +44,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
44 #include <srs_app_source.hpp> 44 #include <srs_app_source.hpp>
45 #include <srs_app_utility.hpp> 45 #include <srs_app_utility.hpp>
46 #include <srs_app_heartbeat.hpp> 46 #include <srs_app_heartbeat.hpp>
47 -#include <srs_app_poll.hpp>  
48 47
49 // signal defines. 48 // signal defines.
50 #define SIGNAL_RELOAD SIGHUP 49 #define SIGNAL_RELOAD SIGHUP
@@ -665,14 +664,6 @@ int SrsServer::do_cycle() @@ -665,14 +664,6 @@ int SrsServer::do_cycle()
665 { 664 {
666 int ret = ERROR_SUCCESS; 665 int ret = ERROR_SUCCESS;
667 666
668 - // start the poll for play clients.  
669 - // performance issue, @see: https://github.com/winlinvip/simple-rtmp-server/issues/194  
670 - SrsPoll* poll = SrsPoll::instance();  
671 - if ((ret = poll->start()) != ERROR_SUCCESS) {  
672 - srs_error("start poll failed. ret=%d", ret);  
673 - return ret;  
674 - }  
675 -  
676 // find the max loop 667 // find the max loop
677 int max = srs_max(0, SRS_SYS_TIME_RESOLUTION_MS_TIMES); 668 int max = srs_max(0, SRS_SYS_TIME_RESOLUTION_MS_TIMES);
678 669