From 9fb4640a8f5d1562d57981578585928d5bd24760 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 12 Aug 2015 13:22:09 +0800 Subject: [PATCH] enable the SRS_PERF_TCP_NODELAY and add config tcp_nodelay. 2.0.182 --- README.md | 1 + trunk/conf/full.conf | 4 ++++ trunk/conf/realtime.conf | 1 + trunk/src/app/srs_app_config.cpp | 19 ++++++++++++++++++- trunk/src/app/srs_app_config.hpp | 4 ++++ trunk/src/app/srs_app_rtmp_conn.cpp | 13 +++++++++---- trunk/src/app/srs_app_rtmp_conn.hpp | 2 +- trunk/src/core/srs_core.hpp | 2 +- trunk/src/core/srs_core_performance.hpp | 10 +++++----- 9 files changed, 44 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 8c52a875a..01c5e1a55 100755 --- a/README.md +++ b/README.md @@ -342,6 +342,7 @@ Remark: ## History +* v2.0, 2015-08-12, enable the SRS_PERF_TCP_NODELAY and add config tcp_nodelay. 2.0.182 * v2.0, 2015-08-11, for [#442](https://github.com/simple-rtmp-server/srs/issues/442) support kickoff connected client. 2.0.181 * v2.0, 2015-07-21, for [#169](https://github.com/simple-rtmp-server/srs/issues/169) support default values for transcode. 2.0.180 * v2.0, 2015-07-21, fix [#435](https://github.com/simple-rtmp-server/srs/issues/435) add pageUrl for HTTP callback on_play. diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index 9764c1ed9..14414bd17 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -851,6 +851,10 @@ vhost min.delay.com { # drop the old whole gop. # default: 30 queue_length 10; + # whether enable the TCP_NODELAY + # if on, set the nodelay of fd by setsockopt + # default: off + tcp_nodelay on; } # the vhost for antisuck. diff --git a/trunk/conf/realtime.conf b/trunk/conf/realtime.conf index 4257019b3..a87f293f4 100644 --- a/trunk/conf/realtime.conf +++ b/trunk/conf/realtime.conf @@ -12,4 +12,5 @@ vhost __defaultVhost__ { enabled off; } mw_latency 100; + tcp_nodelay on; } diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 37a650f95..d14154a72 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -1750,7 +1750,7 @@ int SrsConfig::check_config() && n != "time_jitter" && n != "mix_correct" && n != "atc" && n != "atc_auto" && n != "debug_srs_upnode" - && n != "mr" && n != "mw_latency" && n != "min_latency" + && n != "mr" && n != "mw_latency" && n != "min_latency" && n != "tcp_nodelay" && n != "security" && n != "http_remux" && n != "http" && n != "http_static" && n != "hds" @@ -2489,6 +2489,23 @@ bool SrsConfig::get_realtime_enabled(string vhost) return SRS_CONF_PERFER_FALSE(conf->arg0()); } +bool SrsConfig::get_tcp_nodelay(string vhost) +{ + static bool DEFAULT = false; + + SrsConfDirective* conf = get_vhost(vhost); + if (!conf) { + return DEFAULT; + } + + conf = conf->get("tcp_nodelay"); + if (!conf || conf->arg0().empty()) { + return DEFAULT; + } + + return SRS_CONF_PERFER_FALSE(conf->arg0()); +} + int SrsConfig::get_global_chunk_size() { SrsConfDirective* conf = root->get("chunk_size"); diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 2c5f52d5f..a1ca864e1 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -522,6 +522,10 @@ public: */ // TODO: FIXME: add utest for min_latency. virtual bool get_realtime_enabled(std::string vhost); + /** + * whether enable tcp nodelay for all clients of vhost. + */ + virtual bool get_tcp_nodelay(std::string vhost); private: /** * get the global chunk size. diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index ae2ad3cd8..8b796b8ab 100755 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -591,7 +591,7 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRe change_mw_sleep(_srs_config->get_mw_sleep_ms(req->vhost)); // set the sock options. - play_set_sock_options(); + set_sock_options(); while (!disposed) { // collect elapse for pithy print. @@ -769,6 +769,9 @@ int SrsRtmpConn::do_publishing(SrsSource* source, SrsPublishRecvThread* trd) srs_error("start isolate recv thread failed. ret=%d", ret); return ret; } + + // set the sock options. + set_sock_options(); int64_t nb_msgs = 0; while (!disposed) { @@ -1093,10 +1096,10 @@ void SrsRtmpConn::change_mw_sleep(int sleep_ms) mw_sleep = sleep_ms; } -void SrsRtmpConn::play_set_sock_options() +void SrsRtmpConn::set_sock_options() { + if (_srs_config->get_tcp_nodelay(req->vhost)) { #ifdef SRS_PERF_TCP_NODELAY - if (true) { int fd = st_netfd_fileno(stfd); socklen_t nb_v = sizeof(int); @@ -1112,8 +1115,10 @@ void SrsRtmpConn::play_set_sock_options() getsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &v, &nb_v); srs_trace("set TCP_NODELAY %d=>%d", ov, v); - } +#else + srs_warn("SRS_PERF_TCP_NODELAY is disabled but tcp_nodelay configed."); #endif + } } int SrsRtmpConn::check_edge_token_traverse_auth() diff --git a/trunk/src/app/srs_app_rtmp_conn.hpp b/trunk/src/app/srs_app_rtmp_conn.hpp index ddaa7e349..683a23271 100755 --- a/trunk/src/app/srs_app_rtmp_conn.hpp +++ b/trunk/src/app/srs_app_rtmp_conn.hpp @@ -119,7 +119,7 @@ private: virtual int process_publish_message(SrsSource* source, SrsCommonMessage* msg, bool vhost_is_edge); virtual int process_play_control_msg(SrsConsumer* consumer, SrsCommonMessage* msg); virtual void change_mw_sleep(int sleep_ms); - virtual void play_set_sock_options(); + virtual void set_sock_options(); private: virtual int check_edge_token_traverse_auth(); virtual int connect_server(int origin_index, st_netfd_t* pstsock); diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index 87d139332..02c33b36b 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // current release version #define VERSION_MAJOR 2 #define VERSION_MINOR 0 -#define VERSION_REVISION 181 +#define VERSION_REVISION 182 // server info. #define RTMP_SIG_SRS_KEY "SRS" diff --git a/trunk/src/core/srs_core_performance.hpp b/trunk/src/core/srs_core_performance.hpp index f68efced2..897540b62 100644 --- a/trunk/src/core/srs_core_performance.hpp +++ b/trunk/src/core/srs_core_performance.hpp @@ -163,12 +163,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. //#undef SRS_PERF_COMPLEX_SEND #define SRS_PERF_COMPLEX_SEND /** -* whether enable the TCP_NODELAY -* user maybe need send small tcp packet for some network. -* @see https://github.com/simple-rtmp-server/srs/issues/320 -*/ -//#define SRS_PERF_TCP_NODELAY + * whether enable the TCP_NODELAY + * user maybe need send small tcp packet for some network. + * @see https://github.com/simple-rtmp-server/srs/issues/320 + */ #undef SRS_PERF_TCP_NODELAY +#define SRS_PERF_TCP_NODELAY /** * set the socket send buffer, * to force the server to send smaller tcp packet.