SslStream - Linux Solving it all in 4 lines (and deleting 2) - #25646
Conversation
|
The best bit, no throttle, no PAL crazy, so so simple. |
|
|
||
| extern "C" int32_t CryptoNative_SslGetError(SSL* ssl, int32_t ret) | ||
| { | ||
| while(ERR_peek_error() != ERR_peek_last_error()) |
There was a problem hiding this comment.
I think this needs some code comments explaining what is happening (and why)
|
@dotnet-bot test Outerloop Linux x64 Debug Build please |
|
If @bartonjs is happy with it, I am, too. |
|
RedHat seg fault in regular release @dotnet-bot test Linux x64 Release Build please |
|
fedora.25.amd64.Open:Debug-x64 Outerloop issue, same place |
bartonjs
left a comment
There was a problem hiding this comment.
I'm having trouble deciding if this is bad or not. I can't immediately think of a reason why it would be bad, but it's not obviously not-bad, either.
I guess you can always revert it when people start reporting nonsense errors.
| // This pops off "old" errors left by other operations | ||
| // until the first and last error are the same | ||
| // this should be looked at again when OpenSsl 1.1 is migrated to | ||
| while(ERR_peek_error() != ERR_peek_last_error()) |
There was a problem hiding this comment.
Please run clang-format -i on this file. (At least accepting any changes in this function)
| // This pops off "old" errors left by other operations | ||
| // until the first and last error are the same | ||
| // this should be looked at again when OpenSsl 1.1 is migrated to | ||
| while(ERR_peek_error() != ERR_peek_last_error()) |
There was a problem hiding this comment.
Technically this will stop if there's a repeat value. And the error could be stale.
There was a problem hiding this comment.
Yeah the stale is an issue, let me try a couple of things and see the perf.
|
@dotnet-bot test Linux x64 Release Build please |
|
@dotnet-bot test Outerloop Linux x64 Debug Build please |
1 similar comment
|
@dotnet-bot test Outerloop Linux x64 Debug Build please |
| // This pops off "old" errors left by other operations | ||
| // until the first and last error are the same | ||
| // this should be looked at again when OpenSsl 1.1 is migrated to | ||
| while(ERR_peek_error() != ERR_peek_last_error()) |
There was a problem hiding this comment.
This should be while<space>(. Please run clang-format -i against this file.
|
@dotnet-bot test Outerloop Linux x64 Debug Build please |
stephentoub
left a comment
There was a problem hiding this comment.
As long as @bartonjs says it's sound, this is certainly a better approach than the manual throttling.
…otnet#25646)" This reverts commit 03c7617.
|
@Drawaes what did you use in your benchmark? I would like to keep tracking the perf status of this while we do some more work to ensure no errors are left on the queue. |
|
The aspnetcore plaintext test from the asp team. They have it in docker now
…On Thu, 19 Apr 2018, 17:43 Paulo Janotti, ***@***.***> wrote:
@Drawaes <https://github.com/Drawaes> what did you use in your benchmark?
I would like to keep tracking the perf status of this while we do some more
work to ensure no errors are left on the queue.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#25646 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/APpZuYo5qgaAGJIgGvVsQVBkLxvTcrRAks5tqL69gaJpZM4QzDIq>
.
|
…corefx#25646) * Change get error to remove all but the last. * Remove clear errors * Added code comment * Try peeking at the errors before clearing * Make sure the error queue is cleared if there were multiple errors during Ssl_GetError * Format with clang Commit migrated from dotnet/corefx@03c7617
Well, I sat, I thought, ... I read some c.. and I think I figured it out..
Basically the problem is if another bit of code that used this thread didn't clean up after itself (bad manners if you ask me but you can't control everyone).
The errors are just a queue and we can "peek_last_error" but the problem is that we are calling Ssl_Get_Error.
Ssl_Get_Error is a about 100 lines of code that does a bunch of other things than just check the error queue (checks internal bio states for async needs read/write etc).
So we can't change that, and we can't change that it needs the error code of the latest error. And we can't change that it looks at the "first" item in the queue.
The current solution is to clear the error queue before each encrypt/decrypt but that hits the evil global lock and causes all the grief. And removing the clear of course causes potentially the wrong item at the top of the error queue.
However the clear is on the hot path, and what isn't on the hot path is the "Ssl_Get_Error" mostly because SslStream ensures sending of complete frames to OpenSSL so we don't rely on the "Needs Read/Write" in hot situations. We will get these for an actual error, but then that is now a slow path anyway.
To get to it, my solution is not to do the clear, but when we are in the error state, just makesure the queues first and last error number are the same with a Peek of the first and last (the only operations I have other than get). If they aren't the same then do a get to pop one off the queue and repeat until they equal.
Master ~200k rps
Throttle ~400k rps
Throttle with ProcCount/2 ~580k rps
With my error change
713021.51
This is my preferred solution over #25187