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

Flatbuffers #927

Closed
wants to merge 321 commits into from
Closed

Flatbuffers #927

wants to merge 321 commits into from

Conversation

jmillan
Copy link
Member

@jmillan jmillan commented Oct 19, 2022

NOTE: THIS PR IS DEPRECATED IN FAVOUR OF #1063

WIP to remove JSON in favour of flatbuffers for as the worker communication format.

  • JSON parsing is CPU intensive.
  • JSON is not type safe.
  • flatbuffers does not parse the buffer. Reading the message takes 0ms.
  • flatbuffers is type safe since code (C++, Typescript, Rust, etc) is autogenerated out of the schema definitions.

Extras that come along with this changes:

  • There is now a single Channel for worker communication.
    • Previously there were 2 (Channel and PayloadChannel)
  • Each message sent Node->Worker requires a single write() call to Channel.
    • Previously 2 calls per message were needed for Channel and 4 for PayloadChannel.
  • Each message send Worker->Node previously executed two extra calls to memcpy that are now executed now.

Feature request for making optional field getters return undefined instead of null if the value is not set.

  • update flatbuffers meson wrapdb in order to use latest version PR ready
  • Instead of creating a vector for uint8*, make a memcpy in C++ and the correponding Buffer copy in TS.
  • Consider whether it's worth it avoiding to create a new Uint8Array out of the flatbuffers builder each time we send data to worker.
  • Remove temporal checks in TS once this issue is fixed.
  • Planus not supporting same table name in different namespaces.
  • flatbuffers (TS) should throw TypeError instead of Error when there is a missing required field. PR

Copy link
Member

@ibc ibc left a comment

Choose a reason for hiding this comment

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

Looks amazing. Just a few comments or questions basically to understand things.

fbs/consumer.fbs Outdated Show resolved Hide resolved
fbs/rtpParameters.fbs Outdated Show resolved Hide resolved
fbs/rtpParameters.fbs Outdated Show resolved Hide resolved
fbs/rtpParameters.fbs Outdated Show resolved Hide resolved
node/src/Channel.ts Outdated Show resolved Hide resolved
node/src/Channel.ts Show resolved Hide resolved
node/src/Channel.ts Outdated Show resolved Hide resolved
node/src/Channel.ts Outdated Show resolved Hide resolved
node/src/Transport.ts Show resolved Hide resolved
@ibc
Copy link
Member

ibc commented Oct 19, 2022

Why such a double /fbs/fbs/ path? I know why and wonder whether we should rename the root one to flatbuffers.

@jmillan
Copy link
Member Author

jmillan commented Oct 19, 2022

For some reason I don't understand libwebrtc dependency is not being compiled with -DMS_LOG_STD and -DMS_TEST flags, hence the worker tests are failing.

Any idea why those flags are suddenly not being passed to this dependency? I've just added a new dependency (flatbuffers) within this PR and I can't see how it could affect it.

cc @nazar-pc if you can please comment.

NOTE: It is not a blocker, I can still go on with this PR.

@nazar-pc
Copy link
Collaborator

Any idea why those flags are suddenly not being passed to this dependency? I've just added a new dependency (flatbuffers) within this PR and I can't see how it could affect it.

Are you sure it worked before then? I see nothing that would have affected it.

@jmillan
Copy link
Member Author

jmillan commented Oct 21, 2022

Are you sure it worked before then? I see nothing that would have affected it.

It works in v3 indeed. Otherwise the GH actions would fail the same way.

@nazar-pc
Copy link
Collaborator

nazar-pc commented Oct 21, 2022

I see CI fails due to segfault when running tests, why do you think it is related to those constants?

@jmillan
Copy link
Member Author

jmillan commented Oct 21, 2022

why do you think it is related to those constants?

I'm certain.

if you add '-v' option to meson compile statement in test: setup target of worker/Makefile you'll see that libwebrtc is compiled without such flags.

Then when running the test executable mediasoup initializes DepLibwebrtc, this generates a log that instead of stdout goes to a non existent Channel , hence the core dump.

I've verified it compiling the debug symbols and running the test binary with lldb

@jmillan
Copy link
Member Author

jmillan commented Oct 21, 2022

I'm checking the rest of warnings too, which are probably related to the compiler versions used in GH actions.

@nazar-pc
Copy link
Collaborator

I have no idea why it stops adding constants, but should be possible to debug by incrementally modifying meson.build files in v3 branch and see at which point it breaks.

@jmillan
Copy link
Member Author

jmillan commented Oct 23, 2022

I have no idea why it stops adding constants, but should be possible to debug by incrementally modifying meson.build files in v3 branch and see at which point it breaks.

Yes, I need to debug it before continuing pushing further commits here.

@jmillan
Copy link
Member Author

jmillan commented Oct 24, 2022

3eb3813 creates a new libwebrtc_test dependency with the required 'cpp_flags'. 'mediasoup_worker_test' makes use of such dependency instead of the non test 'libwebrtc' dependency.

As indicated in the commit comment, I don't know how it worked before, but as I understand 'cpp_args' are not passed to subprojects.

@nazar-pc
Copy link
Collaborator

As indicated in the commit comment, I don't know how it worked before, but as I understand 'cpp_args' are not passed to subprojects.

Talks to Meson folks on Matrix, they're pretty responsive there and might help

Copy link
Member

@ibc ibc left a comment

Choose a reason for hiding this comment

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

Some preliminary comments but I need a call to discuss in a call

fbs/common.fbs Outdated Show resolved Hide resolved
fbs/request.fbs Outdated Show resolved Hide resolved
fbs/request.fbs Outdated Show resolved Hide resolved
fbs/response.fbs Outdated Show resolved Hide resolved
fbs/response.fbs Outdated Show resolved Hide resolved
@jmillan
Copy link
Member Author

jmillan commented Apr 13, 2023

IMHO the whole generation of the flatbuffers request body (before sending it) should be wrapped with try/catch and the catch block should generate a

IMHO it would be better to provide a patch to flatbuffers so it throws optionally TypeError instead of Error here. I'm adding this task in the issue description. Otherwise we will fill everything with these try/catch blocks.

PR: google/flatbuffers#7910

@jmillan
Copy link
Member Author

jmillan commented Apr 13, 2023

@nazar-pc, could you please check the warning given by clippy? Following the compiler suggestions leads me to an endless loop.

@ibc
Copy link
Member

ibc commented Apr 13, 2023

PR: google/flatbuffers#7910

Once that PR is merged and released and we upgrade flatbuffers dep, there is a test in mediasoup that will fail. Easy fix. It's has a note about this.

@nazar-pc
Copy link
Collaborator

@nazar-pc, could you please check the warning given by clippy? Following the compiler suggestions leads me to an endless loop.

Please push what you have before Saturday (I'll be mostly unavailable today) and I'll try to make some progress here. Not sure how much, but it'll be helpful for me to look at changes as a whole rather than patching tiny things here and there.

@jmillan
Copy link
Member Author

jmillan commented Apr 14, 2023

@nazar-pc, could you please check the warning given by clippy? Following the compiler suggestions leads me to an endless loop.

Please push what you have before Saturday (I'll be mostly unavailable today) and I'll try to make some progress here. Not sure how much, but it'll be helpful for me to look at changes as a whole rather than patching tiny things here and there.

This branch is up to date.

@jmillan
Copy link
Member Author

jmillan commented Apr 14, 2023

I'll try to make some progress here

I'll be out for the weekend but I'll be available during the week. We can sync anytime.

@nazar-pc
Copy link
Collaborator

nazar-pc commented Apr 15, 2023

I am reading through changes now and trying to understand what is going on and I see things that appear to be unrelated to this branch.

For example ConsumerOptions::enable_rtx was added, was it added because it was missing in one of the PRs in v3? If so it needs to be added to v3 and merged into here instead.

There are also a bunch of things edited under .github/workflows, none of which seem necessary (concurrency should have been added to v3 instead).

libwebrtc_test_dep is added for some reason, why not using libwebrtc_dep the way it was before?

BUILD_DIR ?= $(INSTALL_DIR)/build is interesting, it looks fine on surface, but what if you don't want to build in the same directory as you install stuff into? MEDIASOUP_OUT_DIR was specifically for build output, it is still where pip is stored.

General comments on the whole branch: 319 commits is completely insane and unmanageable at all, try to use rebase and squash features of git. You develop incrementally locally, but you don't need to push every though and every experiment to GitHub. Squash things into locally structured and named commits that can be reviewed individually. When something changes in v3, rebase on it, so we have up to date starting point for the whole branch and clean changes on top. Right now it looks more or less like a stream of consciousness and the only way to deal with it is to look at the whole thing, but then I don't have the context of why many of the things changed.

UPD: Looks like IDEA can't even compare the branches properly anymore, it essentially shows the wrong diff, so some of above changes are not really the changes that are present 😕

rust/src/fbs.rs Outdated
Comment on lines 1 to 9
//! Flatbuffers data structures compiled from `.fbs` files
pub use root::fbs::*;

const _: () = ::planus::check_version_compatibility("planus-0.3.1");

#[no_implicit_prelude]
mod root {
#[allow(missing_docs)]
#[allow(clippy::all)]
Copy link
Member Author

Choose a reason for hiding this comment

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

This file is auto-generated. Do we need to add this changes manually when the flatbuffers schema changes?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe the way you had it before could suppress the whole project. This will is currently committed into the repo, but it will be replaced with actually auto-generated during compile time in mediasoup-sys in the future, so these changes are temporary either way.

rust/src/fbs.rs Outdated
@@ -1,9 +1,12 @@
pub use root::*;
//! Flatbuffers data structures compiled from `.fbs` files
pub use root::fbs::*;
Copy link
Member Author

Choose a reason for hiding this comment

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

👍

Copy link
Member Author

Choose a reason for hiding this comment

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

nice

@ibc
Copy link
Member

ibc commented Apr 17, 2023

For example ConsumerOptions::enable_rtx was added, was it added because it was missing in one of the PRs in v3? If so it needs to be added to v3 and merged into here instead.

Probably we forgot to add that field in ConsumerOptions in Rust in the past. Yes, I agree that this should have been done in v3 first. But we must be pragmatic. Those non urgent/critical changes in v3 may later generate conflicts when it comes to merge flatbuffers into v3.

General comments on the whole branch: 319 commits is completely insane and unmanageable at all, try to use rebase and squash features of git. You develop incrementally locally, but you don't need to push every though and every experiment to GitHub. Squash things into locally structured and named commits that can be reviewed individually. When something changes in v3, rebase on it, so we have up to date starting point for the whole branch and clean changes on top. Right now it looks more or less like a stream of consciousness and the only way to deal with it is to look at the whole thing, but then I don't have the context of why many of the things changed.

Would it help if we rebase flatbuffers into a few commits with descriptive messages and force push it?

@jmillan
Copy link
Member Author

jmillan commented Apr 17, 2023

I'm trying to reduce the history of this branch by squashing commits...

@nazar-pc
Copy link
Collaborator

Would it help if we rebase flatbuffers into a few commits with descriptive messages and force push it?

Absolutely, but not sure how much time that'd require at this point

@jmillan
Copy link
Member Author

jmillan commented Apr 17, 2023

It's certainly impossible in terms of spent time to do squash commits at this point.

My only sane proposal is:

  • Create a new branch flatbuffers-new out of v3.
  • merge flatbuffers branch into it.
  • reset the last commit (the whole difference between flatbuffers and v3)
  • commit all diff into a single commit "flatbuffers".
  • remove flatbuffers branch.
  • rename flatbuffers-new to flatbuffers.

We would have a single commit with all the changes performed in this branch. IMHO, up to this point is the safest and cleanest option.

Do we agree?

@nazar-pc
Copy link
Collaborator

I don't think it would be so much better, but it would likely fix my IDE showing correct diff.

Please don't delete old flatbuffers branch though, I have created bug report into IntelliJ IDEA, hopefully they'll try to reproduce it and having branch around would be helpful for them.

@jmillan
Copy link
Member Author

jmillan commented Apr 17, 2023

NOTE: THIS PR IS DEPRECATED IN FAVOUR OF #1063

Please, don't push anything in flatbuffers branch but in flatbuffers-new.

I'm closing this PR.

@nazar-pc, I'm renaming this branch flatbuffers-old so the new branch is called flatbuffers. I'm telling this so you can update the issue you opened in IntelliJ IDEA.

@jmillan jmillan closed this Apr 17, 2023
@jmillan jmillan deleted the flatbuffers branch April 17, 2023 10:28
@jmillan
Copy link
Member Author

jmillan commented Apr 17, 2023

@nazar-pc, I'm renaming this branch flatbuffers-old so the new branch is called flatbuffers. I'm telling this so you can update the issue you opened in IntelliJ IDEA.

here:
https://github.com/versatica/mediasoup/tree/flatbuffers-old

@ibc
Copy link
Member

ibc commented Apr 17, 2023

I'm renaming this branch flatbuffers-old so the new branch is called flatbuffers

Please notify when done so I can retarget my PR.

@jmillan
Copy link
Member Author

jmillan commented Apr 17, 2023

Please notify when done so I can retarget my PR.

It's done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants