1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

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

This commit is contained in:
winlin 2014-07-26 15:34:45 +08:00
parent 5f7ff37e64
commit ebf9e560b1
24 changed files with 133 additions and 4 deletions

View file

@ -2,6 +2,7 @@
# @see full.conf for detail config. # @see full.conf for detail config.
listen 1935; listen 1935;
max_connections 1000;
vhost __defaultVhost__ { vhost __defaultVhost__ {
} }

View file

@ -2,6 +2,7 @@
# @see full.conf for detail config. # @see full.conf for detail config.
listen 1935; listen 1935;
max_connections 1000;
daemon off; daemon off;
srs_log_tank console; srs_log_tank console;
http_api { http_api {

View file

@ -3,6 +3,7 @@
# @see full.conf for detail config. # @see full.conf for detail config.
listen 19350; listen 19350;
max_connections 1000;
daemon on; daemon on;
srs_log_tank file; srs_log_tank file;
srs_log_file ./objs/srs.demo.19350.log; srs_log_file ./objs/srs.demo.19350.log;

View file

@ -3,6 +3,7 @@
# @see full.conf for detail config. # @see full.conf for detail config.
listen 1935; listen 1935;
max_connections 1000;
daemon on; daemon on;
srs_log_tank file; srs_log_tank file;
srs_log_file ./objs/srs.demo.log; srs_log_file ./objs/srs.demo.log;

View file

@ -3,6 +3,7 @@
# @see full.conf for detail config. # @see full.conf for detail config.
listen 1935; listen 1935;
max_connections 1000;
vhost __defaultVhost__ { vhost __defaultVhost__ {
dvr { dvr {
enabled on; enabled on;

View file

@ -3,6 +3,7 @@
# @see full.conf for detail config. # @see full.conf for detail config.
listen 1935; listen 1935;
max_connections 1000;
vhost __defaultVhost__ { vhost __defaultVhost__ {
dvr { dvr {
enabled on; enabled on;

View file

@ -3,6 +3,7 @@
# @see full.conf for detail config. # @see full.conf for detail config.
listen 1935; listen 1935;
max_connections 1000;
pid objs/edge.pid; pid objs/edge.pid;
srs_log_file ./objs/edge.log; srs_log_file ./objs/edge.log;
vhost __defaultVhost__ { vhost __defaultVhost__ {

View file

@ -2,7 +2,8 @@
# @see https://github.com/winlinvip/simple-rtmp-server/wiki/DRM # @see https://github.com/winlinvip/simple-rtmp-server/wiki/DRM
# @see full.conf for detail config. # @see full.conf for detail config.
listen 1935; listen 1935
max_connections 1000;
vhost __defaultVhost__ { vhost __defaultVhost__ {
mode remote; mode remote;
origin 127.0.0.1:19350; origin 127.0.0.1:19350;

View file

@ -3,6 +3,7 @@
# @see full.conf for detail config. # @see full.conf for detail config.
listen 1935; listen 1935;
max_connections 1000;
vhost __defaultVhost__ { vhost __defaultVhost__ {
transcode { transcode {
enabled on; enabled on;

View file

@ -3,6 +3,7 @@
# @see full.conf for detail config. # @see full.conf for detail config.
listen 1935; listen 1935;
max_connections 1000;
pid ./objs/srs.master.pid; pid ./objs/srs.master.pid;
srs_log_tank file; srs_log_tank file;
srs_log_file ./objs/srs.master.log; srs_log_file ./objs/srs.master.log;

View file

@ -3,6 +3,7 @@
# @see full.conf for detail config. # @see full.conf for detail config.
listen 19350; listen 19350;
max_connections 1000;
pid ./objs/srs.slave.pid; pid ./objs/srs.slave.pid;
srs_log_tank file; srs_log_tank file;
srs_log_file ./objs/srs.slave.log; srs_log_file ./objs/srs.slave.log;

View file

@ -3,6 +3,7 @@
# @see full.conf for detail config. # @see full.conf for detail config.
listen 1935; listen 1935;
max_connections 1000;
vhost __defaultVhost__ { vhost __defaultVhost__ {
hls { hls {
enabled on; enabled on;

View file

@ -1,7 +1,8 @@
# the config for srs http heartbeat, report its info to api-server # the config for srs http heartbeat, report its info to api-server
# @see full.conf for detail config. # @see full.conf for detail config.
listen 1935; listen 1935
max_connections 1000;
heartbeat { heartbeat {
enabled on; enabled on;
interval 9.3; interval 9.3;

View file

@ -3,6 +3,7 @@
# @see full.conf for detail config. # @see full.conf for detail config.
listen 1935; listen 1935;
max_connections 1000;
http_stream { http_stream {
enabled on; enabled on;
listen 8080; listen 8080;

View file

@ -2,6 +2,7 @@
# @see full.conf for detail config. # @see full.conf for detail config.
listen 1935; listen 1935;
max_connections 1000;
srs_log_tank file; srs_log_tank file;
srs_log_file ./objs/srs.log; srs_log_file ./objs/srs.log;
vhost __defaultVhost__ { vhost __defaultVhost__ {

View file

@ -3,6 +3,7 @@
# @see full.conf for detail config. # @see full.conf for detail config.
listen 1935; listen 1935;
max_connections 1000;
vhost __defaultVhost__ { vhost __defaultVhost__ {
ingest livestream { ingest livestream {
enabled on; enabled on;

View file

@ -3,6 +3,7 @@
# @see full.conf for detail config. # @see full.conf for detail config.
listen 19350; listen 19350;
max_connections 1000;
pid objs/origin.pid; pid objs/origin.pid;
srs_log_file ./objs/origin.log; srs_log_file ./objs/origin.log;
vhost __defaultVhost__ { vhost __defaultVhost__ {

View file

@ -3,6 +3,7 @@
# @see full.conf for detail config. # @see full.conf for detail config.
listen 1935; listen 1935;
max_connections 1000;
vhost __defaultVhost__ { vhost __defaultVhost__ {
gop_cache off; gop_cache off;
queue_length 10; queue_length 10;

View file

@ -3,5 +3,6 @@
# @see full.conf for detail config. # @see full.conf for detail config.
listen 1935; listen 1935;
max_connections 1000;
vhost __defaultVhost__ { vhost __defaultVhost__ {
} }

View file

@ -2,6 +2,7 @@
# @see full.conf for detail config. # @see full.conf for detail config.
listen 1935; listen 1935;
max_connections 1000;
srs_log_tank file; srs_log_tank file;
srs_log_file ./objs/srs.log; srs_log_file ./objs/srs.log;
http_api { http_api {

View file

@ -3,6 +3,7 @@
# @see full.conf for detail config. # @see full.conf for detail config.
listen 1935; listen 1935;
max_connections 1000;
vhost __defaultVhost__ { vhost __defaultVhost__ {
hls { hls {
enabled on; enabled on;

View file

@ -23,6 +23,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_app_config.hpp> #include <srs_app_config.hpp>
#include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
@ -1405,6 +1406,18 @@ int SrsConfig::check_config()
return ret; return ret;
} }
// check max connections of system limits
if (true) {
int max_open_files = sysconf(_SC_OPEN_MAX);
if (get_max_connections() > max_open_files) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("invalid max_connections=%d, system limit to %d, ret=%d. "
"you can login as root and set the limit: ulimit -HSn %d", get_max_connections(), max_open_files,
ret, get_max_connections());
return ret;
}
}
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// check heartbeat // check heartbeat
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////

View file

@ -197,7 +197,9 @@ void SrsFastLog::error(const char* tag, int context_id, const char* fmt, ...)
va_end(ap); va_end(ap);
// add strerror() to error msg. // add strerror() to error msg.
size += snprintf(log_data + size, LOG_MAX_SIZE - size, "(%s)", strerror(errno)); if (errno != 0) {
size += snprintf(log_data + size, LOG_MAX_SIZE - size, "(%s)", strerror(errno));
}
write_log(fd, log_data, size, SrsLogLevel::Error); write_log(fd, log_data, size, SrsLogLevel::Error);
} }

View file

@ -1787,11 +1787,13 @@ VOID TEST(ConfigMainTest, ParseEmpty)
VOID TEST(ConfigMainTest, ParseMinConf) VOID TEST(ConfigMainTest, ParseMinConf)
{ {
MockSrsConfig conf; MockSrsConfig conf;
EXPECT_TRUE(ERROR_SUCCESS == conf.parse("listen 1935;")); EXPECT_TRUE(ERROR_SUCCESS == conf.parse("listen 1935; max_connections 1000;"));
vector<string> listens = conf.get_listen(); vector<string> listens = conf.get_listen();
EXPECT_EQ(1, (int)listens.size()); EXPECT_EQ(1, (int)listens.size());
EXPECT_STREQ("1935", listens.at(0).c_str()); EXPECT_STREQ("1935", listens.at(0).c_str());
EXPECT_EQ(1000, conf.get_max_connections());
} }
VOID TEST(ConfigMainTest, ParseInvalidDirective) VOID TEST(ConfigMainTest, ParseInvalidDirective)
@ -4364,3 +4366,94 @@ VOID TEST(ConfigMainTest, CheckConf_listen)
EXPECT_TRUE(ERROR_SUCCESS != conf.parse("listen -1935;")); EXPECT_TRUE(ERROR_SUCCESS != conf.parse("listen -1935;"));
} }
} }
VOID TEST(ConfigMainTest, CheckConf_pid)
{
if (true) {
MockSrsConfig conf;
EXPECT_TRUE(ERROR_SUCCESS != conf.parse("pids ./objs/srs.pid;"));
}
}
VOID TEST(ConfigMainTest, CheckConf_chunk_size)
{
if (true) {
MockSrsConfig conf;
EXPECT_TRUE(ERROR_SUCCESS != conf.parse("chunk_sizes 60000;"));
}
if (true) {
MockSrsConfig conf;
EXPECT_TRUE(ERROR_SUCCESS != conf.parse("chunk_size 0;"));
}
if (true) {
MockSrsConfig conf;
EXPECT_TRUE(ERROR_SUCCESS != conf.parse("chunk_size 1;"));
}
if (true) {
MockSrsConfig conf;
EXPECT_TRUE(ERROR_SUCCESS != conf.parse("chunk_size 127;"));
}
if (true) {
MockSrsConfig conf;
EXPECT_TRUE(ERROR_SUCCESS != conf.parse("chunk_size -1;"));
}
if (true) {
MockSrsConfig conf;
EXPECT_TRUE(ERROR_SUCCESS != conf.parse("chunk_size -4096;"));
}
if (true) {
MockSrsConfig conf;
EXPECT_TRUE(ERROR_SUCCESS != conf.parse("chunk_size 65536;"));
}
}
VOID TEST(ConfigMainTest, CheckConf_ff_log_dir)
{
if (true) {
MockSrsConfig conf;
EXPECT_TRUE(ERROR_SUCCESS != conf.parse("ff_log_dirs ./objs;"));
}
}
VOID TEST(ConfigMainTest, CheckConf_srs_log_level)
{
if (true) {
MockSrsConfig conf;
EXPECT_TRUE(ERROR_SUCCESS != conf.parse("srs_log_levels trace;"));
}
}
VOID TEST(ConfigMainTest, CheckConf_srs_log_file)
{
if (true) {
MockSrsConfig conf;
EXPECT_TRUE(ERROR_SUCCESS != conf.parse("srs_log_files ./objs/srs.log;"));
}
}
VOID TEST(ConfigMainTest, CheckConf_max_connections)
{
if (true) {
MockSrsConfig conf;
EXPECT_TRUE(ERROR_SUCCESS != conf.parse("max_connectionss 1000;"));
}
if (true) {
MockSrsConfig conf;
EXPECT_TRUE(ERROR_SUCCESS != conf.parse("max_connections 0;"));
}
}
VOID TEST(ConfigMainTest, CheckConf_)
{
if (true) {
MockSrsConfig conf;
EXPECT_TRUE(ERROR_SUCCESS != conf.parse("listens 1935;"));
}
}