diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index acd302059..186760361 100644 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -69,9 +69,6 @@ using namespace std; // when edge timeout, retry next. #define SRS_EDGE_TOKEN_TRAVERSE_TIMEOUT_US (int64_t)(3*1000*1000LL) -// to get msgs then totally send out. -#define SYS_MAX_PLAY_SEND_MSGS 128 - SrsRtmpConn::SrsRtmpConn(SrsServer* srs_server, st_netfd_t client_stfd) : SrsConnection(srs_server, client_stfd) { @@ -520,7 +517,7 @@ int SrsRtmpConn::playing(SrsSource* source) // initialize other components SrsPithyPrint pithy_print(SRS_CONSTS_STAGE_PLAY_USER); - SrsSharedPtrMessageArray msgs(SYS_MAX_PLAY_SEND_MSGS); + SrsSharedPtrMessageArray msgs(SYS_CONSTS_MAX_PLAY_SEND_MSGS); bool user_specified_duration_to_stop = (req->duration > 0); int64_t starttime = -1; diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index 49df43998..d9ce8c389 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -50,12 +50,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define SERVER_LISTEN_BACKLOG 512 -// system interval +// system interval in ms, // all resolution times should be times togother, // for example, system-time is 3(300ms), // then rusage can be 3*x, for instance, 3*10=30(3s), // the meminfo canbe 30*x, for instance, 30*2=60(6s) // for performance refine, @see: https://github.com/winlinvip/simple-rtmp-server/issues/194 +// @remark, recomment to 1000ms. #define SRS_SYS_CYCLE_INTERVAL 1000 // update time interval: diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index 64fd2d0e0..f25e64e3e 100644 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -216,7 +216,7 @@ int SrsMessageQueue::dump_packets(int max_count, SrsSharedPtrMessage** pmsgs, in } else { // erase some vector elements may cause memory copy, // maybe can use more efficient vector.swap to avoid copy. - // @remark for the pmsgs is big enough, for instance, SYS_MAX_PLAY_SEND_MSGS 128, + // @remark for the pmsgs is big enough, for instance, SYS_CONSTS_MAX_PLAY_SEND_MSGS 128, // the rtmp play client will get 128msgs once, so this branch rarely execute. msgs.erase(msgs.begin(), msgs.begin() + count); } diff --git a/trunk/src/kernel/srs_kernel_consts.hpp b/trunk/src/kernel/srs_kernel_consts.hpp index 4bb551311..d30fd07d1 100644 --- a/trunk/src/kernel/srs_kernel_consts.hpp +++ b/trunk/src/kernel/srs_kernel_consts.hpp @@ -78,6 +78,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // the timeout to wait for client control message, // if timeout, we generally ignore and send the data to client, // generally, it's the pulse time for data seding. +// @remark, recomment to 500ms. #define SRS_CONSTS_RTMP_PULSE_TIMEOUT_US (int64_t)(500*1000LL) /** @@ -97,18 +98,42 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // always use fmt0 as cache. //#define SRS_CONSTS_RTMP_MAX_FMT3_HEADER_SIZE 5 +/** +* how many msgs can be send entirely. +* for play clients to get msgs then totally send out. +* for example, 25fps video, 40ms per video packet, +* while audio is 20ms per audio packet where 2/3 is audios, +* when SYS_CONSTS_MAX_PLAY_SEND_MSGS is 128, then +* we will send all 128*40ms/3=1706ms packets in a time, +* which should greater than the SRS_CONSTS_RTMP_PULSE_TIMEOUT_US +* (for example, 500ms), that is, we should: +* SYS_CONSTS_MAX_PLAY_SEND_MSGS * 40 / 3 >= SRS_CONSTS_RTMP_PULSE_TIMEOUT_US +* @remark, recomment to 128. +*/ +#define SYS_CONSTS_MAX_PLAY_SEND_MSGS 128 /** * for performance issue, * the iovs cache, @see https://github.com/winlinvip/simple-rtmp-server/issues/194 * iovs cache for multiple messages for each connections. +* each iovc is 16bytes, sizeof(iovec)=16, suppose the chunk size is 64k, +* each message send in a chunk which needs only 2 iovec, +* so the iovs max should be (SYS_CONSTS_MAX_PLAY_SEND_MSGS * 16 * 2) +* +* @remark, SRS will realloc when the iovs not enough. */ -#define SRS_CONSTS_IOVS_MAX 1024 +#define SRS_CONSTS_IOVS_MAX (SYS_CONSTS_MAX_PLAY_SEND_MSGS * 32) /** * for performance issue, * the c0c3 cache, @see https://github.com/winlinvip/simple-rtmp-server/issues/194 * c0c3 cache for multiple messages for each connections. +* each c0 <= 16byes, suppose the chunk size is 64k, +* each message send in a chunk which needs only a c0 header, +* so the c0c3 cache should be (SYS_CONSTS_MAX_PLAY_SEND_MSGS * 16) +* +* @remark, SRS will try another loop when c0c3 cache dry, for we cannot realloc it. +* so we use larger c0c3 cache, that is (SYS_CONSTS_MAX_PLAY_SEND_MSGS * 32) */ -#define SRS_CONSTS_C0C3_HEADERS_MAX 4096 +#define SRS_CONSTS_C0C3_HEADERS_MAX (SYS_CONSTS_MAX_PLAY_SEND_MSGS * 32) /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// diff --git a/trunk/src/rtmp/srs_protocol_rtmp.hpp b/trunk/src/rtmp/srs_protocol_rtmp.hpp index e6dcb0b51..70fc8e8ca 100644 --- a/trunk/src/rtmp/srs_protocol_rtmp.hpp +++ b/trunk/src/rtmp/srs_protocol_rtmp.hpp @@ -374,6 +374,9 @@ public: * @param msgs, the msgs to send out, never be NULL. * @param nb_msgs, the size of msgs to send out. * @param stream_id, the stream id of packet to send over, 0 for control message. + * + * @remark performance issue, to support 6k+ 250kbps client, + * @see https://github.com/winlinvip/simple-rtmp-server/issues/194 */ virtual int send_and_free_messages(SrsSharedPtrMessage** msgs, int nb_msgs, int stream_id); /**