winlin

refine the max connections, compare the system ulimit max open files, error when exeed limit

@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 # @see full.conf for detail config. 2 # @see full.conf for detail config.
3 3
4 listen 1935; 4 listen 1935;
  5 +max_connections 1000;
5 vhost __defaultVhost__ { 6 vhost __defaultVhost__ {
6 } 7 }
7 8
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 # @see full.conf for detail config. 2 # @see full.conf for detail config.
3 3
4 listen 1935; 4 listen 1935;
  5 +max_connections 1000;
5 daemon off; 6 daemon off;
6 srs_log_tank console; 7 srs_log_tank console;
7 http_api { 8 http_api {
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 # @see full.conf for detail config. 3 # @see full.conf for detail config.
4 4
5 listen 19350; 5 listen 19350;
  6 +max_connections 1000;
6 daemon on; 7 daemon on;
7 srs_log_tank file; 8 srs_log_tank file;
8 srs_log_file ./objs/srs.demo.19350.log; 9 srs_log_file ./objs/srs.demo.19350.log;
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 # @see full.conf for detail config. 3 # @see full.conf for detail config.
4 4
5 listen 1935; 5 listen 1935;
  6 +max_connections 1000;
6 daemon on; 7 daemon on;
7 srs_log_tank file; 8 srs_log_tank file;
8 srs_log_file ./objs/srs.demo.log; 9 srs_log_file ./objs/srs.demo.log;
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 # @see full.conf for detail config. 3 # @see full.conf for detail config.
4 4
5 listen 1935; 5 listen 1935;
  6 +max_connections 1000;
6 vhost __defaultVhost__ { 7 vhost __defaultVhost__ {
7 dvr { 8 dvr {
8 enabled on; 9 enabled on;
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 # @see full.conf for detail config. 3 # @see full.conf for detail config.
4 4
5 listen 1935; 5 listen 1935;
  6 +max_connections 1000;
6 vhost __defaultVhost__ { 7 vhost __defaultVhost__ {
7 dvr { 8 dvr {
8 enabled on; 9 enabled on;
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 # @see full.conf for detail config. 3 # @see full.conf for detail config.
4 4
5 listen 1935; 5 listen 1935;
  6 +max_connections 1000;
6 pid objs/edge.pid; 7 pid objs/edge.pid;
7 srs_log_file ./objs/edge.log; 8 srs_log_file ./objs/edge.log;
8 vhost __defaultVhost__ { 9 vhost __defaultVhost__ {
@@ -2,7 +2,8 @@ @@ -2,7 +2,8 @@
2 # @see https://github.com/winlinvip/simple-rtmp-server/wiki/DRM 2 # @see https://github.com/winlinvip/simple-rtmp-server/wiki/DRM
3 # @see full.conf for detail config. 3 # @see full.conf for detail config.
4 4
5 -listen 1935; 5 +listen 1935
  6 +max_connections 1000;
6 vhost __defaultVhost__ { 7 vhost __defaultVhost__ {
7 mode remote; 8 mode remote;
8 origin 127.0.0.1:19350; 9 origin 127.0.0.1:19350;
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 # @see full.conf for detail config. 3 # @see full.conf for detail config.
4 4
5 listen 1935; 5 listen 1935;
  6 +max_connections 1000;
6 vhost __defaultVhost__ { 7 vhost __defaultVhost__ {
7 transcode { 8 transcode {
8 enabled on; 9 enabled on;
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 # @see full.conf for detail config. 3 # @see full.conf for detail config.
4 4
5 listen 1935; 5 listen 1935;
  6 +max_connections 1000;
6 pid ./objs/srs.master.pid; 7 pid ./objs/srs.master.pid;
7 srs_log_tank file; 8 srs_log_tank file;
8 srs_log_file ./objs/srs.master.log; 9 srs_log_file ./objs/srs.master.log;
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 # @see full.conf for detail config. 3 # @see full.conf for detail config.
4 4
5 listen 19350; 5 listen 19350;
  6 +max_connections 1000;
6 pid ./objs/srs.slave.pid; 7 pid ./objs/srs.slave.pid;
7 srs_log_tank file; 8 srs_log_tank file;
8 srs_log_file ./objs/srs.slave.log; 9 srs_log_file ./objs/srs.slave.log;
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 # @see full.conf for detail config. 3 # @see full.conf for detail config.
4 4
5 listen 1935; 5 listen 1935;
  6 +max_connections 1000;
6 vhost __defaultVhost__ { 7 vhost __defaultVhost__ {
7 hls { 8 hls {
8 enabled on; 9 enabled on;
1 # the config for srs http heartbeat, report its info to api-server 1 # the config for srs http heartbeat, report its info to api-server
2 # @see full.conf for detail config. 2 # @see full.conf for detail config.
3 3
4 -listen 1935; 4 +listen 1935
  5 +max_connections 1000;
5 heartbeat { 6 heartbeat {
6 enabled on; 7 enabled on;
7 interval 9.3; 8 interval 9.3;
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 # @see full.conf for detail config. 3 # @see full.conf for detail config.
4 4
5 listen 1935; 5 listen 1935;
  6 +max_connections 1000;
6 http_stream { 7 http_stream {
7 enabled on; 8 enabled on;
8 listen 8080; 9 listen 8080;
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 # @see full.conf for detail config. 2 # @see full.conf for detail config.
3 3
4 listen 1935; 4 listen 1935;
  5 +max_connections 1000;
5 srs_log_tank file; 6 srs_log_tank file;
6 srs_log_file ./objs/srs.log; 7 srs_log_file ./objs/srs.log;
7 vhost __defaultVhost__ { 8 vhost __defaultVhost__ {
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 # @see full.conf for detail config. 3 # @see full.conf for detail config.
4 4
5 listen 1935; 5 listen 1935;
  6 +max_connections 1000;
6 vhost __defaultVhost__ { 7 vhost __defaultVhost__ {
7 ingest livestream { 8 ingest livestream {
8 enabled on; 9 enabled on;
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 # @see full.conf for detail config. 3 # @see full.conf for detail config.
4 4
5 listen 19350; 5 listen 19350;
  6 +max_connections 1000;
6 pid objs/origin.pid; 7 pid objs/origin.pid;
7 srs_log_file ./objs/origin.log; 8 srs_log_file ./objs/origin.log;
8 vhost __defaultVhost__ { 9 vhost __defaultVhost__ {
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 # @see full.conf for detail config. 3 # @see full.conf for detail config.
4 4
5 listen 1935; 5 listen 1935;
  6 +max_connections 1000;
6 vhost __defaultVhost__ { 7 vhost __defaultVhost__ {
7 gop_cache off; 8 gop_cache off;
8 queue_length 10; 9 queue_length 10;
@@ -3,5 +3,6 @@ @@ -3,5 +3,6 @@
3 # @see full.conf for detail config. 3 # @see full.conf for detail config.
4 4
5 listen 1935; 5 listen 1935;
  6 +max_connections 1000;
6 vhost __defaultVhost__ { 7 vhost __defaultVhost__ {
7 } 8 }
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 # @see full.conf for detail config. 2 # @see full.conf for detail config.
3 3
4 listen 1935; 4 listen 1935;
  5 +max_connections 1000;
5 srs_log_tank file; 6 srs_log_tank file;
6 srs_log_file ./objs/srs.log; 7 srs_log_file ./objs/srs.log;
7 http_api { 8 http_api {
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 # @see full.conf for detail config. 3 # @see full.conf for detail config.
4 4
5 listen 1935; 5 listen 1935;
  6 +max_connections 1000;
6 vhost __defaultVhost__ { 7 vhost __defaultVhost__ {
7 hls { 8 hls {
8 enabled on; 9 enabled on;
@@ -23,6 +23,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -23,6 +23,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 23
24 #include <srs_app_config.hpp> 24 #include <srs_app_config.hpp>
25 25
  26 +#include <unistd.h>
26 #include <stdio.h> 27 #include <stdio.h>
27 #include <stdlib.h> 28 #include <stdlib.h>
28 #include <errno.h> 29 #include <errno.h>
@@ -1405,6 +1406,18 @@ int SrsConfig::check_config() @@ -1405,6 +1406,18 @@ int SrsConfig::check_config()
1405 return ret; 1406 return ret;
1406 } 1407 }
1407 1408
  1409 + // check max connections of system limits
  1410 + if (true) {
  1411 + int max_open_files = sysconf(_SC_OPEN_MAX);
  1412 + if (get_max_connections() > max_open_files) {
  1413 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1414 + srs_error("invalid max_connections=%d, system limit to %d, ret=%d. "
  1415 + "you can login as root and set the limit: ulimit -HSn %d", get_max_connections(), max_open_files,
  1416 + ret, get_max_connections());
  1417 + return ret;
  1418 + }
  1419 + }
  1420 +
1408 //////////////////////////////////////////////////////////////////////// 1421 ////////////////////////////////////////////////////////////////////////
1409 // check heartbeat 1422 // check heartbeat
1410 //////////////////////////////////////////////////////////////////////// 1423 ////////////////////////////////////////////////////////////////////////
@@ -197,7 +197,9 @@ void SrsFastLog::error(const char* tag, int context_id, const char* fmt, ...) @@ -197,7 +197,9 @@ void SrsFastLog::error(const char* tag, int context_id, const char* fmt, ...)
197 va_end(ap); 197 va_end(ap);
198 198
199 // add strerror() to error msg. 199 // add strerror() to error msg.
  200 + if (errno != 0) {
200 size += snprintf(log_data + size, LOG_MAX_SIZE - size, "(%s)", strerror(errno)); 201 size += snprintf(log_data + size, LOG_MAX_SIZE - size, "(%s)", strerror(errno));
  202 + }
201 203
202 write_log(fd, log_data, size, SrsLogLevel::Error); 204 write_log(fd, log_data, size, SrsLogLevel::Error);
203 } 205 }
@@ -1787,11 +1787,13 @@ VOID TEST(ConfigMainTest, ParseEmpty) @@ -1787,11 +1787,13 @@ VOID TEST(ConfigMainTest, ParseEmpty)
1787 VOID TEST(ConfigMainTest, ParseMinConf) 1787 VOID TEST(ConfigMainTest, ParseMinConf)
1788 { 1788 {
1789 MockSrsConfig conf; 1789 MockSrsConfig conf;
1790 - EXPECT_TRUE(ERROR_SUCCESS == conf.parse("listen 1935;")); 1790 + EXPECT_TRUE(ERROR_SUCCESS == conf.parse("listen 1935; max_connections 1000;"));
1791 1791
1792 vector<string> listens = conf.get_listen(); 1792 vector<string> listens = conf.get_listen();
1793 EXPECT_EQ(1, (int)listens.size()); 1793 EXPECT_EQ(1, (int)listens.size());
1794 EXPECT_STREQ("1935", listens.at(0).c_str()); 1794 EXPECT_STREQ("1935", listens.at(0).c_str());
  1795 +
  1796 + EXPECT_EQ(1000, conf.get_max_connections());
1795 } 1797 }
1796 1798
1797 VOID TEST(ConfigMainTest, ParseInvalidDirective) 1799 VOID TEST(ConfigMainTest, ParseInvalidDirective)
@@ -4364,3 +4366,94 @@ VOID TEST(ConfigMainTest, CheckConf_listen) @@ -4364,3 +4366,94 @@ VOID TEST(ConfigMainTest, CheckConf_listen)
4364 EXPECT_TRUE(ERROR_SUCCESS != conf.parse("listen -1935;")); 4366 EXPECT_TRUE(ERROR_SUCCESS != conf.parse("listen -1935;"));
4365 } 4367 }
4366 } 4368 }
  4369 +
  4370 +VOID TEST(ConfigMainTest, CheckConf_pid)
  4371 +{
  4372 + if (true) {
  4373 + MockSrsConfig conf;
  4374 + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("pids ./objs/srs.pid;"));
  4375 + }
  4376 +}
  4377 +
  4378 +VOID TEST(ConfigMainTest, CheckConf_chunk_size)
  4379 +{
  4380 + if (true) {
  4381 + MockSrsConfig conf;
  4382 + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("chunk_sizes 60000;"));
  4383 + }
  4384 +
  4385 + if (true) {
  4386 + MockSrsConfig conf;
  4387 + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("chunk_size 0;"));
  4388 + }
  4389 +
  4390 + if (true) {
  4391 + MockSrsConfig conf;
  4392 + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("chunk_size 1;"));
  4393 + }
  4394 +
  4395 + if (true) {
  4396 + MockSrsConfig conf;
  4397 + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("chunk_size 127;"));
  4398 + }
  4399 +
  4400 + if (true) {
  4401 + MockSrsConfig conf;
  4402 + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("chunk_size -1;"));
  4403 + }
  4404 +
  4405 + if (true) {
  4406 + MockSrsConfig conf;
  4407 + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("chunk_size -4096;"));
  4408 + }
  4409 +
  4410 + if (true) {
  4411 + MockSrsConfig conf;
  4412 + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("chunk_size 65536;"));
  4413 + }
  4414 +}
  4415 +
  4416 +VOID TEST(ConfigMainTest, CheckConf_ff_log_dir)
  4417 +{
  4418 + if (true) {
  4419 + MockSrsConfig conf;
  4420 + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("ff_log_dirs ./objs;"));
  4421 + }
  4422 +}
  4423 +
  4424 +VOID TEST(ConfigMainTest, CheckConf_srs_log_level)
  4425 +{
  4426 + if (true) {
  4427 + MockSrsConfig conf;
  4428 + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("srs_log_levels trace;"));
  4429 + }
  4430 +}
  4431 +
  4432 +VOID TEST(ConfigMainTest, CheckConf_srs_log_file)
  4433 +{
  4434 + if (true) {
  4435 + MockSrsConfig conf;
  4436 + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("srs_log_files ./objs/srs.log;"));
  4437 + }
  4438 +}
  4439 +
  4440 +VOID TEST(ConfigMainTest, CheckConf_max_connections)
  4441 +{
  4442 + if (true) {
  4443 + MockSrsConfig conf;
  4444 + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("max_connectionss 1000;"));
  4445 + }
  4446 +
  4447 + if (true) {
  4448 + MockSrsConfig conf;
  4449 + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("max_connections 0;"));
  4450 + }
  4451 +}
  4452 +
  4453 +VOID TEST(ConfigMainTest, CheckConf_)
  4454 +{
  4455 + if (true) {
  4456 + MockSrsConfig conf;
  4457 + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("listens 1935;"));
  4458 + }
  4459 +}