winlin

update performance to 4k, when mr_sleep to 2000ms. 2.0.52

@@ -738,6 +738,7 @@ The publish benchmark by [st-load](https://github.com/winlinvip/st-load): @@ -738,6 +738,7 @@ The publish benchmark by [st-load](https://github.com/winlinvip/st-load):
738 * 2014-12-04, SRS 2.0.49, 1.4k(1400) publishers, 68%CPU, 144MB. 738 * 2014-12-04, SRS 2.0.49, 1.4k(1400) publishers, 68%CPU, 144MB.
739 * 2014-12-04, SRS 2.0.49, 2.5k(2500) publishers, 95%CPU, 404MB. [commit](https://github.com/winlinvip/simple-rtmp-server/commit/29324fab469e0f7cef9ad04ffdbce832ac7dd9ff) 739 * 2014-12-04, SRS 2.0.49, 2.5k(2500) publishers, 95%CPU, 404MB. [commit](https://github.com/winlinvip/simple-rtmp-server/commit/29324fab469e0f7cef9ad04ffdbce832ac7dd9ff)
740 * 2014-12-04, SRS 2.0.51, 2.5k(2500) publishers, 91%CPU, 259MB. [commit](https://github.com/winlinvip/simple-rtmp-server/commit/f57801eb46c16755b173984b915a4166922df6a6) 740 * 2014-12-04, SRS 2.0.51, 2.5k(2500) publishers, 91%CPU, 259MB. [commit](https://github.com/winlinvip/simple-rtmp-server/commit/f57801eb46c16755b173984b915a4166922df6a6)
  741 +* 2014-12-04, SRS 2.0.52, 4.0k(4000) publishers, 80%CPU, 331MB. (mr_sleep=2000) [commit](https://github.com/winlinvip/simple-rtmp-server/commit/5589b13d2e216b91f97afb78ee0c011b2fccf7da)
741 742
742 ## Architecture 743 ## Architecture
743 744
@@ -165,17 +165,23 @@ int SrsFastBuffer::grow(ISrsBufferReader* reader, int required_size) @@ -165,17 +165,23 @@ int SrsFastBuffer::grow(ISrsBufferReader* reader, int required_size)
165 } 165 }
166 166
167 // when read payload and need to grow, reset buffer. 167 // when read payload and need to grow, reset buffer.
168 - if (end - p < required_size && required_size > SRS_RTMP_MAX_MESSAGE_HEADER) { 168 + // or there is no space to read.
  169 + int max_to_read = buffer + nb_buffer - end;
  170 + if (end - p < required_size
  171 + && (required_size > SRS_RTMP_MAX_MESSAGE_HEADER || max_to_read < required_size)
  172 + ) {
169 int nb_cap = end - p; 173 int nb_cap = end - p;
170 srs_verbose("move fast buffer %d bytes", nb_cap); 174 srs_verbose("move fast buffer %d bytes", nb_cap);
171 - buffer = (char*)memmove(buffer, p, nb_cap);  
172 - p = buffer;  
173 - end = p + nb_cap; 175 + if (nb_cap < nb_buffer) {
  176 + buffer = (char*)memmove(buffer, p, nb_cap);
  177 + p = buffer;
  178 + end = p + nb_cap;
  179 + }
174 } 180 }
175 181
176 while (end - p < required_size) { 182 while (end - p < required_size) {
177 // the max to read is the left bytes. 183 // the max to read is the left bytes.
178 - size_t max_to_read = buffer + nb_buffer - end; 184 + max_to_read = buffer + nb_buffer - end;
179 185
180 if (max_to_read <= 0) { 186 if (max_to_read <= 0) {
181 ret = ERROR_RTMP_BUFFER_OVERFLOW; 187 ret = ERROR_RTMP_BUFFER_OVERFLOW;