-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
HTTP-FLV: Notify connection to expire when unpublishing. v6.0.152 v7.0.11 #4164
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -583,13 +583,15 @@ SrsLiveStream::SrsLiveStream(SrsRequest* r, SrsBufferCache* c) | |
cache = c; | ||
req = r->copy()->as_http(); | ||
security_ = new SrsSecurity(); | ||
alive_viewers_ = 0; | ||
} | ||
|
||
SrsLiveStream::~SrsLiveStream() | ||
{ | ||
srs_freep(req); | ||
srs_freep(security_); | ||
|
||
// The live stream should never be destroyed when it's serving any viewers. | ||
srs_assert(viewers_.empty()); | ||
} | ||
|
||
srs_error_t SrsLiveStream::update_auth(SrsRequest* r) | ||
|
@@ -634,18 +636,35 @@ srs_error_t SrsLiveStream::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage | |
return srs_error_wrap(err, "http hook"); | ||
} | ||
|
||
alive_viewers_++; | ||
// Add the viewer to the viewers list. | ||
viewers_.push_back(hc); | ||
|
||
// Serve the viewer connection. | ||
err = do_serve_http(w, r); | ||
alive_viewers_--; | ||
|
||
|
||
// Remove viewer from the viewers list. | ||
vector<ISrsExpire*>::iterator it = std::find(viewers_.begin(), viewers_.end(), hc); | ||
srs_assert (it != viewers_.end()); | ||
viewers_.erase(it); | ||
|
||
// Do hook after serving. | ||
http_hooks_on_stop(r); | ||
|
||
return err; | ||
} | ||
|
||
bool SrsLiveStream::alive() | ||
{ | ||
return alive_viewers_ > 0; | ||
return !viewers_.empty(); | ||
} | ||
|
||
void SrsLiveStream::expire() | ||
{ | ||
vector<ISrsExpire*>::iterator it; | ||
for (it = viewers_.begin(); it != viewers_.end(); ++it) { | ||
ISrsExpire* conn = *it; | ||
conn->expire(); | ||
} | ||
} | ||
|
||
srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | ||
|
@@ -1075,6 +1094,7 @@ void SrsHttpStreamServer::http_unmount(SrsRequest* r) | |
|
||
// Notify cache and stream to stop. | ||
if (stream->entry) stream->entry->enabled = false; | ||
stream->expire(); | ||
cache->stop(); | ||
|
||
// Wait for cache and stream to stop. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No essential difference. I want keep it. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,6 @@ | |
|
||
#define VERSION_MAJOR 6 | ||
#define VERSION_MINOR 0 | ||
#define VERSION_REVISION 151 | ||
#define VERSION_REVISION 152 | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,6 @@ | |
|
||
#define VERSION_MAJOR 7 | ||
#define VERSION_MINOR 0 | ||
#define VERSION_REVISION 10 | ||
#define VERSION_REVISION 11 | ||
|
||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
viewers_
, asvector
container , has bad efficiency inerase
, and alsofind
for unsorted data.For one SRS instance, it is reasonable to support 1K flv http connection.
So it's 1K unsorted vector search and delete frequently. (Not so bad, also not so good).
If the vector size is 10K, it will be serious problem.
In those reason, consider
map
orunordered_map
as the container. theSrsHttpConn->get_id
as the key, make sure the key is unique for eachSrsHttpConn
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No performance issues even for 10,000 viewers, because this only executes once when a viewer closes the connection.
I have written a test program to verify it; it is definitely not that slow. We should never fix problems that do not exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try bellow benchmark, to randomly find a elem in 100k vector:
Result:
It only increase 0.1ms when viewer closing the connection, note that in 100k vector, not 10k.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one viewer close the http connection, it exec one time, but if 10K viewers close http flv connections, this code will run 10K times. The rarely case is the 10K viewers close the connection at same time. OK, I accept this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the benchmark, The real disaster of the vector is the
erase
. I would avoid doing this as far as possible.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even with 10,000 viewers, each increase is only 0.01ms. When will 10,000 viewers close the connection simultaneously? We should never fix problems that do not exist. You will be completely occupied if you try to solve every imaginary problem that does not exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, accept it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try this:
The result:
For 10,000 viewers, each increase is 0.02ms. I think the key point is to run some benchmarks and gather data when you are concerned about performance issues.