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

Rewrite re_ws_comms to work without async & tokio runtime #6005

Merged
merged 15 commits into from
Apr 17, 2024

Conversation

Wumpf
Copy link
Member

@Wumpf Wumpf commented Apr 17, 2024

What

Removes tokio & async code from re_ws_comms. Achieves this by spawning a thread for listening and another one for relaying messages (the later was already the case but via tokio).
Main disadvantage of this change here is that all clients now share the same thread for sending whereas before this was handled by the tokio pool. In theory we have less latency though since before we had to go from the broadcast thread to the client worker threads in a separate step.

Ended up depending on the polling crate because otherwise shutting down a tcplistener with vanilla std rust is close to impossible. The version I picked is such that Cargo.lock doesn't have (yet) another instance of this crate.

This change fixes a bug in the process where we'd not send all so far received messages to new clients.

⚠️ Rerun serve still needs a tokio runtime with this change ⚠️: To fix this we need to remove it also for the web server which should be quite a bit easier 🤞

Testing done:

  • pixi run rerun-web <some rrd> to serve several local browsers
  • pixi run python .\examples\python\face_tracking\main.py --serve to serve several local browsers and checking that they catch up on old data
    • keeping an eye on debug output ensuring that shutdown is graceful
  • Test the same on Mac (did only windows so far)

Checklist

  • I have read and agree to Contributor Guide and the Code of Conduct
  • I've included a screenshot or gif (if applicable)
  • I have tested the web demo (if applicable):
  • The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG
  • If applicable, add a new check to the release checklist!

To run all checks from main, comment on the PR with @rerun-bot full-check.

@Wumpf Wumpf added 🕸️ web regarding running the viewer in a browser 🚜 refactor Change the code, not the functionality include in changelog labels Apr 17, 2024
@Wumpf Wumpf changed the title Rewrite re_ws_comms to work without async & tokio runtime Rewrite re_ws_comms to work without async & tokio runtime Apr 17, 2024
Copy link

github-actions bot commented Apr 17, 2024

Deployed docs

Commit Link
3687ec9 https://landing-9jrgkfv6a-rerun.vercel.app/docs

indexmap = "2.1" # Version chosen to align with other dependencies
indicatif = "0.17.7" # Progress bar
infer = "0.15" # infer MIME type by checking the magic number signaturefer MIME type by checking the magic number signature
indexmap = "2.1" # Version chosen to align with other dependencies
Copy link
Member Author

Choose a reason for hiding this comment

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

my local formatter had different ideas I guess. All I wanted to do is sort some dependencies

/// Handle to keep the [`re_ws_comms::RerunServer`] alive
_rerun_server: RerunServerHandle,
/// Rerun websocket server.
_rerun_server: RerunServer,
Copy link
Member Author

Choose a reason for hiding this comment

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

note that there's no distinction between RerunServer and RerunServerHandle now

pixi.toml Show resolved Hide resolved
crates/re_ws_comms/Cargo.toml Outdated Show resolved Hide resolved
crates/re_ws_comms/Cargo.toml Show resolved Hide resolved
pixi.toml Show resolved Hide resolved
crates/re_ws_comms/src/server.rs Show resolved Hide resolved
crates/re_ws_comms/src/server.rs Show resolved Hide resolved
crates/re_ws_comms/src/server.rs Outdated Show resolved Hide resolved
crates/re_ws_comms/src/server.rs Outdated Show resolved Hide resolved
crates/re_ws_comms/src/server.rs Outdated Show resolved Hide resolved
crates/re_ws_comms/src/server.rs Outdated Show resolved Hide resolved
crates/re_ws_comms/src/server.rs Outdated Show resolved Hide resolved
Copy link
Member

@emilk emilk left a comment

Choose a reason for hiding this comment

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

Awesome

@Wumpf Wumpf force-pushed the andreas/ws_comms-without-tokio branch from 77f7638 to 3687ec9 Compare April 17, 2024 14:50
@Wumpf Wumpf merged commit a299f4b into main Apr 17, 2024
37 checks passed
@Wumpf Wumpf deleted the andreas/ws_comms-without-tokio branch April 17, 2024 15:05
Wumpf added a commit that referenced this pull request Apr 18, 2024
#6030)

### What

* Followup to #6005
* another piece of #5907

Removes tokio dependency from re_web_viewer_server:
* async `WebViewerServer` no longer uses tokio internally, instead use
`future_channel::oneshot` for shutdown
* `WebViewerServerHandle` is now optional (but default enabled) and
spawns a thread that internally uses the tiny pollster crate
* removed `re_web_viewer_server`'s main file - it's not used by any test
and may thus rot
    * this allows us to also remove the clap dependency from this crate


⚠️ Rerun serve/connect still needs a tokio runtime with this change ⚠️:
Likely the last piece after this is `re_sdk_comms` which is very similar
in nature to `re_ws_comms`.

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using examples from latest `main` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/6030?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/6030?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!

- [PR Build Summary](https://build.rerun.io/pr/6030)
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)

To run all checks from `main`, comment on the PR with `@rerun-bot
full-check`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
include in changelog 🚜 refactor Change the code, not the functionality 🕸️ web regarding running the viewer in a browser
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants