-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
pipeToRouter(): Use static map of PipeTransport pairs #697
Conversation
- If `router1.pipeToRouter(router2)` is called and later `router2.pipeToRouter(router1)` is called, then the latter will reuse the already existing pair of `PipeTransports` instead of creating a new pair.
This is not ready yet. I'm adding a test and, in fact, it was buggy. |
Ready |
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.
I really dislike global state like this.
What I would suggest to do instead is to replace PipeTransport[]
with Promise<PipeTransport[]>
and set key in maps of both routers involved. And similarly when one router is closed to remove corresponding entry on all routers that are piped to/from it.
I can't say I know how AwaitQueue
works, but above will probably allow to remove its need too.
Honestly I don't see any benefits in your approach. This is indeed a global state because it must take into account all existing Routers no matter in which Worker they have been created. When calling router1.pipeToRoute(router2) the method must access a global state in which it may find that there is a PipeTransport pair involving both router1 and router2, no matter in which Router it was previously created. And such a global state must be somewhere, and I prefer to keep it private in Router class than adding a public instance setter in Router to set the pair externally. In summary, I consider that this is a perfect use case for global state. |
In my approach it only needs to access internal state of both routers, which it can, and no global state is needed, just internal states of those 2 routers. I can implement this when I have some time. Global state is better to be avoided and for this use cases it totally can be avoided. |
Must to say, i've just did an implementation between two servers that's almost equal to previous code (with this fixed and other improvements), and was thinking that maybe pipeToRouter could be moved out to an external mediasoup-helpers package, so Mediasoup Code can be reduced... so maybe using internal info is not so good :-/ |
@nazar-pc I've another reason to go the way this PR is done. This: // AwaitQueue instance to make pipeToRouter tasks happen sequentially.
private static readonly pipeToRouterQueue =
new AwaitQueue({ ClosedErrorClass: InvalidStateError }); This queue must be global, why? because the app may call
And both cases are wrong. |
In the other side, I agree |
Obviously It can't be removed in a 3.x version, but could be moved to the mediasoup-helpers package and use It as dependency. I have seen some other APIs with a similar state, let me review them and open a new issue listing them. |
It's very clear to me that such a mediasoup-helper package should not be included within mediasoup itself. Otherwise it means lot of sugar API and opinionated features to maintain as part of the core library (since it would be a direct dependency). |
In my case it would not, this is why I suggested to store mapping to You can store the promise before it is resolved in a map. Thus avoiding mentioned issue and allowing any number of pipe transports to be created concurrently (in your case even with multiple workers involved, all of them will wait on each other). |
It's very clear to me that such a mediasoup-helper package should not be
included within mediasoup itself. Otherwise it means lot of sugar API and
opinionated features to maintain as part of the core library (since it
would be a direct dependency).
Good point, my sugestion about using It as a dependency was only while in
the 3.x branch to maintain backward compatibility, once that a future 4.x
version appears that would be removed and users pointed to use
mediasoup-helpers directly if they want, making core mediasoup smaller.
|
Oh yes... right! I'll do. BTW will you be able to replicate it in Rust? I've very limited time these days and learning Rust doesn't fit well. |
Yes, should be. |
Being honest I don't want to maintain any mediasoup-helper package, and it wouldn't make sense that it just provides with the pipeToRoute() helper. So I prefer to not create any separate library nor include it in v3. |
I believe |
@nazar-pc please, re-review, you'll like it :) (and I've removed the |
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.
I like it much better indeed, still a few comments
@nazar-pc re-review please :) |
I've put a description of the things that I've seen can be moved out at #705. |
router1.pipeToRouter(router2)
is called and laterrouter2.pipeToRouter(router1)
is called, then the latter will reuse the already existing pair ofPipeTransports
instead of creating a new pair.