Skip to content

SmartPtr: Support load test for source by srs-bench. v6.0.130#4097

Merged
winlinvip merged 11 commits intoossrs:developfrom
winlinvip:feature/smart-ptr-test
Jun 20, 2024
Merged

SmartPtr: Support load test for source by srs-bench. v6.0.130#4097
winlinvip merged 11 commits intoossrs:developfrom
winlinvip:feature/smart-ptr-test

Conversation

@winlinvip
Copy link
Copy Markdown
Member

@winlinvip winlinvip commented Jun 19, 2024

  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

@winlinvip winlinvip added the EnglishNative This issue is conveyed exclusively in English. label Jun 19, 2024
@winlinvip winlinvip marked this pull request as ready for review June 19, 2024 09:47
if (!enabled) {
return 0;
}
return _srs_config->get_dash_dispose(req->vhost) * 1.1;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dash_dispose is not illustrated in full.conf, which can be used as the doc. It's better to add it to full.conf.

Another problem, the default dash_dispose config is 0, or user can config the [hls | dash]_dispose to 0 second, then this cleanup_delay will be 0, is the cleanup_delay has to be keep > 0 ? In this case:
_srs_config->get_dash_dispose(req->vhost) > 0 ? _srs_config->get_dash_dispose(req->vhost) * 1.1 : 1
Let the cleanup_delay at least 1 second.

Copy link
Copy Markdown
Member Author

@winlinvip winlinvip Jun 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add dash_dispose to full.conf.
If user config dispose to 0, this cleanup_delay will return 0, which will be ignored.
It works as expectation. Won't fix.

# @remark apply for publisher timeout only, while "etc/init.d/srs stop" always dispose DASH.
# Overwrite by env SRS_VHOST_DASH_DASH_DISPOSE for all vhosts.
# default: 120
dash_dispose 120;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

srs_utime_t SrsConfig::get_dash_dispose(std::string vhost)
{
SRS_OVERWRITE_BY_ENV_SECONDS("srs.vhost.dash.dash_dispose"); // SRS_VHOST_DASH_DASH_DISPOSE
static srs_utime_t DEFAULT = 0;

the default value in the code need to match the value here, be careful, change the default value in the srs_app_config may has impact.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous default value is 0, but hls dispose defaults to 120. I think it's ok to change to the same.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't notice the dash_dispose default value in srs_app_config.cpp already changed to 120 to match the full.conf. No problem here.

}

std::string vhost = pattern;
if (pattern.at(0) != '/') {
Copy link
Copy Markdown
Contributor

@suzp1984 suzp1984 Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vhosts store the vhost -> ISrsHttpHandler map, but the value, ISrsHttpHandler never used, so is is ok to downgrade the map -> set?
About the code to extract the vhost, they are repeated in:

std::string vhost = pattern;
if (pattern.at(0) != '/') {
if (pattern.find("/") != string::npos) {
vhost = pattern.substr(0, pattern.find("/"));
}
vhosts[vhost] = handler;
}

Maybe a another method to get the vhost from pattern.

Copy link
Copy Markdown
Member Author

@winlinvip winlinvip Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need another PR to refine the code, because it not about the smart ptr.

Won't fix in this PR.

@@ -691,14 +691,12 @@ srs_error_t SrsHttpServeMux::handle(std::string pattern, ISrsHttpHandler* handle
srs_assert(handler);

if (pattern.empty()) {
srs_freep(handler);
Copy link
Copy Markdown
Contributor

@suzp1984 suzp1984 Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ISrsHttpHander memory release still not perfect.
For a normal process, the ISrsHttpHandler is created in:

entry->stream = new SrsLiveStream(r, entry->cache);

and released in
SrsHttpMuxEntry::~SrsHttpMuxEntry()
{
srs_freep(handler);
}

I would think if it's possible to manager it in same place, SrsLiveEntry in this case. I see the auto release in SrsHttpStreamServer::http_unmount(SrsRequest* r), the ISrsHttpHander, or SrsLiveStream, seems freed twice in SrsHttpMuxEntry destructor and SrsHttpStreamServer::http_unmount

And For exception cases, like here, handler not freed here, but this exception not handled well, the handler not released below at least.

if ((err = mux.handle(mount, entry->stream)) != srs_success) {
return srs_error_wrap(err, "http: mount flv stream for vhost=%s failed", sid.c_str());
}

Copy link
Copy Markdown
Member Author

@winlinvip winlinvip Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, in http_unmount, won't free it twice, please check it carefully.

Second, if mux.handle failed, it won't free the stream, but the http_unmount will do.

So I think it's ok. Won't fix.

sflvs.erase(it);

SrsLiveStream* stream = entry->stream;
SrsAutoFree(SrsLiveStream, stream);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the SrsAutoFree not good enough here, when stream being released, stream = NULL, but the entry->stream still hold an not NULL pointer, but it's memory already released.

So is it a good idea to let the SrsLiveEntry destructor to free stream, cache?

Copy link
Copy Markdown
Member Author

@winlinvip winlinvip Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's ok, because the entry is removed and freed:

    SrsLiveEntry* entry = it->second;
    SrsAutoFree(SrsLiveEntry, entry);
    streamHandlers.erase(it);

    SrsLiveStream* stream = entry->stream;
    SrsAutoFree(SrsLiveStream, stream);

    SrsBufferCache* cache = entry->cache;
    SrsAutoFree(SrsBufferCache, cache);

Won't fix.

@winlinvip winlinvip force-pushed the feature/smart-ptr-test branch from 253bfe6 to a49f089 Compare June 20, 2024 03:09
@winlinvip winlinvip changed the title SmartPtr: Support load test for source by srs-bench SmartPtr: Support load test for source by srs-bench. v6.0.130 Jun 20, 2024
@winlinvip winlinvip added the RefinedByAI Refined by AI/GPT. label Jun 20, 2024
@winlinvip winlinvip merged commit 1f9309a into ossrs:develop Jun 20, 2024
winlinvip added a commit that referenced this pull request Jul 13, 2024
## Cause
dash auto dispose is configured by seconds, but the code compare by
usecond, 1 second = 1,000,000 useconds.

releated to #4097
Bug introduced after #4097 supported Dash auto dispose after a timeout
without media data.

## How to reproduce

1. `./objs/srs -c conf/dash.conf`
2. publish a rtmp stream.
3. play dash stream. -> no dash stream, always 404 error.

---------

Co-authored-by: winlin <winlinvip@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

EnglishNative This issue is conveyed exclusively in English. RefinedByAI Refined by AI/GPT.

Development

Successfully merging this pull request may close these issues.

Source: The memory leak seems still exist SrsLiveSource cleanup is different to SrsSrtSource

3 participants