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

ws-server: Submit ping regardless of WS messages #788

Merged
merged 2 commits into from
Jun 3, 2022

Conversation

lexnv
Copy link
Contributor

@lexnv lexnv commented Jun 2, 2022

This PR ensures that a Ping frame is submitted regardless of WS traffic.

Previously, the ping interval timer was dropped with each iteration of the select loop.
As a result, we could encounter a scenario of Ping starvation, where pings are never
submitted due to WS traffic being received at a fast pace.

This ensures the ping interval timer is propagated and reinitialized when triggered, leading
to a Ping being submitted even if the server is handling messages.

One drawback of this approach is that the server spends some cycles handling the Ping
frames instead of the actual server load. One advantage is that the keep-alive functionality
is entirely handled via control frames, as opposed to either: ping interval being expired, or
WS messages handled.

Testing Done

  • manual testing performed with ws server and ws client
  • ws server registered to submit pings every 2 seconds
  • ws client submits requests every 1 second
> ping - 1
2022-06-02T12:12:52.781744Z DEBUG jsonrpsee_ws_server::server: send ping
2022-06-02T12:12:52.781967Z TRACE soketto::connection: 3918d5d9: send: (Ping (fin 1) (rsv 000) (mask (0 0)) (len 0))
2022-06-02T12:12:52.787939Z TRACE soketto::connection: 3918d5d9: recv: (Pong (fin 1) (rsv 000) (mask (1 7e9b6b21)) (len 0))
2022-06-02T12:12:52.788033Z DEBUG jsonrpsee_ws_server::server: recv pong

> request - 1
   2022-06-02T12:12:52.788106Z TRACE soketto::connection: 3918d5d9: recv: (Text (fin 1) (rsv 000) (mask (1 bfcc4e07)) (len 45))
   2022-06-02T12:12:52.791014Z TRACE jsonrpsee_ws_server::server: send: {"jsonrpc":"2.0","result":"lo","id":3}

> request - 2
   2022-06-02T12:12:53.798444Z TRACE soketto::connection: 3918d5d9: recv: (Text (fin 1) (rsv 000) (mask (1 daff6382)) (len 45))
   2022-06-02T12:12:53.798858Z TRACE jsonrpsee_ws_server::server: send: {"jsonrpc":"2.0","result":"lo","id":4}

> ping - 2
2022-06-02T12:12:54.783803Z DEBUG jsonrpsee_ws_server::server: send ping
2022-06-02T12:12:54.784021Z TRACE soketto::connection: 3918d5d9: send: (Ping (fin 1) (rsv 000) (mask (0 0)) (len 0))
2022-06-02T12:12:54.788594Z TRACE soketto::connection: 3918d5d9: recv: (Pong (fin 1) (rsv 000) (mask (1 6664414f)) (len 0))
2022-06-02T12:12:54.788635Z DEBUG jsonrpsee_ws_server::server: recv pong

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
@lexnv lexnv requested a review from a team as a code owner June 2, 2022 12:11
Copy link
Member

@TarikGul TarikGul left a comment

Choose a reason for hiding this comment

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

One drawback of this approach is that the server spends some cycles handling the Ping
frames instead of the actual server load. One advantage is that the keep-alive functionality
is entirely handled via control frames, as opposed to either: ping interval being expired, or
WS messages handled.

👍

ws-server/src/server.rs Outdated Show resolved Hide resolved
Copy link
Member

@niklasad1 niklasad1 left a comment

Choose a reason for hiding this comment

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

great, some questions if we could use tokio::interval instead of tokio::sleep
also maybe it makes sense to have this disabled by default and folks can opt-in if they want this overhead.

we will likely catch this from the "daily" benchmarks anyway.

@niklasad1 niklasad1 merged commit 6421530 into master Jun 3, 2022
@niklasad1 niklasad1 deleted the ping_pong_interval_set branch June 3, 2022 08:16
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

Successfully merging this pull request may close these issues.

3 participants