winlin

enable the SRS_PERF_TCP_NODELAY and add config tcp_nodelay. 2.0.182

@@ -342,6 +342,7 @@ Remark: @@ -342,6 +342,7 @@ Remark:
342 342
343 ## History 343 ## History
344 344
  345 +* v2.0, 2015-08-12, enable the SRS_PERF_TCP_NODELAY and add config tcp_nodelay. 2.0.182
345 * v2.0, 2015-08-11, for [#442](https://github.com/simple-rtmp-server/srs/issues/442) support kickoff connected client. 2.0.181 346 * v2.0, 2015-08-11, for [#442](https://github.com/simple-rtmp-server/srs/issues/442) support kickoff connected client. 2.0.181
346 * v2.0, 2015-07-21, for [#169](https://github.com/simple-rtmp-server/srs/issues/169) support default values for transcode. 2.0.180 347 * v2.0, 2015-07-21, for [#169](https://github.com/simple-rtmp-server/srs/issues/169) support default values for transcode. 2.0.180
347 * v2.0, 2015-07-21, fix [#435](https://github.com/simple-rtmp-server/srs/issues/435) add pageUrl for HTTP callback on_play. 348 * v2.0, 2015-07-21, fix [#435](https://github.com/simple-rtmp-server/srs/issues/435) add pageUrl for HTTP callback on_play.
@@ -851,6 +851,10 @@ vhost min.delay.com { @@ -851,6 +851,10 @@ vhost min.delay.com {
851 # drop the old whole gop. 851 # drop the old whole gop.
852 # default: 30 852 # default: 30
853 queue_length 10; 853 queue_length 10;
  854 + # whether enable the TCP_NODELAY
  855 + # if on, set the nodelay of fd by setsockopt
  856 + # default: off
  857 + tcp_nodelay on;
854 } 858 }
855 859
856 # the vhost for antisuck. 860 # the vhost for antisuck.
@@ -12,4 +12,5 @@ vhost __defaultVhost__ { @@ -12,4 +12,5 @@ vhost __defaultVhost__ {
12 enabled off; 12 enabled off;
13 } 13 }
14 mw_latency 100; 14 mw_latency 100;
  15 + tcp_nodelay on;
15 } 16 }
@@ -1750,7 +1750,7 @@ int SrsConfig::check_config() @@ -1750,7 +1750,7 @@ int SrsConfig::check_config()
1750 && n != "time_jitter" && n != "mix_correct" 1750 && n != "time_jitter" && n != "mix_correct"
1751 && n != "atc" && n != "atc_auto" 1751 && n != "atc" && n != "atc_auto"
1752 && n != "debug_srs_upnode" 1752 && n != "debug_srs_upnode"
1753 - && n != "mr" && n != "mw_latency" && n != "min_latency" 1753 + && n != "mr" && n != "mw_latency" && n != "min_latency" && n != "tcp_nodelay"
1754 && n != "security" && n != "http_remux" 1754 && n != "security" && n != "http_remux"
1755 && n != "http" && n != "http_static" 1755 && n != "http" && n != "http_static"
1756 && n != "hds" 1756 && n != "hds"
@@ -2489,6 +2489,23 @@ bool SrsConfig::get_realtime_enabled(string vhost) @@ -2489,6 +2489,23 @@ bool SrsConfig::get_realtime_enabled(string vhost)
2489 return SRS_CONF_PERFER_FALSE(conf->arg0()); 2489 return SRS_CONF_PERFER_FALSE(conf->arg0());
2490 } 2490 }
2491 2491
  2492 +bool SrsConfig::get_tcp_nodelay(string vhost)
  2493 +{
  2494 + static bool DEFAULT = false;
  2495 +
  2496 + SrsConfDirective* conf = get_vhost(vhost);
  2497 + if (!conf) {
  2498 + return DEFAULT;
  2499 + }
  2500 +
  2501 + conf = conf->get("tcp_nodelay");
  2502 + if (!conf || conf->arg0().empty()) {
  2503 + return DEFAULT;
  2504 + }
  2505 +
  2506 + return SRS_CONF_PERFER_FALSE(conf->arg0());
  2507 +}
  2508 +
2492 int SrsConfig::get_global_chunk_size() 2509 int SrsConfig::get_global_chunk_size()
2493 { 2510 {
2494 SrsConfDirective* conf = root->get("chunk_size"); 2511 SrsConfDirective* conf = root->get("chunk_size");
@@ -522,6 +522,10 @@ public: @@ -522,6 +522,10 @@ public:
522 */ 522 */
523 // TODO: FIXME: add utest for min_latency. 523 // TODO: FIXME: add utest for min_latency.
524 virtual bool get_realtime_enabled(std::string vhost); 524 virtual bool get_realtime_enabled(std::string vhost);
  525 + /**
  526 + * whether enable tcp nodelay for all clients of vhost.
  527 + */
  528 + virtual bool get_tcp_nodelay(std::string vhost);
525 private: 529 private:
526 /** 530 /**
527 * get the global chunk size. 531 * get the global chunk size.
@@ -591,7 +591,7 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRe @@ -591,7 +591,7 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRe
591 change_mw_sleep(_srs_config->get_mw_sleep_ms(req->vhost)); 591 change_mw_sleep(_srs_config->get_mw_sleep_ms(req->vhost));
592 592
593 // set the sock options. 593 // set the sock options.
594 - play_set_sock_options(); 594 + set_sock_options();
595 595
596 while (!disposed) { 596 while (!disposed) {
597 // collect elapse for pithy print. 597 // collect elapse for pithy print.
@@ -769,6 +769,9 @@ int SrsRtmpConn::do_publishing(SrsSource* source, SrsPublishRecvThread* trd) @@ -769,6 +769,9 @@ int SrsRtmpConn::do_publishing(SrsSource* source, SrsPublishRecvThread* trd)
769 srs_error("start isolate recv thread failed. ret=%d", ret); 769 srs_error("start isolate recv thread failed. ret=%d", ret);
770 return ret; 770 return ret;
771 } 771 }
  772 +
  773 + // set the sock options.
  774 + set_sock_options();
772 775
773 int64_t nb_msgs = 0; 776 int64_t nb_msgs = 0;
774 while (!disposed) { 777 while (!disposed) {
@@ -1093,10 +1096,10 @@ void SrsRtmpConn::change_mw_sleep(int sleep_ms) @@ -1093,10 +1096,10 @@ void SrsRtmpConn::change_mw_sleep(int sleep_ms)
1093 mw_sleep = sleep_ms; 1096 mw_sleep = sleep_ms;
1094 } 1097 }
1095 1098
1096 -void SrsRtmpConn::play_set_sock_options() 1099 +void SrsRtmpConn::set_sock_options()
1097 { 1100 {
  1101 + if (_srs_config->get_tcp_nodelay(req->vhost)) {
1098 #ifdef SRS_PERF_TCP_NODELAY 1102 #ifdef SRS_PERF_TCP_NODELAY
1099 - if (true) {  
1100 int fd = st_netfd_fileno(stfd); 1103 int fd = st_netfd_fileno(stfd);
1101 1104
1102 socklen_t nb_v = sizeof(int); 1105 socklen_t nb_v = sizeof(int);
@@ -1112,8 +1115,10 @@ void SrsRtmpConn::play_set_sock_options() @@ -1112,8 +1115,10 @@ void SrsRtmpConn::play_set_sock_options()
1112 getsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &v, &nb_v); 1115 getsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &v, &nb_v);
1113 1116
1114 srs_trace("set TCP_NODELAY %d=>%d", ov, v); 1117 srs_trace("set TCP_NODELAY %d=>%d", ov, v);
1115 - } 1118 +#else
  1119 + srs_warn("SRS_PERF_TCP_NODELAY is disabled but tcp_nodelay configed.");
1116 #endif 1120 #endif
  1121 + }
1117 } 1122 }
1118 1123
1119 int SrsRtmpConn::check_edge_token_traverse_auth() 1124 int SrsRtmpConn::check_edge_token_traverse_auth()
@@ -119,7 +119,7 @@ private: @@ -119,7 +119,7 @@ private:
119 virtual int process_publish_message(SrsSource* source, SrsCommonMessage* msg, bool vhost_is_edge); 119 virtual int process_publish_message(SrsSource* source, SrsCommonMessage* msg, bool vhost_is_edge);
120 virtual int process_play_control_msg(SrsConsumer* consumer, SrsCommonMessage* msg); 120 virtual int process_play_control_msg(SrsConsumer* consumer, SrsCommonMessage* msg);
121 virtual void change_mw_sleep(int sleep_ms); 121 virtual void change_mw_sleep(int sleep_ms);
122 - virtual void play_set_sock_options(); 122 + virtual void set_sock_options();
123 private: 123 private:
124 virtual int check_edge_token_traverse_auth(); 124 virtual int check_edge_token_traverse_auth();
125 virtual int connect_server(int origin_index, st_netfd_t* pstsock); 125 virtual int connect_server(int origin_index, st_netfd_t* pstsock);
@@ -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 181 34 +#define VERSION_REVISION 182
35 35
36 // server info. 36 // server info.
37 #define RTMP_SIG_SRS_KEY "SRS" 37 #define RTMP_SIG_SRS_KEY "SRS"
@@ -163,12 +163,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -163,12 +163,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
163 //#undef SRS_PERF_COMPLEX_SEND 163 //#undef SRS_PERF_COMPLEX_SEND
164 #define SRS_PERF_COMPLEX_SEND 164 #define SRS_PERF_COMPLEX_SEND
165 /** 165 /**
166 -* whether enable the TCP_NODELAY  
167 -* user maybe need send small tcp packet for some network.  
168 -* @see https://github.com/simple-rtmp-server/srs/issues/320  
169 -*/  
170 -//#define SRS_PERF_TCP_NODELAY 166 + * whether enable the TCP_NODELAY
  167 + * user maybe need send small tcp packet for some network.
  168 + * @see https://github.com/simple-rtmp-server/srs/issues/320
  169 + */
171 #undef SRS_PERF_TCP_NODELAY 170 #undef SRS_PERF_TCP_NODELAY
  171 +#define SRS_PERF_TCP_NODELAY
172 /** 172 /**
173 * set the socket send buffer, 173 * set the socket send buffer,
174 * to force the server to send smaller tcp packet. 174 * to force the server to send smaller tcp packet.