-
Notifications
You must be signed in to change notification settings - Fork 742
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
Improvements for TLS with I/O threads #1271
Improvements for TLS with I/O threads #1271
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## unstable #1271 +/- ##
=========================================
Coverage 70.68% 70.68%
=========================================
Files 114 115 +1
Lines 63150 63158 +8
=========================================
+ Hits 44637 44643 +6
- Misses 18513 18515 +2
|
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.
Looks good to me, but I'd like @madolson to take a look too.
Impressing performance result, and this is with more lines deleted than added!
Does the change have any performance impact without I/O threads enabled?
Will check tomorrow, but @uriyage please fix the DCO when you get a chance. |
I would be surprised if there was any performance improvement when io-threads are not used. This will actually cause SSL_pending and ERR_clear_error to be called multiple times in some scenarios where we are reading multiple times on the read handler. BUT I think those cases are rare and AFAIK are mostly limited to cases like the connSyncReadLine. |
src/tls.c
Outdated
ERR_clear_error(); | ||
int ret = SSL_read(conn->ssl, ptr, size); | ||
ret = updateStateAfterSSLIO(conn, ret, 0); | ||
int ret = connTLSRead(conn_, ptr, size); |
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.
I think this will cause us to potentially keep updating the event in updateStateAfterSSLIO. Same for the connTLSSyncReadLine. Maybe you want to create an internal function which will also get the update_event indication?
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.
Thanks, I reverted this change. Instead, we will call updatePendingFlags
explicitly.
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.
Other than Ran's comment, this looks good to me. Nice perf results!
Signed-off-by: Uri Yagelnik <[email protected]>
As expected, there is no performance difference without I/O threads as the behavior remains the same.
The only change is indeed for |
62adf80
to
e65c2a0
Compare
Main thread profiling revealed significant overhead in TLS operations, even with read/write offloaded to I/O threads:
Perf results:
10.82% 8.82%
valkey-server libssl.so.3 [.] SSL_pending
# Called by main thread after I/O completion10.16% 5.06%
valkey-server libcrypto.so.3 [.] ERR_clear_error
# Called for every event regardless of thread handlingThis commit further optimizes TLS operations by moving more work from the main thread to I/O threads:
Improve TLS offloading to I/O threads with two main changes:
Move
ERR_clear_error()
calls closer to SSL operationsare handled by I/O threads
Optimize
SSL_pending()
checksTLS_CONN_FLAG_HAS_PENDING
flag to track pending dataPerformance improvements:
Testing setup based on https://valkey.io/blog/unlock-one-million-rps-part2/
Before:
After: