Switch from gen_tcp to the socket NIF API - #9
Merged
Merged
Conversation
Use socket:accept/recv/send/close throughout the acceptor and
connection loop. The raw SO_REUSEPORT options are replaced with the
portable {socket, reuseport} option and the listener's send_timeout
behaviour is emulated with socket:send/3 plus close-on-error.
Accepted sockets have {otp, select_read} enabled: every successful
recv re-arms the read select inside the same NIF call, so the steady
state is one $socket message plus one recv per request instead of
recv/EAGAIN/select/recv. Keep-alive throughput improves ~7%
(107.5k -> 115.1k req/s, 64 connections, M2 Pro). Connection-per-
request drops ~6% on stock OTP because socket:close finalizes on a
dirty scheduler; a fix is pending upstream.
select_read requires OTP 27.3, so the CI matrix drops 25 and 26.
Dialyzer is skipped on 27 since its socket specs predate select_read.
lpgauth
force-pushed
the
socket-backend
branch
from
August 15, 2026 18:21
848e09e to
ff0beef
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ports the acceptor and connection loop from gen_tcp to the socket NIF API.
{socket, reuseport}option.send_timeout/send_timeout_closebehaviour is emulated withsocket:send/3and close-on-error.{otp, select_read}: each successful recv re-arms the read select inside the same NIF call, so the steady state is one$socketmessage plus one recv per request instead of recv/EAGAIN/select/recv.Benchmarks (M2 Pro, 64 connections, empty 200 handler):
{otp, select_read}was added in OTP 27.3, so the CI matrix drops 25 and 26. Dialyzer is skipped on 27 because its socket specs predate select_read (compile/xref/eunit still run there).