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):
* 2014-12-04, SRS 2.0.49, 1.4k(1400) publishers, 68%CPU, 144MB.
* 2014-12-04, SRS 2.0.49, 2.5k(2500) publishers, 95%CPU, 404MB. [commit](https://github.com/winlinvip/simple-rtmp-server/commit/29324fab469e0f7cef9ad04ffdbce832ac7dd9ff)
* 2014-12-04, SRS 2.0.51, 2.5k(2500) publishers, 91%CPU, 259MB. [commit](https://github.com/winlinvip/simple-rtmp-server/commit/f57801eb46c16755b173984b915a4166922df6a6)
* 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)
## Architecture
... ...
... ... @@ -165,17 +165,23 @@ int SrsFastBuffer::grow(ISrsBufferReader* reader, int required_size)
}
// when read payload and need to grow, reset buffer.
if (end - p < required_size && required_size > SRS_RTMP_MAX_MESSAGE_HEADER) {
// or there is no space to read.
int max_to_read = buffer + nb_buffer - end;
if (end - p < required_size
&& (required_size > SRS_RTMP_MAX_MESSAGE_HEADER || max_to_read < required_size)
) {
int nb_cap = end - p;
srs_verbose("move fast buffer %d bytes", nb_cap);
buffer = (char*)memmove(buffer, p, nb_cap);
p = buffer;
end = p + nb_cap;
if (nb_cap < nb_buffer) {
buffer = (char*)memmove(buffer, p, nb_cap);
p = buffer;
end = p + nb_cap;
}
}
while (end - p < required_size) {
// the max to read is the left bytes.
size_t max_to_read = buffer + nb_buffer - end;
max_to_read = buffer + nb_buffer - end;
if (max_to_read <= 0) {
ret = ERROR_RTMP_BUFFER_OVERFLOW;
... ...