winlin

slowdown the cpu usage for srs to calc connections when too many connections. 0.9.180

@@ -14,7 +14,7 @@ gprof2dot.py: @@ -14,7 +14,7 @@ gprof2dot.py:
14 0. 若需要图形化,编译dot: 14 0. 若需要图形化,编译dot:
15 cd 3rdparty/gprof && bash build_gprof2dot.sh 15 cd 3rdparty/gprof && bash build_gprof2dot.sh
16 1. srs配置时: 16 1. srs配置时:
17 - ./configure --with-pg 17 + ./configure --with-gprof
18 脚本会加入编译参数"-pg -lc_p",gcc -g -pg -lc_p -c xxx -o xxx.o,即在configure中打开 Performance="-pg -lc_p" 18 脚本会加入编译参数"-pg -lc_p",gcc -g -pg -lc_p -c xxx -o xxx.o,即在configure中打开 Performance="-pg -lc_p"
19 链接时,加入链接选项"-pg",否则无法工作:gcc -pg -o srs xxxx.o,即在configure中打开 PerformanceLink="-pg" 19 链接时,加入链接选项"-pg",否则无法工作:gcc -pg -o srs xxxx.o,即在configure中打开 PerformanceLink="-pg"
20 2. 编译和启动程序:make && ./objs/srs -c conf/srs.conf 20 2. 编译和启动程序:make && ./objs/srs -c conf/srs.conf
@@ -90,7 +90,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -90,7 +90,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
90 90
91 // update network devices info interval: 91 // update network devices info interval:
92 // SRS_SYS_CYCLE_INTERVAL * SRS_SYS_NETWORK_RTMP_SERVER_RESOLUTION_TIMES 92 // SRS_SYS_CYCLE_INTERVAL * SRS_SYS_NETWORK_RTMP_SERVER_RESOLUTION_TIMES
93 -#define SRS_SYS_NETWORK_RTMP_SERVER_RESOLUTION_TIMES 90 93 +#define SRS_SYS_NETWORK_RTMP_SERVER_RESOLUTION_TIMES 120
94 94
95 SrsListener::SrsListener(SrsServer* server, SrsListenerType type) 95 SrsListener::SrsListener(SrsServer* server, SrsListenerType type)
96 { 96 {
@@ -833,10 +833,18 @@ void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps) @@ -833,10 +833,18 @@ void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps)
833 int nb_conn_sys_other = 0; 833 int nb_conn_sys_other = 0;
834 834
835 // @see: http://tester-higkoo.googlecode.com/svn-history/r14/trunk/Tools/iostat/iostat.c 835 // @see: http://tester-higkoo.googlecode.com/svn-history/r14/trunk/Tools/iostat/iostat.c
836 - while (fgets(buf, sizeof(buf), f)) { 836 + for (int i = 0; fgets(buf, sizeof(buf), f); i++) {
837 int st = 0; 837 int st = 0;
838 int ret = sscanf(buf, "%*s %*s %*s %2x\n", &st); 838 int ret = sscanf(buf, "%*s %*s %*s %2x\n", &st);
839 839
  840 + // there are maybe many many connections,
  841 + // for example, when srs used for monitor other process,
  842 + // like nginx, there are maybe many TIME_WAIT conections.
  843 + // we sleep 1ms when read 1000 records, so 100ms for 10w connections.
  844 + if ((i % 1000) == 0) {
  845 + st_usleep(1000);
  846 + }
  847 +
840 if (ret == 1) { 848 if (ret == 1) {
841 if (st == SYS_TCP_ESTABLISHED) { 849 if (st == SYS_TCP_ESTABLISHED) {
842 nb_conn_sys_established++; 850 nb_conn_sys_established++;
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 // current release version 31 // current release version
32 #define VERSION_MAJOR "0" 32 #define VERSION_MAJOR "0"
33 #define VERSION_MINOR "9" 33 #define VERSION_MINOR "9"
34 -#define VERSION_REVISION "179" 34 +#define VERSION_REVISION "180"
35 #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION 35 #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
36 // server info. 36 // server info.
37 #define RTMP_SIG_SRS_KEY "SRS" 37 #define RTMP_SIG_SRS_KEY "SRS"