mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
fix #249, cache the chunk headers info to +5% or +10% performance. 2.0.51
This commit is contained in:
parent
b84e87845e
commit
f57801eb46
4 changed files with 52 additions and 9 deletions
|
@ -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 50
|
#define VERSION_REVISION 51
|
||||||
// server info.
|
// server info.
|
||||||
#define RTMP_SIG_SRS_KEY "SRS"
|
#define RTMP_SIG_SRS_KEY "SRS"
|
||||||
#define RTMP_SIG_SRS_ROLE "origin/edge server"
|
#define RTMP_SIG_SRS_ROLE "origin/edge server"
|
||||||
|
|
|
@ -79,5 +79,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#define SRS_PERF_SEND_MSGS_CACHE 500
|
#define SRS_PERF_SEND_MSGS_CACHE 500
|
||||||
|
|
||||||
|
/**
|
||||||
|
* how many chunk stream to cache, [0, N].
|
||||||
|
* to imporove about 10% performance when chunk size small, and 5% for large chunk.
|
||||||
|
* @see https://github.com/winlinvip/simple-rtmp-server/issues/249
|
||||||
|
*/
|
||||||
|
#define SRS_PERF_CHUNK_STREAM_CACHE 16
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -417,6 +417,16 @@ SrsProtocol::SrsProtocol(ISrsProtocolReaderWriter* io)
|
||||||
|
|
||||||
warned_c0c3_cache_dry = false;
|
warned_c0c3_cache_dry = false;
|
||||||
auto_response_when_recv = true;
|
auto_response_when_recv = true;
|
||||||
|
|
||||||
|
cs_cache = new SrsChunkStream*[SRS_PERF_CHUNK_STREAM_CACHE];
|
||||||
|
for (int cid = 0; cid < SRS_PERF_CHUNK_STREAM_CACHE; cid++) {
|
||||||
|
SrsChunkStream* cs = new SrsChunkStream(cid);
|
||||||
|
// set the perfer cid of chunk,
|
||||||
|
// which will copy to the message received.
|
||||||
|
cs->header.perfer_cid = cid;
|
||||||
|
|
||||||
|
cs_cache[cid] = cs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsProtocol::~SrsProtocol()
|
SrsProtocol::~SrsProtocol()
|
||||||
|
@ -448,6 +458,13 @@ SrsProtocol::~SrsProtocol()
|
||||||
free(out_iovs);
|
free(out_iovs);
|
||||||
out_iovs = NULL;
|
out_iovs = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// free all chunk stream cache.
|
||||||
|
for (int i = 0; i < SRS_PERF_CHUNK_STREAM_CACHE; i++) {
|
||||||
|
SrsChunkStream* cs = cs_cache[i];
|
||||||
|
srs_freep(cs);
|
||||||
|
}
|
||||||
|
srs_freep(cs_cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsProtocol::set_auto_response(bool v)
|
void SrsProtocol::set_auto_response(bool v)
|
||||||
|
@ -1102,17 +1119,30 @@ int SrsProtocol::recv_interlaced_message(SrsMessage** pmsg)
|
||||||
// get the cached chunk stream.
|
// get the cached chunk stream.
|
||||||
SrsChunkStream* chunk = NULL;
|
SrsChunkStream* chunk = NULL;
|
||||||
|
|
||||||
if (chunk_streams.find(cid) == chunk_streams.end()) {
|
// use chunk stream cache to get the chunk info.
|
||||||
chunk = chunk_streams[cid] = new SrsChunkStream(cid);
|
// @see https://github.com/winlinvip/simple-rtmp-server/issues/249
|
||||||
// set the perfer cid of chunk,
|
if (cid < SRS_PERF_CHUNK_STREAM_CACHE) {
|
||||||
// which will copy to the message received.
|
// chunk stream cache hit.
|
||||||
chunk->header.perfer_cid = cid;
|
srs_verbose("cs-cache hit, cid=%d", cid);
|
||||||
srs_verbose("cache new chunk stream: fmt=%d, cid=%d", fmt, cid);
|
// already init, use it direclty
|
||||||
} else {
|
chunk = cs_cache[cid];
|
||||||
chunk = chunk_streams[cid];
|
|
||||||
srs_verbose("cached chunk stream: fmt=%d, cid=%d, size=%d, message(type=%d, size=%d, time=%"PRId64", sid=%d)",
|
srs_verbose("cached chunk stream: fmt=%d, cid=%d, size=%d, message(type=%d, size=%d, time=%"PRId64", sid=%d)",
|
||||||
chunk->fmt, chunk->cid, (chunk->msg? chunk->msg->size : 0), chunk->header.message_type, chunk->header.payload_length,
|
chunk->fmt, chunk->cid, (chunk->msg? chunk->msg->size : 0), chunk->header.message_type, chunk->header.payload_length,
|
||||||
chunk->header.timestamp, chunk->header.stream_id);
|
chunk->header.timestamp, chunk->header.stream_id);
|
||||||
|
} else {
|
||||||
|
// chunk stream cache miss, use map.
|
||||||
|
if (chunk_streams.find(cid) == chunk_streams.end()) {
|
||||||
|
chunk = chunk_streams[cid] = new SrsChunkStream(cid);
|
||||||
|
// set the perfer cid of chunk,
|
||||||
|
// which will copy to the message received.
|
||||||
|
chunk->header.perfer_cid = cid;
|
||||||
|
srs_verbose("cache new chunk stream: fmt=%d, cid=%d", fmt, cid);
|
||||||
|
} else {
|
||||||
|
chunk = chunk_streams[cid];
|
||||||
|
srs_verbose("cached chunk stream: fmt=%d, cid=%d, size=%d, message(type=%d, size=%d, time=%"PRId64", sid=%d)",
|
||||||
|
chunk->fmt, chunk->cid, (chunk->msg? chunk->msg->size : 0), chunk->header.message_type, chunk->header.payload_length,
|
||||||
|
chunk->header.timestamp, chunk->header.stream_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// chunk stream message header
|
// chunk stream message header
|
||||||
|
|
|
@ -205,6 +205,12 @@ private:
|
||||||
*/
|
*/
|
||||||
std::map<int, SrsChunkStream*> chunk_streams;
|
std::map<int, SrsChunkStream*> chunk_streams;
|
||||||
/**
|
/**
|
||||||
|
* cache some frequently used chunk header.
|
||||||
|
* cs_cache, the chunk stream cache.
|
||||||
|
* @see https://github.com/winlinvip/simple-rtmp-server/issues/249
|
||||||
|
*/
|
||||||
|
SrsChunkStream** cs_cache;
|
||||||
|
/**
|
||||||
* bytes buffer cache, recv from skt, provide services for stream.
|
* bytes buffer cache, recv from skt, provide services for stream.
|
||||||
*/
|
*/
|
||||||
SrsFastBuffer* in_buffer;
|
SrsFastBuffer* in_buffer;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue