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 active socket #6

Merged
merged 8 commits into from
May 14, 2024
Merged

Use active socket #6

merged 8 commits into from
May 14, 2024

Conversation

Noarkhh
Copy link
Collaborator

@Noarkhh Noarkhh commented Apr 24, 2024

This PR modifies the Source so that it relies on a :gen_tcp socket using active mode rather than non-active, since the latter seems to use a lot more CPU in our implmentation, especially where the demand is higher than supply. To keep the flow control features the socket is using the active: :once or active: N, which limits the amount of messages that the element will receive before returning to active: false state.

@Noarkhh Noarkhh requested a review from mat-hek April 24, 2024 11:19
lib/membrane_tcp/source.ex Show resolved Hide resolved
raise "TCP Socket receiving error, reason: #{inspect(reason)}"
end
def handle_demand(_pad, size, _unit, _ctx, state) do
:inet.setopts(state.local_socket.socket_handle, active: size)
Copy link
Member

Choose a reason for hiding this comment

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

This makes sense if only if the demand unit is buffers, you can enforce it in def_output_pad

}

{
[buffer: {:output, %Buffer{payload: payload, metadata: metadata}}, redemand: :output],
Copy link
Member

Choose a reason for hiding this comment

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

since we request the same amount of buffers from TCP that is demanded, the redemand is not needed

@Noarkhh Noarkhh requested a review from mat-hek May 8, 2024 09:06
@Noarkhh Noarkhh merged commit f8fc1df into master May 14, 2024
3 checks passed
@Noarkhh Noarkhh deleted the use-active-socket branch May 14, 2024 10:38
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.

2 participants