正在显示
12 个修改的文件
包含
125 行增加
和
28 行删除
| @@ -485,6 +485,7 @@ Supported operating systems and hardware: | @@ -485,6 +485,7 @@ Supported operating systems and hardware: | ||
| 485 | * 2013-10-17, Created.<br/> | 485 | * 2013-10-17, Created.<br/> |
| 486 | 486 | ||
| 487 | ## History | 487 | ## History |
| 488 | +* v2.0, 2014-12-04, fix [#241](https://github.com/winlinvip/simple-rtmp-server/issues/241), add mw(merged-write) config. 2.0.53 | ||
| 488 | * v2.0, 2014-12-04, for [#241](https://github.com/winlinvip/simple-rtmp-server/issues/241), support mr(merged-read) config and reload. 2.0.52. | 489 | * v2.0, 2014-12-04, for [#241](https://github.com/winlinvip/simple-rtmp-server/issues/241), support mr(merged-read) config and reload. 2.0.52. |
| 489 | * v2.0, 2014-12-04, enable [#241](https://github.com/winlinvip/simple-rtmp-server/issues/241) and [#248](https://github.com/winlinvip/simple-rtmp-server/issues/248), +25% performance, 2.5k publisher. 2.0.50 | 490 | * v2.0, 2014-12-04, enable [#241](https://github.com/winlinvip/simple-rtmp-server/issues/241) and [#248](https://github.com/winlinvip/simple-rtmp-server/issues/248), +25% performance, 2.5k publisher. 2.0.50 |
| 490 | * v2.0, 2014-12-04, fix [#248](https://github.com/winlinvip/simple-rtmp-server/issues/248), improve about 15% performance for fast buffer. 2.0.49 | 491 | * v2.0, 2014-12-04, fix [#248](https://github.com/winlinvip/simple-rtmp-server/issues/248), improve about 15% performance for fast buffer. 2.0.49 |
| @@ -143,7 +143,8 @@ vhost __defaultVhost__ { | @@ -143,7 +143,8 @@ vhost __defaultVhost__ { | ||
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | # the MR(merged-read) setting for publisher. | 145 | # the MR(merged-read) setting for publisher. |
| 146 | -vhost mr.srs.com { | 146 | +# the MW(merged-write) settings for player. |
| 147 | +vhost mrw.srs.com { | ||
| 147 | # about MR, read https://github.com/winlinvip/simple-rtmp-server/issues/241 | 148 | # about MR, read https://github.com/winlinvip/simple-rtmp-server/issues/241 |
| 148 | mr { | 149 | mr { |
| 149 | # whether enable the MR(merged-read) | 150 | # whether enable the MR(merged-read) |
| @@ -160,6 +161,11 @@ vhost mr.srs.com { | @@ -160,6 +161,11 @@ vhost mr.srs.com { | ||
| 160 | # default: 500 | 161 | # default: 500 |
| 161 | latency 500; | 162 | latency 500; |
| 162 | } | 163 | } |
| 164 | + # set the MW(merged-write) latency in ms. | ||
| 165 | + # SRS always set mw on, so we just set the latency value. | ||
| 166 | + # the latency of stream >= mw_latency + mr_latency | ||
| 167 | + # default: 500 | ||
| 168 | + mw_latency 500; | ||
| 163 | } | 169 | } |
| 164 | 170 | ||
| 165 | # vhost for edge, edge and origin is the same vhost | 171 | # vhost for edge, edge and origin is the same vhost |
| @@ -45,6 +45,7 @@ using namespace std; | @@ -45,6 +45,7 @@ using namespace std; | ||
| 45 | #include <srs_app_source.hpp> | 45 | #include <srs_app_source.hpp> |
| 46 | #include <srs_kernel_file.hpp> | 46 | #include <srs_kernel_file.hpp> |
| 47 | #include <srs_app_utility.hpp> | 47 | #include <srs_app_utility.hpp> |
| 48 | +#include <srs_core_performance.hpp> | ||
| 48 | 49 | ||
| 49 | using namespace _srs_internal; | 50 | using namespace _srs_internal; |
| 50 | 51 | ||
| @@ -829,6 +830,17 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root) | @@ -829,6 +830,17 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root) | ||
| 829 | } | 830 | } |
| 830 | srs_trace("vhost %s reload mr success.", vhost.c_str()); | 831 | srs_trace("vhost %s reload mr success.", vhost.c_str()); |
| 831 | } | 832 | } |
| 833 | + // mw, only one per vhost | ||
| 834 | + if (!srs_directive_equals(new_vhost->get("mw_latency"), old_vhost->get("mw_latency"))) { | ||
| 835 | + for (it = subscribes.begin(); it != subscribes.end(); ++it) { | ||
| 836 | + ISrsReloadHandler* subscribe = *it; | ||
| 837 | + if ((ret = subscribe->on_reload_vhost_mw(vhost)) != ERROR_SUCCESS) { | ||
| 838 | + srs_error("vhost %s notify subscribes mw failed. ret=%d", vhost.c_str(), ret); | ||
| 839 | + return ret; | ||
| 840 | + } | ||
| 841 | + } | ||
| 842 | + srs_trace("vhost %s reload mw success.", vhost.c_str()); | ||
| 843 | + } | ||
| 832 | // http, only one per vhost. | 844 | // http, only one per vhost. |
| 833 | if (!srs_directive_equals(new_vhost->get("http"), old_vhost->get("http"))) { | 845 | if (!srs_directive_equals(new_vhost->get("http"), old_vhost->get("http"))) { |
| 834 | for (it = subscribes.begin(); it != subscribes.end(); ++it) { | 846 | for (it = subscribes.begin(); it != subscribes.end(); ++it) { |
| @@ -1327,7 +1339,7 @@ int SrsConfig::check_config() | @@ -1327,7 +1339,7 @@ int SrsConfig::check_config() | ||
| 1327 | && n != "time_jitter" | 1339 | && n != "time_jitter" |
| 1328 | && n != "atc" && n != "atc_auto" | 1340 | && n != "atc" && n != "atc_auto" |
| 1329 | && n != "debug_srs_upnode" | 1341 | && n != "debug_srs_upnode" |
| 1330 | - && n != "mr" | 1342 | + && n != "mr" && n != "mw_latency" |
| 1331 | ) { | 1343 | ) { |
| 1332 | ret = ERROR_SYSTEM_CONFIG_INVALID; | 1344 | ret = ERROR_SYSTEM_CONFIG_INVALID; |
| 1333 | srs_error("unsupported vhost directive %s, ret=%d", n.c_str(), ret); | 1345 | srs_error("unsupported vhost directive %s, ret=%d", n.c_str(), ret); |
| @@ -1951,7 +1963,7 @@ bool SrsConfig::get_gop_cache(string vhost) | @@ -1951,7 +1963,7 @@ bool SrsConfig::get_gop_cache(string vhost) | ||
| 1951 | SrsConfDirective* conf = get_vhost(vhost); | 1963 | SrsConfDirective* conf = get_vhost(vhost); |
| 1952 | 1964 | ||
| 1953 | if (!conf) { | 1965 | if (!conf) { |
| 1954 | - return true; | 1966 | + return SRS_PERF_GOP_CACHE; |
| 1955 | } | 1967 | } |
| 1956 | 1968 | ||
| 1957 | conf = conf->get("gop_cache"); | 1969 | conf = conf->get("gop_cache"); |
| @@ -1959,7 +1971,7 @@ bool SrsConfig::get_gop_cache(string vhost) | @@ -1959,7 +1971,7 @@ bool SrsConfig::get_gop_cache(string vhost) | ||
| 1959 | return false; | 1971 | return false; |
| 1960 | } | 1972 | } |
| 1961 | 1973 | ||
| 1962 | - return true; | 1974 | + return SRS_PERF_GOP_CACHE; |
| 1963 | } | 1975 | } |
| 1964 | 1976 | ||
| 1965 | bool SrsConfig::get_debug_srs_upnode(string vhost) | 1977 | bool SrsConfig::get_debug_srs_upnode(string vhost) |
| @@ -2032,12 +2044,12 @@ double SrsConfig::get_queue_length(string vhost) | @@ -2032,12 +2044,12 @@ double SrsConfig::get_queue_length(string vhost) | ||
| 2032 | SrsConfDirective* conf = get_vhost(vhost); | 2044 | SrsConfDirective* conf = get_vhost(vhost); |
| 2033 | 2045 | ||
| 2034 | if (!conf) { | 2046 | if (!conf) { |
| 2035 | - return SRS_CONF_DEFAULT_QUEUE_LENGTH; | 2047 | + return SRS_PERF_PLAY_QUEUE; |
| 2036 | } | 2048 | } |
| 2037 | 2049 | ||
| 2038 | conf = conf->get("queue_length"); | 2050 | conf = conf->get("queue_length"); |
| 2039 | if (!conf || conf->arg0().empty()) { | 2051 | if (!conf || conf->arg0().empty()) { |
| 2040 | - return SRS_CONF_DEFAULT_QUEUE_LENGTH; | 2052 | + return SRS_PERF_PLAY_QUEUE; |
| 2041 | } | 2053 | } |
| 2042 | 2054 | ||
| 2043 | return ::atoi(conf->arg0().c_str()); | 2055 | return ::atoi(conf->arg0().c_str()); |
| @@ -2106,17 +2118,17 @@ bool SrsConfig::get_mr_enabled(string vhost) | @@ -2106,17 +2118,17 @@ bool SrsConfig::get_mr_enabled(string vhost) | ||
| 2106 | SrsConfDirective* conf = get_vhost(vhost); | 2118 | SrsConfDirective* conf = get_vhost(vhost); |
| 2107 | 2119 | ||
| 2108 | if (!conf) { | 2120 | if (!conf) { |
| 2109 | - return SRS_CONSTS_RTMP_MR; | 2121 | + return SRS_PERF_MR_ENABLED; |
| 2110 | } | 2122 | } |
| 2111 | 2123 | ||
| 2112 | conf = conf->get("mr"); | 2124 | conf = conf->get("mr"); |
| 2113 | if (!conf) { | 2125 | if (!conf) { |
| 2114 | - return SRS_CONSTS_RTMP_MR; | 2126 | + return SRS_PERF_MR_ENABLED; |
| 2115 | } | 2127 | } |
| 2116 | 2128 | ||
| 2117 | conf = conf->get("enabled"); | 2129 | conf = conf->get("enabled"); |
| 2118 | if (!conf || conf->arg0() != "on") { | 2130 | if (!conf || conf->arg0() != "on") { |
| 2119 | - return SRS_CONSTS_RTMP_MR; | 2131 | + return SRS_PERF_MR_ENABLED; |
| 2120 | } | 2132 | } |
| 2121 | 2133 | ||
| 2122 | return true; | 2134 | return true; |
| @@ -2128,17 +2140,34 @@ int SrsConfig::get_mr_sleep_ms(string vhost) | @@ -2128,17 +2140,34 @@ int SrsConfig::get_mr_sleep_ms(string vhost) | ||
| 2128 | SrsConfDirective* conf = get_vhost(vhost); | 2140 | SrsConfDirective* conf = get_vhost(vhost); |
| 2129 | 2141 | ||
| 2130 | if (!conf) { | 2142 | if (!conf) { |
| 2131 | - return SRS_CONSTS_RTMP_MR_SLEEP; | 2143 | + return SRS_PERF_MR_SLEEP; |
| 2132 | } | 2144 | } |
| 2133 | 2145 | ||
| 2134 | conf = conf->get("mr"); | 2146 | conf = conf->get("mr"); |
| 2135 | if (!conf) { | 2147 | if (!conf) { |
| 2136 | - return SRS_CONSTS_RTMP_MR_SLEEP; | 2148 | + return SRS_PERF_MR_SLEEP; |
| 2137 | } | 2149 | } |
| 2138 | 2150 | ||
| 2139 | conf = conf->get("latency"); | 2151 | conf = conf->get("latency"); |
| 2140 | if (!conf || conf->arg0().empty()) { | 2152 | if (!conf || conf->arg0().empty()) { |
| 2141 | - return SRS_CONSTS_RTMP_MR_SLEEP; | 2153 | + return SRS_PERF_MR_SLEEP; |
| 2154 | + } | ||
| 2155 | + | ||
| 2156 | + return ::atoi(conf->arg0().c_str()); | ||
| 2157 | +} | ||
| 2158 | + | ||
| 2159 | +int SrsConfig::get_mw_sleep_ms(string vhost) | ||
| 2160 | +{ | ||
| 2161 | + | ||
| 2162 | + SrsConfDirective* conf = get_vhost(vhost); | ||
| 2163 | + | ||
| 2164 | + if (!conf) { | ||
| 2165 | + return SRS_PERF_MW_SLEEP; | ||
| 2166 | + } | ||
| 2167 | + | ||
| 2168 | + conf = conf->get("mw_latency"); | ||
| 2169 | + if (!conf || conf->arg0().empty()) { | ||
| 2170 | + return SRS_PERF_MW_SLEEP; | ||
| 2142 | } | 2171 | } |
| 2143 | 2172 | ||
| 2144 | return ::atoi(conf->arg0().c_str()); | 2173 | return ::atoi(conf->arg0().c_str()); |
| @@ -54,8 +54,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -54,8 +54,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 54 | #define SRS_CONF_DEFAULT_DVR_PLAN SRS_CONF_DEFAULT_DVR_PLAN_SESSION | 54 | #define SRS_CONF_DEFAULT_DVR_PLAN SRS_CONF_DEFAULT_DVR_PLAN_SESSION |
| 55 | #define SRS_CONF_DEFAULT_DVR_DURATION 30 | 55 | #define SRS_CONF_DEFAULT_DVR_DURATION 30 |
| 56 | #define SRS_CONF_DEFAULT_TIME_JITTER "full" | 56 | #define SRS_CONF_DEFAULT_TIME_JITTER "full" |
| 57 | -// in seconds, the live queue length. | ||
| 58 | -#define SRS_CONF_DEFAULT_QUEUE_LENGTH 30 | ||
| 59 | // in seconds, the paused queue length. | 57 | // in seconds, the paused queue length. |
| 60 | #define SRS_CONF_DEFAULT_PAUSED_LENGTH 10 | 58 | #define SRS_CONF_DEFAULT_PAUSED_LENGTH 10 |
| 61 | // the interval in seconds for bandwidth check | 59 | // the interval in seconds for bandwidth check |
| @@ -541,6 +539,12 @@ public: | @@ -541,6 +539,12 @@ public: | ||
| 541 | */ | 539 | */ |
| 542 | // TODO: FIXME: add utest for mr config. | 540 | // TODO: FIXME: add utest for mr config. |
| 543 | virtual int get_mr_sleep_ms(std::string vhost); | 541 | virtual int get_mr_sleep_ms(std::string vhost); |
| 542 | + /** | ||
| 543 | + * get the mw sleep time in ms for vhost. | ||
| 544 | + * @param vhost, the vhost to get the mw sleep time. | ||
| 545 | + */ | ||
| 546 | + // TODO: FIXME: add utest for mw config. | ||
| 547 | + virtual int get_mw_sleep_ms(std::string vhost); | ||
| 544 | private: | 548 | private: |
| 545 | /** | 549 | /** |
| 546 | * get the global chunk size. | 550 | * get the global chunk size. |
| @@ -145,6 +145,11 @@ int ISrsReloadHandler::on_reload_vhost_mr(string /*vhost*/) | @@ -145,6 +145,11 @@ int ISrsReloadHandler::on_reload_vhost_mr(string /*vhost*/) | ||
| 145 | return ERROR_SUCCESS; | 145 | return ERROR_SUCCESS; |
| 146 | } | 146 | } |
| 147 | 147 | ||
| 148 | +int ISrsReloadHandler::on_reload_vhost_mw(string /*vhost*/) | ||
| 149 | +{ | ||
| 150 | + return ERROR_SUCCESS; | ||
| 151 | +} | ||
| 152 | + | ||
| 148 | int ISrsReloadHandler::on_reload_vhost_transcode(string /*vhost*/) | 153 | int ISrsReloadHandler::on_reload_vhost_transcode(string /*vhost*/) |
| 149 | { | 154 | { |
| 150 | return ERROR_SUCCESS; | 155 | return ERROR_SUCCESS; |
| @@ -66,6 +66,7 @@ public: | @@ -66,6 +66,7 @@ public: | ||
| 66 | virtual int on_reload_vhost_hls(std::string vhost); | 66 | virtual int on_reload_vhost_hls(std::string vhost); |
| 67 | virtual int on_reload_vhost_dvr(std::string vhost); | 67 | virtual int on_reload_vhost_dvr(std::string vhost); |
| 68 | virtual int on_reload_vhost_mr(std::string vhost); | 68 | virtual int on_reload_vhost_mr(std::string vhost); |
| 69 | + virtual int on_reload_vhost_mw(std::string vhost); | ||
| 69 | virtual int on_reload_vhost_transcode(std::string vhost); | 70 | virtual int on_reload_vhost_transcode(std::string vhost); |
| 70 | virtual int on_reload_ingest_removed(std::string vhost, std::string ingest_id); | 71 | virtual int on_reload_ingest_removed(std::string vhost, std::string ingest_id); |
| 71 | virtual int on_reload_ingest_added(std::string vhost, std::string ingest_id); | 72 | virtual int on_reload_ingest_added(std::string vhost, std::string ingest_id); |
| @@ -83,6 +83,7 @@ SrsRtmpConn::SrsRtmpConn(SrsServer* srs_server, st_netfd_t client_stfd) | @@ -83,6 +83,7 @@ SrsRtmpConn::SrsRtmpConn(SrsServer* srs_server, st_netfd_t client_stfd) | ||
| 83 | duration = 0; | 83 | duration = 0; |
| 84 | kbps = new SrsKbps(); | 84 | kbps = new SrsKbps(); |
| 85 | kbps->set_io(skt, skt); | 85 | kbps->set_io(skt, skt); |
| 86 | + mw_sleep = SRS_PERF_MW_SLEEP; | ||
| 86 | 87 | ||
| 87 | _srs_config->subscribe(this); | 88 | _srs_config->subscribe(this); |
| 88 | } | 89 | } |
| @@ -209,6 +210,13 @@ int SrsRtmpConn::on_reload_vhost_removed(string vhost) | @@ -209,6 +210,13 @@ int SrsRtmpConn::on_reload_vhost_removed(string vhost) | ||
| 209 | return ret; | 210 | return ret; |
| 210 | } | 211 | } |
| 211 | 212 | ||
| 213 | +int SrsRtmpConn::on_reload_vhost_mw(string /*vhost*/) | ||
| 214 | +{ | ||
| 215 | + mw_sleep = _srs_config->get_mw_sleep_ms(req->vhost); | ||
| 216 | + | ||
| 217 | + return ERROR_SUCCESS; | ||
| 218 | +} | ||
| 219 | + | ||
| 212 | int64_t SrsRtmpConn::get_send_bytes_delta() | 220 | int64_t SrsRtmpConn::get_send_bytes_delta() |
| 213 | { | 221 | { |
| 214 | return kbps->get_send_bytes_delta(); | 222 | return kbps->get_send_bytes_delta(); |
| @@ -361,7 +369,7 @@ int SrsRtmpConn::stream_service_cycle() | @@ -361,7 +369,7 @@ int SrsRtmpConn::stream_service_cycle() | ||
| 361 | } | 369 | } |
| 362 | 370 | ||
| 363 | bool enabled_cache = _srs_config->get_gop_cache(req->vhost); | 371 | bool enabled_cache = _srs_config->get_gop_cache(req->vhost); |
| 364 | - srs_trace("source url=%s, ip=%s, cache=%d, is_edge=%d, source_id=%d[%d]", | 372 | + srs_trace("source url=%s, ip=%s, cache=%d, is_edge=%d, source_id=%d[%d]", |
| 365 | req->get_stream_url().c_str(), ip.c_str(), enabled_cache, vhost_is_edge, | 373 | req->get_stream_url().c_str(), ip.c_str(), enabled_cache, vhost_is_edge, |
| 366 | source->source_id(), source->source_id()); | 374 | source->source_id(), source->source_id()); |
| 367 | source->set_cache(enabled_cache); | 375 | source->set_cache(enabled_cache); |
| @@ -592,17 +600,18 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsQueueRecvThread* trd) | @@ -592,17 +600,18 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsQueueRecvThread* trd) | ||
| 592 | // no message to send, sleep a while. | 600 | // no message to send, sleep a while. |
| 593 | if (count <= 0) { | 601 | if (count <= 0) { |
| 594 | srs_verbose("sleep for no messages to send"); | 602 | srs_verbose("sleep for no messages to send"); |
| 595 | - st_usleep(SRS_PERF_SEND_MSGS_CACHE * 1000); | 603 | + st_usleep(mw_sleep * 1000); |
| 596 | } | 604 | } |
| 597 | 605 | ||
| 598 | // reportable | 606 | // reportable |
| 599 | if (pithy_print.can_print()) { | 607 | if (pithy_print.can_print()) { |
| 600 | kbps->sample(); | 608 | kbps->sample(); |
| 601 | srs_trace("-> "SRS_CONSTS_LOG_PLAY | 609 | srs_trace("-> "SRS_CONSTS_LOG_PLAY |
| 602 | - " time=%"PRId64", msgs=%d, okbps=%d,%d,%d, ikbps=%d,%d,%d", | 610 | + " time=%"PRId64", msgs=%d, okbps=%d,%d,%d, ikbps=%d,%d,%d, mw=%d", |
| 603 | pithy_print.age(), count, | 611 | pithy_print.age(), count, |
| 604 | kbps->get_send_kbps(), kbps->get_send_kbps_30s(), kbps->get_send_kbps_5m(), | 612 | kbps->get_send_kbps(), kbps->get_send_kbps_30s(), kbps->get_send_kbps_5m(), |
| 605 | - kbps->get_recv_kbps(), kbps->get_recv_kbps_30s(), kbps->get_recv_kbps_5m() | 613 | + kbps->get_recv_kbps(), kbps->get_recv_kbps_30s(), kbps->get_recv_kbps_5m(), |
| 614 | + mw_sleep | ||
| 606 | ); | 615 | ); |
| 607 | } | 616 | } |
| 608 | 617 | ||
| @@ -774,10 +783,14 @@ int SrsRtmpConn::do_publishing(SrsSource* source, SrsPublishRecvThread* trd) | @@ -774,10 +783,14 @@ int SrsRtmpConn::do_publishing(SrsSource* source, SrsPublishRecvThread* trd) | ||
| 774 | // reportable | 783 | // reportable |
| 775 | if (pithy_print.can_print()) { | 784 | if (pithy_print.can_print()) { |
| 776 | kbps->sample(); | 785 | kbps->sample(); |
| 786 | + bool mr = _srs_config->get_mr_enabled(req->vhost); | ||
| 787 | + int mr_sleep = _srs_config->get_mr_sleep_ms(req->vhost); | ||
| 777 | srs_trace("<- "SRS_CONSTS_LOG_CLIENT_PUBLISH | 788 | srs_trace("<- "SRS_CONSTS_LOG_CLIENT_PUBLISH |
| 778 | - " time=%"PRId64", okbps=%d,%d,%d, ikbps=%d,%d,%d", pithy_print.age(), | 789 | + " time=%"PRId64", okbps=%d,%d,%d, ikbps=%d,%d,%d, mr=%d/%d", pithy_print.age(), |
| 779 | kbps->get_send_kbps(), kbps->get_send_kbps_30s(), kbps->get_send_kbps_5m(), | 790 | kbps->get_send_kbps(), kbps->get_send_kbps_30s(), kbps->get_send_kbps_5m(), |
| 780 | - kbps->get_recv_kbps(), kbps->get_recv_kbps_30s(), kbps->get_recv_kbps_5m()); | 791 | + kbps->get_recv_kbps(), kbps->get_recv_kbps_30s(), kbps->get_recv_kbps_5m(), |
| 792 | + mr, mr_sleep | ||
| 793 | + ); | ||
| 781 | } | 794 | } |
| 782 | } | 795 | } |
| 783 | 796 |
| @@ -71,6 +71,8 @@ private: | @@ -71,6 +71,8 @@ private: | ||
| 71 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/47 | 71 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/47 |
| 72 | int64_t duration; | 72 | int64_t duration; |
| 73 | SrsKbps* kbps; | 73 | SrsKbps* kbps; |
| 74 | + // the MR(merged-write) sleep time in ms. | ||
| 75 | + int mw_sleep; | ||
| 74 | public: | 76 | public: |
| 75 | SrsRtmpConn(SrsServer* srs_server, st_netfd_t client_stfd); | 77 | SrsRtmpConn(SrsServer* srs_server, st_netfd_t client_stfd); |
| 76 | virtual ~SrsRtmpConn(); | 78 | virtual ~SrsRtmpConn(); |
| @@ -81,6 +83,7 @@ protected: | @@ -81,6 +83,7 @@ protected: | ||
| 81 | // interface ISrsReloadHandler | 83 | // interface ISrsReloadHandler |
| 82 | public: | 84 | public: |
| 83 | virtual int on_reload_vhost_removed(std::string vhost); | 85 | virtual int on_reload_vhost_removed(std::string vhost); |
| 86 | + virtual int on_reload_vhost_mw(std::string vhost); | ||
| 84 | // interface IKbpsDelta | 87 | // interface IKbpsDelta |
| 85 | public: | 88 | public: |
| 86 | virtual int64_t get_send_bytes_delta(); | 89 | virtual int64_t get_send_bytes_delta(); |
| @@ -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 2 | 32 | #define VERSION_MAJOR 2 |
| 33 | #define VERSION_MINOR 0 | 33 | #define VERSION_MINOR 0 |
| 34 | -#define VERSION_REVISION 52 | 34 | +#define VERSION_REVISION 53 |
| 35 | // server info. | 35 | // server info. |
| 36 | #define RTMP_SIG_SRS_KEY "SRS" | 36 | #define RTMP_SIG_SRS_KEY "SRS" |
| 37 | #define RTMP_SIG_SRS_ROLE "origin/edge server" | 37 | #define RTMP_SIG_SRS_ROLE "origin/edge server" |
| @@ -48,6 +48,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -48,6 +48,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 48 | #define RTMP_SIG_SRS_HANDSHAKE RTMP_SIG_SRS_KEY"("RTMP_SIG_SRS_VERSION")" | 48 | #define RTMP_SIG_SRS_HANDSHAKE RTMP_SIG_SRS_KEY"("RTMP_SIG_SRS_VERSION")" |
| 49 | #define RTMP_SIG_SRS_RELEASE "https://github.com/winlinvip/simple-rtmp-server/tree/1.0release" | 49 | #define RTMP_SIG_SRS_RELEASE "https://github.com/winlinvip/simple-rtmp-server/tree/1.0release" |
| 50 | #define RTMP_SIG_SRS_HTTP_SERVER "https://github.com/winlinvip/simple-rtmp-server/wiki/v1_CN_HTTPServer#feature" | 50 | #define RTMP_SIG_SRS_HTTP_SERVER "https://github.com/winlinvip/simple-rtmp-server/wiki/v1_CN_HTTPServer#feature" |
| 51 | +#define RTMP_SIG_SRS_ISSUES(id) "https://github.com/winlinvip/simple-rtmp-server/issues/"#id | ||
| 51 | #define RTMP_SIG_SRS_VERSION __SRS_XSTR(VERSION_MAJOR)"."__SRS_XSTR(VERSION_MINOR)"."__SRS_XSTR(VERSION_REVISION) | 52 | #define RTMP_SIG_SRS_VERSION __SRS_XSTR(VERSION_MAJOR)"."__SRS_XSTR(VERSION_MINOR)"."__SRS_XSTR(VERSION_REVISION) |
| 52 | 53 | ||
| 53 | // internal macros, covert macro values to str, | 54 | // internal macros, covert macro values to str, |
| @@ -38,6 +38,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -38,6 +38,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 38 | * to improve read performance, merge some packets then read, | 38 | * to improve read performance, merge some packets then read, |
| 39 | * when it on and read small bytes, we sleep to wait more data., | 39 | * when it on and read small bytes, we sleep to wait more data., |
| 40 | * that is, we merge some data to read together. | 40 | * that is, we merge some data to read together. |
| 41 | +* @see SrsConfig::get_mr_enabled() | ||
| 42 | +* @see SrsConfig::get_mr_sleep_ms() | ||
| 41 | * @see https://github.com/winlinvip/simple-rtmp-server/issues/241 | 43 | * @see https://github.com/winlinvip/simple-rtmp-server/issues/241 |
| 42 | * @example, for the default settings, this algorithm will use: | 44 | * @example, for the default settings, this algorithm will use: |
| 43 | * that is, when got nread bytes smaller than 4KB, sleep(780ms). | 45 | * that is, when got nread bytes smaller than 4KB, sleep(780ms). |
| @@ -55,11 +57,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -55,11 +57,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 55 | * For example, sleep 120ms. Then there is, and always 120ms data in buffer. | 57 | * For example, sleep 120ms. Then there is, and always 120ms data in buffer. |
| 56 | * That is, the latency is 120ms(the sleep time). | 58 | * That is, the latency is 120ms(the sleep time). |
| 57 | */ | 59 | */ |
| 58 | -// to enable merged read. | ||
| 59 | #define SRS_PERF_MERGED_READ | 60 | #define SRS_PERF_MERGED_READ |
| 61 | +// the default config of mr. | ||
| 62 | +#define SRS_PERF_MR_ENABLED false | ||
| 63 | +#define SRS_PERF_MR_SLEEP 500 | ||
| 60 | 64 | ||
| 61 | /** | 65 | /** |
| 62 | -* the send cache time in ms. | 66 | +* the MW(merged-write) send cache time in ms. |
| 67 | +* the default value, user can override it in config. | ||
| 63 | * to improve send performance, cache msgs and send in a time. | 68 | * to improve send performance, cache msgs and send in a time. |
| 64 | * for example, cache 500ms videos and audios, then convert all these | 69 | * for example, cache 500ms videos and audios, then convert all these |
| 65 | * msgs to iovecs, finally use writev to send. | 70 | * msgs to iovecs, finally use writev to send. |
| @@ -67,8 +72,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -67,8 +72,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 67 | * the latency+ when cache+. | 72 | * the latency+ when cache+. |
| 68 | * @remark the socket send buffer default to 185KB, it large enough. | 73 | * @remark the socket send buffer default to 185KB, it large enough. |
| 69 | * @see https://github.com/winlinvip/simple-rtmp-server/issues/194 | 74 | * @see https://github.com/winlinvip/simple-rtmp-server/issues/194 |
| 75 | +* @see SrsConfig::get_mw_sleep_ms() | ||
| 70 | */ | 76 | */ |
| 71 | -#define SRS_PERF_SEND_MSGS_CACHE 500 | 77 | +// the default config of mw. |
| 78 | +#define SRS_PERF_MW_SLEEP 500 | ||
| 72 | 79 | ||
| 73 | /** | 80 | /** |
| 74 | * how many chunk stream to cache, [0, N]. | 81 | * how many chunk stream to cache, [0, N]. |
| @@ -78,5 +85,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -78,5 +85,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 78 | */ | 85 | */ |
| 79 | #define SRS_PERF_CHUNK_STREAM_CACHE 16 | 86 | #define SRS_PERF_CHUNK_STREAM_CACHE 16 |
| 80 | 87 | ||
| 88 | +/** | ||
| 89 | +* the gop cache and play cache queue. | ||
| 90 | +*/ | ||
| 91 | +// whether gop cache is on. | ||
| 92 | +#define SRS_PERF_GOP_CACHE true | ||
| 93 | +// in seconds, the live queue length. | ||
| 94 | +#define SRS_PERF_PLAY_QUEUE 30 | ||
| 95 | + | ||
| 81 | #endif | 96 | #endif |
| 82 | 97 |
| @@ -50,10 +50,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -50,10 +50,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 50 | // 6. Chunking, RTMP protocol default chunk size. | 50 | // 6. Chunking, RTMP protocol default chunk size. |
| 51 | #define SRS_CONSTS_RTMP_PROTOCOL_CHUNK_SIZE 128 | 51 | #define SRS_CONSTS_RTMP_PROTOCOL_CHUNK_SIZE 128 |
| 52 | 52 | ||
| 53 | -// the default setting of mr. | ||
| 54 | -#define SRS_CONSTS_RTMP_MR false | ||
| 55 | -#define SRS_CONSTS_RTMP_MR_SLEEP 500 | ||
| 56 | - | ||
| 57 | /** | 53 | /** |
| 58 | * 6. Chunking | 54 | * 6. Chunking |
| 59 | * The chunk size is configurable. It can be set using a control | 55 | * The chunk size is configurable. It can be set using a control |
| @@ -39,6 +39,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -39,6 +39,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 39 | #include <srs_app_config.hpp> | 39 | #include <srs_app_config.hpp> |
| 40 | #include <srs_app_log.hpp> | 40 | #include <srs_app_log.hpp> |
| 41 | #include <srs_kernel_utility.hpp> | 41 | #include <srs_kernel_utility.hpp> |
| 42 | +#include <srs_core_performance.hpp> | ||
| 42 | 43 | ||
| 43 | // pre-declare | 44 | // pre-declare |
| 44 | int run(); | 45 | int run(); |
| @@ -130,6 +131,24 @@ void show_macro_features() | @@ -130,6 +131,24 @@ void show_macro_features() | ||
| 130 | #else | 131 | #else |
| 131 | srs_warn("check feature compile ffmpeg: off"); | 132 | srs_warn("check feature compile ffmpeg: off"); |
| 132 | #endif | 133 | #endif |
| 134 | + | ||
| 135 | +#ifdef SRS_PERF_MERGED_READ | ||
| 136 | + srs_trace("MR(merged-read): on, @see %s", RTMP_SIG_SRS_ISSUES(241)); | ||
| 137 | +#else | ||
| 138 | + srs_warn("MR(merged-read): off, @see %s", RTMP_SIG_SRS_ISSUES(241)); | ||
| 139 | +#endif | ||
| 140 | + | ||
| 141 | + srs_trace("MR(merged-read) default %d sleep %d", SRS_PERF_MR_ENABLED, SRS_PERF_MR_SLEEP); | ||
| 142 | + srs_trace("MW(merged-write) default sleep %d", SRS_PERF_MW_SLEEP); | ||
| 143 | + srs_trace("read chunk stream cache cid [0, %d)", SRS_PERF_CHUNK_STREAM_CACHE); | ||
| 144 | + srs_trace("default gop cache %d, play queue %ds", SRS_PERF_GOP_CACHE, SRS_PERF_PLAY_QUEUE); | ||
| 145 | + | ||
| 146 | + int possible_mr_latency = 0; | ||
| 147 | +#ifdef SRS_PERF_MERGED_READ | ||
| 148 | + possible_mr_latency = SRS_PERF_MR_SLEEP; | ||
| 149 | +#endif | ||
| 150 | + srs_trace("system default latency in ms: mw(0-%d) + mr(0-%d) + play-queue(0-%d)", | ||
| 151 | + SRS_PERF_MW_SLEEP, possible_mr_latency, SRS_PERF_PLAY_QUEUE*1000); | ||
| 133 | } | 152 | } |
| 134 | 153 | ||
| 135 | void check_macro_features() | 154 | void check_macro_features() |
| @@ -139,6 +158,10 @@ void check_macro_features() | @@ -139,6 +158,10 @@ void check_macro_features() | ||
| 139 | srs_warn("http server is dev feature, @see %s", RTMP_SIG_SRS_HTTP_SERVER); | 158 | srs_warn("http server is dev feature, @see %s", RTMP_SIG_SRS_HTTP_SERVER); |
| 140 | #endif | 159 | #endif |
| 141 | 160 | ||
| 161 | +#ifndef SRS_PERF_MERGED_READ | ||
| 162 | + srs_warn("MR(merged-read) is disabled, hurts read performance. @see %s", RTMP_SIG_SRS_ISSUES(241)); | ||
| 163 | +#endif | ||
| 164 | + | ||
| 142 | #if VERSION_MAJOR > 1 | 165 | #if VERSION_MAJOR > 1 |
| 143 | #warning "using develop SRS, please use release instead." | 166 | #warning "using develop SRS, please use release instead." |
| 144 | srs_warn("SRS %s is develop branch, please use %s instead", RTMP_SIG_SRS_VERSION, RTMP_SIG_SRS_RELEASE); | 167 | srs_warn("SRS %s is develop branch, please use %s instead", RTMP_SIG_SRS_VERSION, RTMP_SIG_SRS_RELEASE); |
-
请 注册 或 登录 后发表评论