Repository navigation
Add benchmarks for SSLEngine implementations - #6360
normanmaurer wants to merge 1 commit into
Conversation
|
@nmittler I took some inspiration from the work you did in conscrypt with your benchmarks but added a lot more then what you have. Maybe you want to port this over. |
nmittler
left a comment
There was a problem hiding this comment.
@normanmaurer Looks great! Will port over. I've added this to google/conscrypt#31. Thanks!
| sTOc.flip(); | ||
|
|
||
| cTOsPos = cTOs.position(); | ||
| sTOcPos = sTOc.position(); |
|
|
||
| do { | ||
| int cTOsPos = cTOs.position(); | ||
| int sTOcPos = sTOc.position(); |
|
|
||
| private SslContext newServerContext() { | ||
| try { | ||
| File keyFile = new File(getClass().getResource("test_unencrypted.pem").getFile()); |
|
|
||
| abstract ByteBuffer newBuffer(int size); | ||
|
|
||
| void freeBuffer(ByteBuffer buffer) { } |
|
|
||
| protected void doTearDown() throws Exception { } | ||
|
|
||
| @Setup(Level.Invocation) |
There was a problem hiding this comment.
have you seen the warning for Level.Invocation in the javadocs? Have you tried just putting this in the test ... if this consumes a relatively small proportion of the benchmark invocation resources (cpu/time) then maybe we will get more accurate results?
There was a problem hiding this comment.
@Scottmitch yeah I saw this but I think we really not want to have this in the test itself.
There was a problem hiding this comment.
Agreed that it is ideal from a logical perspective to have it completely isolated from the benchmark. However I'm curious if we fall into the warnings that are listed in the javadocs for Level.Invocation.
As long as the overhead is consistent and "relatively small" compared to what we want to run in the benchmark then conceivably this may make the overhead of managing the counters/timers lower, reduce risk for coordinated omission, etc... WDYT?
There was a problem hiding this comment.
@Scottmitch yeah good point. Let me see how it turns out when not using Level.Invocation
|
Created a quick and dirty proto to plot the JMH results.. https://rawgit.com/johnou/ploty-proto/master/index.html |
8551241 to
8244b8c
Compare
|
@Scottmitch PTAL again. Also changed the handshake benchmark to record the average time needed for a handshake. This may be a more useful benchmark |
| ByteBuffer dst = unwrapDstBuffer; | ||
| dst.clear(); | ||
|
|
||
| SSLEngineResult unwrapResult = serverEngine.unwrap(src, dst); |
| ByteBuffer dst = wrapDstBuffer; | ||
| dst.clear(); | ||
|
|
||
| SSLEngineResult wrapResult = clientEngine.wrap(src, dst); |
| assert empty.remaining() == clientResult.bytesConsumed(); | ||
| assert cTOs.position() - cTOsPos == clientResult.bytesProduced(); | ||
|
|
||
| if (isHandshakeFinished(clientResult)) { |
There was a problem hiding this comment.
to avoid another conditional consider just assigning unconditionally:
clientHandshakeFinished = isHandshakeFinished(clientResult);| ByteBuffer src = wrapSrcBuffer; | ||
| src.position(0).limit(messageSize); | ||
|
|
||
| ByteBuffer dst = wrapDstBuffer; |
There was a problem hiding this comment.
are these temp variables necessary?
There was a problem hiding this comment.
Not really just preferred this to fetch it multiple times from the fields. Should I remove ?
There was a problem hiding this comment.
if they are not necessary then lets kill them ... less is more :)
| initEngines(); | ||
| boolean ok = doHandshake(); | ||
| assert ok; | ||
| // We explicit not call destroyEngines() and let the GC handle this as its a NOOP for JDK but not for |
There was a problem hiding this comment.
explicit not -> explicitly do not
There was a problem hiding this comment.
Is this shown to have a noticeable impact? Can we also test with SslProvider#OPENSSL_REFCNT (and cleanup after the iteration) to avoid this extra GC costs and see if finalizers have impacts? I'm curious if any differences exist and if they are noticeable with the short running micro benchmarks.
There was a problem hiding this comment.
I did not test it. Let me add the destroy here and also add the reference counted one to the mix.
|
Here is what I see from a run on my local laptop: |
|
@Scottmitch addressed your comments and these are the numbers (for 4096 only): |
| cTOs.flip(); | ||
| sTOc.flip(); | ||
|
|
||
| cTOsPos = cTOs.position(); |
| } | ||
|
|
||
| if (!serverHandshakeFinished) { | ||
| int serverAppReadBufferPos = serverAppReadBuffer.position(); |
| boolean serverHandshakeFinished = false; | ||
|
|
||
| do { | ||
| int cTOsPos = cTOs.position(); |
| sTOcPos = sTOc.position(); | ||
|
|
||
| if (!clientHandshakeFinished) { | ||
| int clientAppReadBufferPos = clientAppReadBuffer.position(); |
|
@trustin you may be interested as well. |
|
@normanmaurer I would suggest using |
|
@johnou good idea! |
269a680 to
ad59d4c
Compare
Scottmitch
left a comment
There was a problem hiding this comment.
few more comments left over from last time and then lgtm
There was a problem hiding this comment.
to avoid another conditional consider just assigning unconditionally
same comment as https://github.com/netty/netty/pull/6360/files#r102627897
Motivation: As we provide our own SSLEngine implementation we should have benchmarks to compare it against JDK impl. Modifications: Add benchmarks for wrap / unwrap and handshake performance. Result: Benchmarks FTW.
ad59d4c to
b183b25
Compare


Motivation:
As we provide our own SSLEngine implementation we should have benchmarks to compare it against JDK impl.
Modifications:
Add benchmarks for wrap / unwrap and handshake performance.
Result:
Benchmarks FTW.