正在显示
1 个修改的文件
包含
30 行增加
和
4 行删除
trunk/src/app/srs_app_config.cpp
100644 → 100755
| @@ -1475,12 +1475,38 @@ int SrsConfig::check_config() | @@ -1475,12 +1475,38 @@ int SrsConfig::check_config() | ||
| 1475 | 1475 | ||
| 1476 | // check max connections of system limits | 1476 | // check max connections of system limits |
| 1477 | if (true) { | 1477 | if (true) { |
| 1478 | + int nb_consumed_fds = (int)get_listen().size(); | ||
| 1479 | + if (get_http_api_listen() > 0) { | ||
| 1480 | + nb_consumed_fds++; | ||
| 1481 | + } | ||
| 1482 | + if (get_http_stream_listen() > 0) { | ||
| 1483 | + nb_consumed_fds++; | ||
| 1484 | + } | ||
| 1485 | + if (get_log_tank_file()) { | ||
| 1486 | + nb_consumed_fds++; | ||
| 1487 | + } | ||
| 1488 | + // 0, 1, 2 for stdin, stdout and stderr. | ||
| 1489 | + nb_consumed_fds += 3; | ||
| 1490 | + | ||
| 1491 | + int nb_connections = get_max_connections(); | ||
| 1492 | + int nb_pipes = nb_connections * 2; | ||
| 1493 | + int nb_reserved = 10; // reserved | ||
| 1494 | + int nb_total = nb_connections + nb_pipes + nb_consumed_fds + nb_reserved; | ||
| 1495 | + | ||
| 1478 | int max_open_files = sysconf(_SC_OPEN_MAX); | 1496 | int max_open_files = sysconf(_SC_OPEN_MAX); |
| 1479 | - if (get_max_connections() > max_open_files) { | 1497 | + int nb_canbe = (max_open_files - (nb_consumed_fds + nb_reserved)) / 3 - 1; |
| 1498 | + | ||
| 1499 | + // for each play connections, we open a pipe(2fds) to convert SrsConsumver to io, | ||
| 1500 | + // refine performance, @see: https://github.com/winlinvip/simple-rtmp-server/issues/194 | ||
| 1501 | + if (nb_total >= max_open_files) { | ||
| 1480 | ret = ERROR_SYSTEM_CONFIG_INVALID; | 1502 | ret = ERROR_SYSTEM_CONFIG_INVALID; |
| 1481 | - srs_error("invalid max_connections=%d, system limit to %d, ret=%d. " | ||
| 1482 | - "you can login as root and set the limit: ulimit -HSn %d", get_max_connections(), max_open_files, | ||
| 1483 | - ret, get_max_connections()); | 1503 | + srs_error("invalid max_connections=%d, required=%d, system limit to %d, " |
| 1504 | + "total=%d(max_connections=%d, nb_pipes=%d, nb_consumed_fds=%d, nb_reserved=%d), ret=%d. " | ||
| 1505 | + "you can change max_connections from %d to %d, or " | ||
| 1506 | + "you can login as root and set the limit: ulimit -HSn %d", | ||
| 1507 | + nb_connections, nb_total, max_open_files, | ||
| 1508 | + nb_total, nb_connections, nb_pipes, nb_consumed_fds, nb_reserved, | ||
| 1509 | + ret, nb_connections, nb_canbe, nb_total); | ||
| 1484 | return ret; | 1510 | return ret; |
| 1485 | } | 1511 | } |
| 1486 | } | 1512 | } |
-
mentioned in commit b4c1d553
-
请 注册 或 登录 后发表评论