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

for #320, support macro to disable the complex send algorithm and enable tcp no delay. 2.0.129

This commit is contained in:
winlin 2015-03-03 17:22:44 +08:00
parent f619f174e6
commit 34d6a2ece5
7 changed files with 120 additions and 20 deletions

4
trunk/ide/srs_upp/init Normal file → Executable file
View file

@ -1,3 +1,3 @@
#ifndef _srs_icpp_init_stub #ifndef _srs_upp_icpp_init_stub
#define _srs_icpp_init_stub #define _srs_upp_icpp_init_stub
#endif #endif

View file

@ -36,8 +36,8 @@ file
../../src/kernel/srs_kernel_log.cpp, ../../src/kernel/srs_kernel_log.cpp,
../../src/kernel/srs_kernel_mp3.hpp, ../../src/kernel/srs_kernel_mp3.hpp,
../../src/kernel/srs_kernel_mp3.cpp, ../../src/kernel/srs_kernel_mp3.cpp,
../../src/kernel/srs_rtsp_stack.hpp, ../../src/kernel/srs_rtsp_stack.hpp,
../../src/kernel/srs_rtsp_stack.cpp, ../../src/kernel/srs_rtsp_stack.cpp,
../../src/kernel/srs_kernel_stream.hpp, ../../src/kernel/srs_kernel_stream.hpp,
../../src/kernel/srs_kernel_stream.cpp, ../../src/kernel/srs_kernel_stream.cpp,
../../src/kernel/srs_kernel_ts.cpp, ../../src/kernel/srs_kernel_ts.cpp,
@ -45,8 +45,8 @@ file
../../src/kernel/srs_kernel_utility.hpp, ../../src/kernel/srs_kernel_utility.hpp,
../../src/kernel/srs_kernel_utility.cpp, ../../src/kernel/srs_kernel_utility.cpp,
protocol readonly separator, protocol readonly separator,
../../src/protocol/srs_raw_avc.hpp, ../../src/protocol/srs_raw_avc.hpp,
../../src/protocol/srs_raw_avc.cpp, ../../src/protocol/srs_raw_avc.cpp,
../../src/protocol/srs_rtmp_amf0.hpp, ../../src/protocol/srs_rtmp_amf0.hpp,
../../src/protocol/srs_rtmp_amf0.cpp, ../../src/protocol/srs_rtmp_amf0.cpp,
../../src/protocol/srs_rtmp_buffer.hpp, ../../src/protocol/srs_rtmp_buffer.hpp,
@ -102,8 +102,8 @@ file
../../src/app/srs_app_json.cpp, ../../src/app/srs_app_json.cpp,
../../src/app/srs_app_kbps.hpp, ../../src/app/srs_app_kbps.hpp,
../../src/app/srs_app_kbps.cpp, ../../src/app/srs_app_kbps.cpp,
../../src/app/srs_app_listener.hpp, ../../src/app/srs_app_listener.hpp,
../../src/app/srs_app_listener.cpp, ../../src/app/srs_app_listener.cpp,
../../src/app/srs_app_log.hpp, ../../src/app/srs_app_log.hpp,
../../src/app/srs_app_log.cpp, ../../src/app/srs_app_log.cpp,
../../src/app/srs_app_mpegts_udp.hpp, ../../src/app/srs_app_mpegts_udp.hpp,
@ -116,8 +116,8 @@ file
../../src/app/srs_app_reload.cpp, ../../src/app/srs_app_reload.cpp,
../../src/app/srs_app_rtmp_conn.hpp, ../../src/app/srs_app_rtmp_conn.hpp,
../../src/app/srs_app_rtmp_conn.cpp, ../../src/app/srs_app_rtmp_conn.cpp,
../../src/app/srs_app_rtsp.hpp, ../../src/app/srs_app_rtsp.hpp,
../../src/app/srs_app_rtsp.cpp, ../../src/app/srs_app_rtsp.cpp,
../../src/app/srs_app_pithy_print.hpp, ../../src/app/srs_app_pithy_print.hpp,
../../src/app/srs_app_pithy_print.cpp, ../../src/app/srs_app_pithy_print.cpp,
../../src/app/srs_app_security.hpp, ../../src/app/srs_app_security.hpp,

View file

@ -27,6 +27,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netinet/tcp.h>
using namespace std; using namespace std;
@ -624,6 +625,9 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRe
mw_enabled = true; mw_enabled = true;
change_mw_sleep(_srs_config->get_mw_sleep_ms(req->vhost)); change_mw_sleep(_srs_config->get_mw_sleep_ms(req->vhost));
// set the sock options.
play_set_sock_options();
while (true) { while (true) {
// collect elapse for pithy print. // collect elapse for pithy print.
pprint->elapse(); pprint->elapse();
@ -1089,7 +1093,7 @@ void SrsRtmpConn::change_mw_sleep(int sleep_ms)
socklen_t sock_buf_size = sizeof(int); socklen_t sock_buf_size = sizeof(int);
getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &onb_sbuf, &sock_buf_size); getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &onb_sbuf, &sock_buf_size);
#ifdef SRS_PERF_MW_SO_SNDBUF #ifdef SRS_PERF_MW_SO_SNDBUF
// the bytes: // the bytes:
// 4KB=4096, 8KB=8192, 16KB=16384, 32KB=32768, 64KB=65536, // 4KB=4096, 8KB=8192, 16KB=16384, 32KB=32768, 64KB=65536,
// 128KB=131072, 256KB=262144, 512KB=524288 // 128KB=131072, 256KB=262144, 512KB=524288
@ -1123,6 +1127,29 @@ void SrsRtmpConn::change_mw_sleep(int sleep_ms)
mw_sleep = sleep_ms; mw_sleep = sleep_ms;
} }
void SrsRtmpConn::play_set_sock_options()
{
int fd = st_netfd_fileno(stfd);
#ifdef SRS_PERF_TCP_NODELAY
if (true) {
socklen_t nb_v = sizeof(int);
int ov = 0;
getsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &ov, &nb_v);
int v = 1;
// set the socket send buffer when required larger buffer
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &v, nb_v) < 0) {
srs_warn("set sock TCP_NODELAY=%d failed.", v);
}
getsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &v, &nb_v);
srs_trace("set TCP_NODELAY %d=>%d", ov, v);
}
#endif
}
int SrsRtmpConn::check_edge_token_traverse_auth() int SrsRtmpConn::check_edge_token_traverse_auth()
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;

View file

@ -111,6 +111,7 @@ private:
virtual int process_publish_message(SrsSource* source, SrsCommonMessage* msg, bool vhost_is_edge); virtual int process_publish_message(SrsSource* source, SrsCommonMessage* msg, bool vhost_is_edge);
virtual int process_play_control_msg(SrsConsumer* consumer, SrsCommonMessage* msg); virtual int process_play_control_msg(SrsConsumer* consumer, SrsCommonMessage* msg);
virtual void change_mw_sleep(int sleep_ms); virtual void change_mw_sleep(int sleep_ms);
virtual void play_set_sock_options();
private: private:
virtual int check_edge_token_traverse_auth(); virtual int check_edge_token_traverse_auth();
virtual int connect_server(int origin_index, st_netfd_t* pstsock); virtual int connect_server(int origin_index, st_netfd_t* pstsock);

View file

@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version // current release version
#define VERSION_MAJOR 2 #define VERSION_MAJOR 2
#define VERSION_MINOR 0 #define VERSION_MINOR 0
#define VERSION_REVISION 128 #define VERSION_REVISION 129
// server info. // server info.
#define RTMP_SIG_SRS_KEY "SRS" #define RTMP_SIG_SRS_KEY "SRS"

View file

@ -108,7 +108,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* whether set the socket send buffer size. * whether set the socket send buffer size.
* @see https://github.com/winlinvip/simple-rtmp-server/issues/251 * @see https://github.com/winlinvip/simple-rtmp-server/issues/251
*/ */
#undef SRS_PERF_MW_SO_SNDBUF #define SRS_PERF_MW_SO_SNDBUF
/** /**
* whether set the socket recv buffer size. * whether set the socket recv buffer size.
* @see https://github.com/winlinvip/simple-rtmp-server/issues/251 * @see https://github.com/winlinvip/simple-rtmp-server/issues/251
@ -154,5 +155,20 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// in seconds, the live queue length. // in seconds, the live queue length.
#define SRS_PERF_PLAY_QUEUE 30 #define SRS_PERF_PLAY_QUEUE 30
/**
* whether always use complex send algorithm.
* for some network does not support the complex send,
* @see https://github.com/winlinvip/simple-rtmp-server/issues/320
*/
//#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/winlinvip/simple-rtmp-server/issues/320
*/
//#define SRS_PERF_TCP_NODELAY
#undef SRS_PERF_TCP_NODELAY
#endif #endif

View file

@ -762,8 +762,9 @@ int SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msgs)
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
#ifdef SRS_PERF_COMPLEX_SEND
int iov_index = 0; int iov_index = 0;
iovec* iov = out_iovs + iov_index; iovec* iovs = out_iovs + iov_index;
int c0c3_cache_index = 0; int c0c3_cache_index = 0;
char* c0c3_cache = out_c0c3_caches + c0c3_cache_index; char* c0c3_cache = out_c0c3_caches + c0c3_cache_index;
@ -796,13 +797,13 @@ int SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msgs)
srs_assert(nbh > 0); srs_assert(nbh > 0);
// header iov // header iov
iov[0].iov_base = c0c3_cache; iovs[0].iov_base = c0c3_cache;
iov[0].iov_len = nbh; iovs[0].iov_len = nbh;
// payload iov // payload iov
int payload_size = srs_min(out_chunk_size, pend - p); int payload_size = srs_min(out_chunk_size, pend - p);
iov[1].iov_base = p; iovs[1].iov_base = p;
iov[1].iov_len = payload_size; iovs[1].iov_len = payload_size;
// consume sendout bytes. // consume sendout bytes.
p += payload_size; p += payload_size;
@ -822,7 +823,7 @@ int SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msgs)
// to next pair of iovs // to next pair of iovs
iov_index += 2; iov_index += 2;
iov = out_iovs + iov_index; iovs = out_iovs + iov_index;
// to next c0c3 header cache // to next c0c3 header cache
c0c3_cache_index += nbh; c0c3_cache_index += nbh;
@ -849,7 +850,7 @@ int SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msgs)
// reset caches, while these cache ensure // reset caches, while these cache ensure
// atleast we can sendout a chunk. // atleast we can sendout a chunk.
iov_index = 0; iov_index = 0;
iov = out_iovs + iov_index; iovs = out_iovs + iov_index;
c0c3_cache_index = 0; c0c3_cache_index = 0;
c0c3_cache = out_c0c3_caches + c0c3_cache_index; c0c3_cache = out_c0c3_caches + c0c3_cache_index;
@ -866,6 +867,61 @@ int SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msgs)
nb_msgs, iov_index, SRS_PERF_MW_MSGS, nb_out_iovs); nb_msgs, iov_index, SRS_PERF_MW_MSGS, nb_out_iovs);
return do_iovs_send(out_iovs, iov_index); return do_iovs_send(out_iovs, iov_index);
#else
// try to send use the c0c3 header cache,
// if cache is consumed, try another loop.
for (int i = 0; i < nb_msgs; i++) {
SrsSharedPtrMessage* msg = msgs[i];
if (!msg) {
continue;
}
// ignore empty message.
if (!msg->payload || msg->size <= 0) {
srs_info("ignore empty message.");
continue;
}
// p set to current write position,
// it's ok when payload is NULL and size is 0.
char* p = msg->payload;
char* pend = msg->payload + msg->size;
// always write the header event payload is empty.
while (p < pend) {
// for simple send, send each chunk one by one
iovec* iovs = out_iovs;
char* c0c3_cache = out_c0c3_caches;
int nb_cache = SRS_CONSTS_C0C3_HEADERS_MAX;
// always has header
int nbh = msg->chunk_header(c0c3_cache, nb_cache, p == msg->payload);
srs_assert(nbh > 0);
// header iov
iovs[0].iov_base = c0c3_cache;
iovs[0].iov_len = nbh;
// payload iov
int payload_size = srs_min(out_chunk_size, pend - p);
iovs[1].iov_base = p;
iovs[1].iov_len = payload_size;
// consume sendout bytes.
p += payload_size;
if ((ret = skt->writev(iovs, 2, NULL)) != ERROR_SUCCESS) {
if (!srs_is_client_gracefully_close(ret)) {
srs_error("send packet with writev failed. ret=%d", ret);
}
return ret;
}
}
}
return ret;
#endif
} }
int SrsProtocol::do_iovs_send(iovec* iovs, int size) int SrsProtocol::do_iovs_send(iovec* iovs, int size)