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

The way ping works is kind of inefficient. #6

Open
ioquatix opened this issue Nov 19, 2024 · 2 comments
Open

The way ping works is kind of inefficient. #6

ioquatix opened this issue Nov 19, 2024 · 2 comments

Comments

@ioquatix
Copy link

ioquatix commented Nov 19, 2024

WebSockets (and TCP) both provide keep-alive mechanisms- and HTTP/2+ has connection handling that is well aware of problems / disconnects.

I don't know about browsers, but I'd assume they raise errors when things are broken/disconnected.

There is a cost to emitting ping frames at the application layer:

  • If you imagine 10,000 connections emitting pings every 3 seconds, that's 3000+ messages per second just for ping.
  • Ping message is emitted even if other messages are emitted (redundant).
  • WebSockets already provide ping and disconnection semantics that, IMHO, work as expected.
  • (Unnecessarily) drain power and network usage on mobile devices.

There is no real need to emit a ping frame every 3 seconds IMHO.

I'd personally like to clean up the semantics a bit, e.g. don't emit pings unless absolutely necessary, perhaps change the time to 10-30 seconds, or better yet, move it to the concern of the front end adapter so we can experiment.

@ioquatix
Copy link
Author

I found this discussion interesting: https://www.w3.org/Bugs/Public/show_bug.cgi?id=13104

@palkan
Copy link
Member

palkan commented Nov 25, 2024

We had discussed this some time ago: rails/rails#45112

tl;dr The problem is that low-level keepalive can be unreliable due to a number of intermediate proxies/whatever. The application-level heartbeat provides 100% guarantees.

Ping message is emitted even if other messages are emitted (redundant).
(Unnecessarily) drain power and network usage on mobile devices.

Yeah, that's something that could be considered at the protocol level. For the latter, we (at AnyCable) allow to specify custom ping intervals (incuding per-client ping intervals).

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

2 participants