-
Notifications
You must be signed in to change notification settings - Fork 477
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
srtp_stream_hash_t #659
srtp_stream_hash_t #659
Conversation
Store SRTP streams in several lists rather than in a single one, making those effectively smaller than the current single one. Each hash entry is a srtp_stream_list_t, being this one where the streams are ultimately stored as they are currently.
I like the approach of this PR as it appears to give a big improvement for server side usage, with very little to almost no downside for usage on endpoints with low number of streams. @fluffy @bifurcation @pabuhler what do you think? |
Both server and endpoints handling large number of streams benefit from this improvement in the same way. This improvement applies to both. BTW, the number of buckets in the hash table is hardcoded to 32, which I find a reasonable number (creates 32 lists per hash table, 32 times smaller each, in average). I can make this number configurable if needed. |
performance boosts are always good but I am a little confused, in the srtp code you have basically just replace all calls to xx_list with xx_hash, does't this mean in practice that you could have written you own list implementation that has this hashing functionality inside ? Maybe there is something I am missing, and maybe you could not use libsrtp list inside you hash list but would have to make your own. |
I have not implemented a list. This PR basically creates N (32 concretely) lists and handles them via a hash. I definitely don't know how could I have done it outside the library by rewriting the _list methods. Would you tell me? This is, this PR provides enhancement also for user created lists since it basically reduces the length of them.
Of course the ssrc numbering nature will determine how streams are distributed among lists. We cannot guarantee an even number of streams in every list of the hash, but that does not invalidate this enhancement IMO. EDIT: I think this change would benefit the overall libsrtp usages and hence would make sense to have it inside the library. If it's found it does not, no problem, I'll try to implement it by rewriting the _list methods. |
The If the I'll wait for confirmation on whether there is interest on having this inside libsrtp before doing any other change. |
_hash methods are an internal, agnostic to _list implementation.
This PR is ready for review. GitHub actions should all succeed.
Definition and implementation of Do you need anything from my side that I can provide to consider this change? |
@jmillan, Will try to get some other opinions, but I am not against using a hash for this to improve performance. |
Thanks @pabuhler, Sure, I can make this configurable if needed. |
Should this option be build time and follow the same behaviour as others like |
Hi @jmillan, I have talked with some others on the team and the consensus is that we are unsure if this the right approach. Having a faster lookup using a hash or some other data structure is a good idea but using the approach of having multiple list per session adds an unnecessary layer. It would be preferable to replace the current internal list implementation with something faster and flexible but that there is still one list per session.
This was maybe not the answer you where looking for, and I apologize for taking some time to gather feedback. |
Hi @pabuhler, This is the best option I could think of. Yes, it adds an extra layer which IMHO is so small it can't even be measured, as it makes a single binary mask on two unsigned integers to get the list where the stream is stored:
I think I'll go this way for the time being. I think I'll have to fork libsrtp anyway as I need to modify meson.build (which is what we use) to add the new file, with the hash implementation on the sources to compile.
This was my best shot, I don't know about a better approach at the moment, but don't hesitate to contact me anytime.
All is good! |
Closing as this approach was rejected by the project. Also, this is replaced by a hopefully more suitable solution #674 |
Store SRTP streams in several lists rather than in a single one, making those effectively smaller (and faster to iterate) than the current single one.
Each hash entry is a
srtp_stream_list_t
, being this one where the streams are ultimately stored as they are currently. In order to select thesrtp_stream_list_t
where a stream is stored, the SSRC is masked with the hash size (the number of lists it contains).Enhances greatly the performance derived from iterating the lists as the list to be iterated is, in average, N times smaller comparing to having a single one. N being the number of lists in the hash, which in this PR has been set to 32.
I'm aware of #612, and I think what I'm doing here cannot be done by rewriting the
_list
methods from the outside. These changes perfectly fit with the mentioned PR anyway.EDIT:
SRTP_STREAM_HASH_SIZE 32
.