Skip to content

Conversation

essen
Copy link
Member

@essen essen commented Aug 21, 2025

The current implementation moves the Websocket data through stream handlers before the Websocket process receives it and parses it. The new mechanism relays the data directly as an Erlang message without any intermediary. It also manages HTTP/2 flow control in a simpler way (it maintains it at a configured value).

A new switch_protocol option (coming from the options returned from init/2) called data_delivery decides which mechanism to use: stream_handlers is the old behavior; relay the new.

  • I need to make sure flow control updates act as intended
    and don't increase too much. The default flow control value
    will depend on that. The value must be configurable.
  • Need to test the direct mechanism in other test suites
  • the benchmark test suite is greatly modified because I
    wanted to make sure Gun's poor performance was not negatively
    impacting results (this bit me earlier). Some tests use it,
    some don't, we should keep both for good measure.
  • Other minor todos.

@essen essen force-pushed the direct-data_delivery-for-h2-websocket branch from 31162a1 to cb5efcb Compare August 22, 2025 11:08
The current implementation moves the Websocket data through
stream handlers before the Websocket process receives it and
parses it. The new mechanism relays the data directly as
an Erlang message without any intermediary. It also manages
HTTP/2 flow control in a simpler way (it maintains it at a
configured value).

A new switch_protocol option (coming from the options returned
from init/2) called `data_delivery` decides which mechanism
to use: `stream_handlers` is the old behavior; `relay` the new.

WIP: Need to test the relay mechanism in other test suites

WIP: the benchmark test suite is greatly modified because I
     wanted to make sure Gun's poor performance was not negatively
	 impacting results (this bit me earlier). Some tests use it,
	 some don't, we should keep both for good measure.

WIP: Other minor todos.
@essen essen force-pushed the direct-data_delivery-for-h2-websocket branch from cb5efcb to 316a9d7 Compare August 22, 2025 11:18
%% - The relaying state is used by extended CONNECT protocols to
%% use a 'relay' data_delivery method.
%% - The stopping state indicates the stream used the 'stop' command.
%% @todo Do we need to buffer data before the response is sent? Probably.
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know if we must do this now but at least the location of this todo is wrong.

data_delivery_flow => maps:get(data_delivery_flow, Opts, 131072)
},
Pid ! {{Pid, StreamID}, {switch_protocol, Headers, ?MODULE, ModState}},
%% @todo We can't call the normal takeover because it tries to parse.
Copy link
Member Author

Choose a reason for hiding this comment

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

I mean, we can, the buffer is empty anyway. Remove the comment or clarify it to indicate that attempting to parse is not useful.

%% Unfortunately we cannot currently cancel read_body.
%% But that's OK, we will just stop reading the body
%% after the next message.
%% @todo We can't stop relay data_delivery currently.
Copy link
Member Author

Choose a reason for hiding this comment

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

Stop of reads comes from:

But to make it work with this feature we need a way to signal that we don't want to continue reading data from the stream.

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.

1 participant