Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SmartPtr: Support shared ptr for live source. v6.0.129 #4089

Merged
merged 5 commits into from
Jun 14, 2024

Conversation

winlinvip
Copy link
Member

@winlinvip winlinvip commented Jun 14, 2024

Detail change log:

  1. [Simple,Refactor] Remove member fields of http entry, etc. e34b3d3
  2. [Ignore] Rename source to live_source. 846f95e
  3. [Ignore] Use directly ptr in consumer. d38af02
  4. [Complex, Important] Use shared ptr for live source. 88f9224

The object relationship:

live-source

@winlinvip winlinvip added the EnglishNative This issue is conveyed exclusively in English. label Jun 14, 2024
@winlinvip winlinvip force-pushed the feature/smart-ptr-live-source branch from 1e7d8a7 to 9d5b226 Compare June 14, 2024 07:44
source = pool[stream_url];


SrsLiveSource* source = it->second;
Copy link
Contributor

Choose a reason for hiding this comment

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

just return it->second; seems good.

Copy link
Member Author

@winlinvip winlinvip Jun 14, 2024

Choose a reason for hiding this comment

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

Seems no big difference. Won't fix.

@winlinvip winlinvip marked this pull request as ready for review June 14, 2024 09:53
@winlinvip winlinvip force-pushed the feature/smart-ptr-live-source branch from fb6edaf to 88f9224 Compare June 14, 2024 10:56
@winlinvip
Copy link
Member Author

See #3667 (comment)

virtual srs_error_t do_publishing(SrsSharedPtr<SrsLiveSource> source, SrsPublishRecvThread* trd);
virtual srs_error_t acquire_publish(SrsSharedPtr<SrsLiveSource> source);
virtual void release_publish(SrsSharedPtr<SrsLiveSource> source);
virtual srs_error_t handle_publish_message(SrsSharedPtr<SrsLiveSource>& source, SrsCommonMessage* msg);
Copy link
Contributor

Choose a reason for hiding this comment

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

why above api can not accept a SrsSharedPtr reference as input just like this one, handle_publish_message?
use ref as long as possible, seems better.

Copy link
Member Author

Choose a reason for hiding this comment

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

We should use instance like SrsSharedPtr<SrsLiveSource> source for almost all use scenarios, but for some special and frequently used api like handle_publish_message we should not use instance, instead we should use pointer like SrsSharedPtr<SrsLiveSource>* source or reference like SrsSharedPtr<SrsLiveSource>& source.

Won't fix.


if (it == pool.end()) {
return NULL;
return SrsSharedPtr<SrsLiveSource>(NULL);
Copy link
Contributor

Choose a reason for hiding this comment

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

How about design the fetch api in this way?
SrsSharedPtr<SrsLiveSource>& SrsLiveSourceManager::fetch(SrsRequest* r), return a SrsSharedPtr reference, and Introduce a globally SrsSharedPtr<SrsLiveSource> _SHARED_NULL_LIVE_SOURCE(NULL), return it if the null shared ptr is needed.

And for fetch_or_create, return the SrsSharedPtr reference instead of though the reference parameter: SrsSharedPtr<SrsLiveSource>& SrsLiveSourceManager::fetch_or_create(SrsRequest* r, ISrsLiveSourceHandler* h, srs_error_t& err)

Copy link
Member Author

Choose a reason for hiding this comment

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

For fetch_or_create it may return error, so we should use **pps or & pps as output parameter.

For fetch, a global NULL instance or temporary instance is ok, because it's not a hot path.

Won't fix.

{
// Use lock to protect coroutine switch.
// @bug https://github.com/ossrs/srs/issues/1230
// TODO: FIXME: Use smaller scope lock.
SrsLocker(lock);

string stream_url = r->get_stream_url();
std::map<std::string, SrsLiveSource*>::iterator it = pool.find(stream_url);
std::map< std::string, SrsSharedPtr<SrsLiveSource> >::iterator it = pool.find(stream_url);
Copy link
Contributor

Choose a reason for hiding this comment

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

How many SrsLiveSources do SRS supported in a single node? there are no limitations, just restricted by memory and network bandwidth. So why not use std:unordered_map to replace this std::map, it could be faster in this find operation.

Copy link
Member Author

Choose a reason for hiding this comment

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

For performance improvement, please file another PR and please provide benchmark data.

Won't fix by this PR.

@@ -1993,7 +1980,7 @@ bool SrsLiveSource::publisher_is_idle_for(srs_utime_t timeout)
return false;
}

srs_error_t SrsLiveSource::initialize(SrsRequest* r, ISrsLiveSourceHandler* h)
srs_error_t SrsLiveSource::initialize(SrsSharedPtr<SrsLiveSource> wrapper, SrsRequest* r, ISrsLiveSourceHandler* h)
Copy link
Contributor

Choose a reason for hiding this comment

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

this method and every initialize embedded this is method can be declared to just accept a SrsSharedPtr reference. It will save a lot of SrsSharedPtr construction and destruction operations.

Copy link
Member Author

@winlinvip winlinvip Jun 14, 2024

Choose a reason for hiding this comment

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

I have claimed for many times: If you want to improve performance, please provide benchmark data. Most of performance improvement does not work. Never fix problem that does not exsit.

For this case, initialize is not hot path, so there is no performance bottleneck. We should never use reference unless we really need it.

Won't fix.

@suzp1984 suzp1984 self-requested a review June 14, 2024 15:06
@winlinvip winlinvip changed the title SmartPtr: Support shared ptr for live source. SmartPtr: Support shared ptr for live source. v6.0.129 Jun 14, 2024
@winlinvip winlinvip added the RefinedByAI Refined by AI/GPT. label Jun 14, 2024
@winlinvip winlinvip merged commit e706978 into ossrs:develop Jun 14, 2024
5 checks passed
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants