Repository navigation
Use send()/recv() in IoSocketHandleImpl::writev()/readv() when there is only one IO buffer to work with. - #25695
Conversation
only one IO buffer to work with. Internal testing on Redis filter shows that this change gives 7% performance improvement. Signed-off-by: Wei Si <[email protected]>
Signed-off-by: Wei Si <[email protected]>
Signed-off-by: Wei Si <[email protected]>
Signed-off-by: Wei Si <[email protected]>
|
/assign @jmarantz |
|
/assign @yanavlasov |
Signed-off-by: Wei Si <[email protected]>
| ssize_t rc; | ||
| if (num_iov == 1) { | ||
| // Avoid paying the VFS overhead when there is only one IO buffer to work with | ||
| rc = ::write(fd, iov[0].iov_base, iov[0].iov_len); |
There was a problem hiding this comment.
OsSysCallsImpl is just simple wrap of syscall, we shouldn't hack it here. It seems like the only place write one slice with writev is SSL socket transport socket.
if this is the right place, we should change the io handle bio to use IoHandle::write.
Maybe we need some benchmark on generic TLS, which probably needs maintainers input.
There was a problem hiding this comment.
if this is the right place, we should change the io handle bio to use
IoHandle::write.
And that needs an different read/write interface IoHandle for accept plain buffer.
There was a problem hiding this comment.
Thanks for the input!
Actually after talking with my colleague, it looks like that the perf improvement doesn't come from replacing writev() with write() (the scatter-gather doesn't introduce much overhead), but from replacing writev() with send(), which will reduce some kernel VFS handling overhead.
I'm thinking whether to move the logic to:
|
After talking with my colleague, it looks like that the perf improvement doesn't come from replacing Planning to change |
|
@weisisea sounds like this is still a WiP? I'll flip into draft mode until this is sorted out. Thanks. |
|
Sounds good, thanks Joshua! |
Signed-off-by: Wei Si <[email protected]>
Signed-off-by: Wei Si <[email protected]>
Signed-off-by: Wei Si <[email protected]>
Signed-off-by: Wei Si <[email protected]>
| if (num_slices_to_read == 1) { | ||
| // Avoid paying the VFS overhead when there is only one IO buffer to work with | ||
| return sysCallResultToIoCallResult( | ||
| Api::OsSysCallsSingleton::get().recv(fd_, iov[0].iov_base, iov[0].iov_len, 0)); |
There was a problem hiding this comment.
emm...if this give good performance, I'm little to prefer to replace writev/readv with send/recv at here
But yea, that means we need to figure out what to do for mac and windows. If we just want to focus on linux platform, then this is probably the right place.
There was a problem hiding this comment.
Agree that we can change
to use send() since it explicitly specify the number of slices to be 1.I wonder whether it makes sense to generalize the optimization (not only TLS but other filters like Redis) - this PR tries to look at the number of slices in run time and calls send()/recv() if the number of slices is 1.
Signed-off-by: Wei Si <[email protected]>
Signed-off-by: Wei Si <[email protected]>
Signed-off-by: Wei Si <[email protected]>
Signed-off-by: Wei Si <[email protected]>
Signed-off-by: Wei Si <[email protected]>
Signed-off-by: Wei Si <[email protected]>
|
/retest |
|
Retrying Azure Pipelines: |
ravenblackx
left a comment
There was a problem hiding this comment.
Looks okay to me, one optional cleanup.
| #ifdef WIN32 | ||
| ASSERT_EQ(os_sys_calls.socketpair(AF_INET, SOCK_STREAM, 0, pipe_fds).return_value_, 0); | ||
| ASSERT_EQ(os_sys_calls.socketpair(AF_INET, SOCK_STREAM, 0, fds).return_value_, 0); | ||
| #else | ||
| ASSERT_EQ(pipe(pipe_fds), 0); | ||
| ASSERT_EQ(os_sys_calls.socketpair(AF_UNIX, SOCK_STREAM, 0, fds).return_value_, 0); | ||
| #endif |
There was a problem hiding this comment.
Maybe worth having something like, in win32/os_sys_calls_impl.h, #define ENVOY_DEFAULT_PIPE_TYPE AF_INET, and in posix/os_sys_calls_impl.h, #define ENVOY_DEFAULT_PIPE_TYPE AF_UNIX (or with an ifdef/else in the base os_sys_calls.h), then in the various places like this where os_sys_calls.socketpair is called with ifdefs around it, it could be called without the ifdefs, using this shared value instead.
There was a problem hiding this comment.
Good suggestion, will change!
|
Checking how to fix //test/extensions/filters/listener/http_inspector:http_inspector_test on Windows: |
Signed-off-by: Wei Si <[email protected]>
Signed-off-by: Wei Si <[email protected]>
|
/retest |
|
Retrying Azure Pipelines: |
|
/retest |
|
Retrying Azure Pipelines: |
Signed-off-by: Wei Si <[email protected]>
Signed-off-by: Wei Si <[email protected]>
Signed-off-by: Wei Si <[email protected]>
Signed-off-by: Wei Si <[email protected]>
Signed-off-by: Wei Si <[email protected]>
Signed-off-by: Wei Si <[email protected]>
|
/retest |
|
Retrying Azure Pipelines: |
Signed-off-by: Wei Si <[email protected]>
|
@yanavlasov Thanks a lot for merging, Yan! |
Commit Message: Use send()/recv() in IoSocketHandleImpl::writev()/readv() when there is only one IO buffer to work with.
Additional Description: Performance testing on Redis filter shows that this change gives 7% performance improvement.
Risk Level:
Testing:
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]