mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
SmartPtr: Support load test for source by srs-bench. v6.0.130 (#4097)
1. Add live benchmark support in srs-bench, which only connects and disconnects without any media transport, to test source creation and disposal and verify source memory leaks. 2. SmartPtr: Support cleanup of HTTP-FLV stream. Unregister the HTTP-FLV handler for the pattern and clean up the objects and resources. 3. Support benchmarking RTMP/SRT with srs-bench by integrating the gosrt and oryx RTMP libraries. 4. Refine SRT and RTC sources by using a timer to clean up the sources, following the same strategy as the Live source. --------- Co-authored-by: Haibo Chen <495810242@qq.com> Co-authored-by: Jacob Su <suzp1984@gmail.com>
This commit is contained in:
parent
e3d74fb045
commit
1f9309ae25
508 changed files with 6805 additions and 3299 deletions
|
|
@ -48,7 +48,7 @@ using namespace std;
|
|||
#define SRS_MIX_CORRECT_PURE_AV 10
|
||||
|
||||
// the time to cleanup source.
|
||||
#define SRS_SOURCE_CLEANUP (30 * SRS_UTIME_SECONDS)
|
||||
#define SRS_SOURCE_CLEANUP (3 * SRS_UTIME_SECONDS)
|
||||
|
||||
int srs_time_jitter_string2int(std::string time_jitter)
|
||||
{
|
||||
|
|
@ -910,6 +910,13 @@ bool SrsOriginHub::active()
|
|||
return is_active;
|
||||
}
|
||||
|
||||
srs_utime_t SrsOriginHub::cleanup_delay()
|
||||
{
|
||||
srs_utime_t hls_delay = hls->cleanup_delay();
|
||||
srs_utime_t dash_delay = dash->cleanup_delay();
|
||||
return srs_max(hls_delay, dash_delay);
|
||||
}
|
||||
|
||||
srs_error_t SrsOriginHub::on_meta_data(SrsSharedPtrMessage* shared_metadata, SrsOnMetaDataPacket* packet)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
|
@ -1827,7 +1834,7 @@ srs_error_t SrsLiveSourceManager::setup_ticks()
|
|||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if ((err = timer_->tick(1, 1 * SRS_UTIME_SECONDS)) != srs_success) {
|
||||
if ((err = timer_->tick(1, 3 * SRS_UTIME_SECONDS)) != srs_success) {
|
||||
return srs_error_wrap(err, "tick");
|
||||
}
|
||||
|
||||
|
|
@ -1848,24 +1855,21 @@ srs_error_t SrsLiveSourceManager::notify(int event, srs_utime_t interval, srs_ut
|
|||
|
||||
// Do cycle source to cleanup components, such as hls dispose.
|
||||
if ((err = source->cycle()) != srs_success) {
|
||||
return srs_error_wrap(err, "source=%s/%s cycle", source->source_id().c_str(), source->pre_source_id().c_str());
|
||||
SrsContextId cid = source->source_id();
|
||||
if (cid.empty()) cid = source->pre_source_id();
|
||||
return srs_error_wrap(err, "source cycle, id=[%s]", cid.c_str());
|
||||
}
|
||||
|
||||
// See SrsSrtSource::on_consumer_destroy
|
||||
// TODO: FIXME: support source cleanup.
|
||||
// @see https://github.com/ossrs/srs/issues/713
|
||||
#if 1
|
||||
// When source expired, remove it.
|
||||
// @see https://github.com/ossrs/srs/issues/713
|
||||
if (source->stream_is_dead()) {
|
||||
const SrsContextId& cid = source->source_id();
|
||||
srs_trace("cleanup die source, id=[%s], total=%d", cid.c_str(), (int)pool.size());
|
||||
SrsContextId cid = source->source_id();
|
||||
if (cid.empty()) cid = source->pre_source_id();
|
||||
srs_trace("Live: cleanup die source, id=[%s], total=%d", cid.c_str(), (int)pool.size());
|
||||
pool.erase(it++);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
#else
|
||||
++it;
|
||||
#endif
|
||||
}
|
||||
|
||||
return err;
|
||||
|
|
@ -1923,6 +1927,10 @@ SrsLiveSource::~SrsLiveSource()
|
|||
|
||||
srs_freep(req);
|
||||
srs_freep(bridge_);
|
||||
|
||||
SrsContextId cid = _source_id;
|
||||
if (cid.empty()) cid = _pre_source_id;
|
||||
srs_trace("free live source id=[%s]", cid.c_str());
|
||||
}
|
||||
|
||||
void SrsLiveSource::dispose()
|
||||
|
|
@ -1944,11 +1952,6 @@ srs_error_t SrsLiveSource::cycle()
|
|||
|
||||
bool SrsLiveSource::stream_is_dead()
|
||||
{
|
||||
// unknown state?
|
||||
if (stream_die_at_ == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// still publishing?
|
||||
if (!_can_publish || !publish_edge->can_publish()) {
|
||||
return false;
|
||||
|
|
@ -1958,13 +1961,19 @@ bool SrsLiveSource::stream_is_dead()
|
|||
if (!consumers.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Delay cleanup source.
|
||||
srs_utime_t now = srs_get_system_time();
|
||||
if (now > stream_die_at_ + SRS_SOURCE_CLEANUP) {
|
||||
return true;
|
||||
if (now < stream_die_at_ + SRS_SOURCE_CLEANUP) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Origin hub delay cleanup.
|
||||
if (now < stream_die_at_ + hub->cleanup_delay()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SrsLiveSource::publisher_is_idle_for(srs_utime_t timeout)
|
||||
|
|
@ -2726,6 +2735,11 @@ void SrsLiveSource::on_consumer_destroy(SrsLiveConsumer* consumer)
|
|||
if (consumers.empty()) {
|
||||
play_edge->on_all_client_stop();
|
||||
|
||||
// If no publishers, the stream is die.
|
||||
if (_can_publish) {
|
||||
stream_die_at_ = srs_get_system_time();
|
||||
}
|
||||
|
||||
// For edge server, the stream die when the last player quit, because the edge stream is created by player
|
||||
// activities, so it should die when all players quit.
|
||||
if (_srs_config->get_vhost_is_edge(req->vhost)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue