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 SOCK_NONBLOCK to reduce system calls for outgoing connections #293
Conversation
…ockets Signed-off-by: Andy Pan <i@andypan.me>
Signed-off-by: Andy Pan <i@andypan.me>
@madolson @zuiderkwast Got a minute for this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good in general. Just a few small suggestions.
I'm not sure it has a very big impact though. It's only used for creating the listening socket and for creating outgoing connections, which is basically only for replication and cluster nodes (maybe something more?) but we don't use it for valkey-cli, valkey-benchmark and (IIRC) sentinel which use hiredis for this.
What's more important is accept that we do for each client, but we already use accept4() when it's available (setting options at the same time as accepting).
Signed-off-by: Andy Pan <i@andypan.me>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## unstable #293 +/- ##
===========================================
Coverage ? 68.44%
===========================================
Files ? 108
Lines ? 61558
Branches ? 0
===========================================
Hits ? 42136
Misses ? 19422
Partials ? 0
|
Speaking of which, check out #294 as well. |
Any updates? |
I left it open for a week to let others have time to review. The |
What this PR mainly does is:
anetCreateSocket()
to make it more generic for more socket arguments, and useSOCK_NONBLOCK
if available, which will reduce two system calls (F_GETFL
andF_SETFL
) of enabling the non-blocking mode on each newly created socket.anetUnixGenericConnect()
that callsanetCreateSocket()
.SOCK_NONBLOCK
for system callsocket()
is supported on most UNIX-like platforms (linux
,dragonfly
,freebsd
,netbsd
,openbsd
,solaris
, etc.). This improvement will significantly reduce the system calls considering how massivelyanetTcpGenericConnect()
will be called when needed.As for the cleanup,
anetUnixGenericConnect
was introduced in c61e692 and the only reference back then was from thecreateClient()
inredis-benchmark.c
which had been removed in ec8f066 and made it the dead code. Most of that dead code was also cleaned up in f657315, and it seems that theanetUnixGenericConnect
got left out. Therefore, I also cleaned it up, but I'm not so certain about doing this cleanup in this PR. Maybe you would prefer to do it in a separate PR?References