winlin

refine for bug #241, increase the small bytes for merged read.

@@ -37,14 +37,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -37,14 +37,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 #define SRS_MR_AVERAGE_BITRATE_KBPS 1000 37 #define SRS_MR_AVERAGE_BITRATE_KBPS 1000
38 #define SRS_MR_MIN_BITRATE_KBPS 32 38 #define SRS_MR_MIN_BITRATE_KBPS 32
39 // the max sleep time in ms 39 // the max sleep time in ms
40 -#define SRS_MR_MAX_SLEEP_MS 3000 40 +#define SRS_MR_MAX_SLEEP_MS 2500
41 // the max small bytes to group 41 // the max small bytes to group
42 -#define SRS_MR_SMALL_BYTES 64 42 +#define SRS_MR_SMALL_BYTES 4096
43 // the percent of buffer to set as small bytes 43 // the percent of buffer to set as small bytes
44 #define SRS_MR_SMALL_PERCENT 100 44 #define SRS_MR_SMALL_PERCENT 100
45 -// set the socket buffer to specified KB.  
46 -// the underlayer api will set to 2*SRS_MR_SOCKET_BUFFER KB.  
47 -#define SRS_MR_SOCKET_BUFFER 32 45 +// set the socket buffer to specified bytes.
  46 +// the underlayer api will set to SRS_MR_SOCKET_BUFFER bytes.
  47 +#define SRS_MR_SOCKET_BUFFER SOCKET_READ_SIZE
48 48
49 ISrsMessageHandler::ISrsMessageHandler() 49 ISrsMessageHandler::ISrsMessageHandler()
50 { 50 {
@@ -299,15 +299,15 @@ void SrsPublishRecvThread::on_thread_start() @@ -299,15 +299,15 @@ void SrsPublishRecvThread::on_thread_start()
299 // we donot set the auto response to false, 299 // we donot set the auto response to false,
300 // for the main thread never send message. 300 // for the main thread never send message.
301 301
302 - // socket recv buffer.  
303 - int nb_rbuf = SRS_MR_SOCKET_BUFFER * 1024; 302 + // socket recv buffer, system will double it.
  303 + int nb_rbuf = SRS_MR_SOCKET_BUFFER / 2;
304 socklen_t sock_buf_size = sizeof(int); 304 socklen_t sock_buf_size = sizeof(int);
305 if (setsockopt(mr_fd, SOL_SOCKET, SO_RCVBUF, &nb_rbuf, sock_buf_size) < 0) { 305 if (setsockopt(mr_fd, SOL_SOCKET, SO_RCVBUF, &nb_rbuf, sock_buf_size) < 0) {
306 srs_warn("set sock SO_RCVBUF=%d failed.", nb_rbuf); 306 srs_warn("set sock SO_RCVBUF=%d failed.", nb_rbuf);
307 } 307 }
308 getsockopt(mr_fd, SOL_SOCKET, SO_RCVBUF, &nb_rbuf, &sock_buf_size); 308 getsockopt(mr_fd, SOL_SOCKET, SO_RCVBUF, &nb_rbuf, &sock_buf_size);
309 309
310 - srs_trace("set socket buffer to %d, actual %d KB", SRS_MR_SOCKET_BUFFER, nb_rbuf / 1024); 310 + srs_trace("set socket buffer to %d, actual %d KB", SRS_MR_SOCKET_BUFFER / 1024, nb_rbuf / 1024);
311 311
312 // enable the merge read 312 // enable the merge read
313 // @see https://github.com/winlinvip/simple-rtmp-server/issues/241 313 // @see https://github.com/winlinvip/simple-rtmp-server/issues/241
@@ -381,7 +381,7 @@ void SrsPublishRecvThread::on_buffer_change(int nb_buffer) @@ -381,7 +381,7 @@ void SrsPublishRecvThread::on_buffer_change(int nb_buffer)
381 // set percent. 381 // set percent.
382 mr_small_bytes = (int)(nb_buffer / SRS_MR_SMALL_PERCENT); 382 mr_small_bytes = (int)(nb_buffer / SRS_MR_SMALL_PERCENT);
383 // select the smaller 383 // select the smaller
384 - mr_small_bytes = srs_min(mr_small_bytes, SRS_MR_SMALL_BYTES); 384 + mr_small_bytes = srs_max(mr_small_bytes, SRS_MR_SMALL_BYTES);
385 385
386 // the recv sleep is [buffer / max_kbps, buffer / min_kbps] 386 // the recv sleep is [buffer / max_kbps, buffer / min_kbps]
387 // for example, buffer is 256KB, max kbps is 10Mbps, min kbps is 10Kbps, 387 // for example, buffer is 256KB, max kbps is 10Mbps, min kbps is 10Kbps,
@@ -27,16 +27,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -27,16 +27,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include <srs_kernel_log.hpp> 27 #include <srs_kernel_log.hpp>
28 #include <srs_kernel_utility.hpp> 28 #include <srs_kernel_utility.hpp>
29 29
30 -// 4KB=4096  
31 -// 8KB=8192  
32 -// 16KB=16384  
33 -// 32KB=32768  
34 -// 64KB=65536  
35 -// @see https://github.com/winlinvip/simple-rtmp-server/issues/241  
36 -#define SOCKET_READ_SIZE 65536  
37 -// the max buffer for user space socket buffer.  
38 -#define SOCKET_MAX_BUF 65536  
39 -  
40 IMergeReadHandler::IMergeReadHandler() 30 IMergeReadHandler::IMergeReadHandler()
41 { 31 {
42 } 32 }
@@ -34,6 +34,16 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -34,6 +34,16 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 34
35 #include <srs_protocol_io.hpp> 35 #include <srs_protocol_io.hpp>
36 36
  37 +// 4KB=4096
  38 +// 8KB=8192
  39 +// 16KB=16384
  40 +// 32KB=32768
  41 +// 64KB=65536
  42 +// @see https://github.com/winlinvip/simple-rtmp-server/issues/241
  43 +#define SOCKET_READ_SIZE 65536
  44 +// the max buffer for user space socket buffer.
  45 +#define SOCKET_MAX_BUF SOCKET_READ_SIZE
  46 +
37 /** 47 /**
38 * to improve read performance, merge some packets then read, 48 * to improve read performance, merge some packets then read,
39 * when it on and read small bytes, we sleep to wait more data., 49 * when it on and read small bytes, we sleep to wait more data.,