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

Use polling instead of thread::sleep #49

Open
jprochazk opened this issue Oct 23, 2024 · 0 comments
Open

Use polling instead of thread::sleep #49

jprochazk opened this issue Oct 23, 2024 · 0 comments

Comments

@jprochazk
Copy link
Member

On native, we always block the thread using a thread::sleep/thread::yield_now after a read. The reason we sleep on those threads is to not busy-loop that CPU core. We should instead set the socket to non-blocking mode and poll it using native polling APIs. This would be useful for senders as well.
We use polling in Rerun, and it has a reasonably small footprint, so should be fine to add as a dependency here as well.

jprochazk added a commit that referenced this issue Oct 24, 2024
Currently, the `ws_receiver_blocking` function would always sleep after
every read. Additionally, it did not use the value from
`options.delay_blocking` for the sleep delay. This would result in that
thread being blocked for 10ms _after every read_ no matter what the user
configured it to, meaning it would receive data at an unnecessarily slow
rate.

In this PR:
- Instead of using `set_nonblocking` or calling `std::thread::sleep`
after every read, we now use `set_read_timeout` in the non-tokio native
impls.
- The `delay_blocking` option is removed in favor of `read_timeout`
- The default for `read_timeout` is `Some(10ms)`
- The ideal thing to do here would be to not block at all and instead
use native polling APIs. This work is left as a TODO for another PR.
  - #49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant