Skip to content

Adding benchmark for ciphers - #333

Merged
nmittler merged 2 commits into
google:masterfrom
nmittler:ciphers
Sep 18, 2017
Merged

nmittler merged 2 commits into
google:masterfrom
nmittler:ciphers

Conversation

@nmittler

Copy link
Copy Markdown
Contributor

Supporting perf work for #317

@nmittler nmittler added this to the 1.0.0 milestone Sep 14, 2017
@nmittler nmittler self-assigned this Sep 14, 2017
@nmittler
nmittler requested a review from flooey September 14, 2017 17:35
@nmittler

Copy link
Copy Markdown
Contributor Author

Note: This currently will only work on OpenJDK until #330 is resolved.

@nmittler

Copy link
Copy Markdown
Contributor Author

@carl-mastrangelo FYI

@nmittler

nmittler commented Sep 14, 2017 •

Copy link
Copy Markdown
Contributor Author

FYI, results show we have a lot of work to do :)

Benchmark                            (a_transformation)  (b_inputLength)  (c_bufferType)  (d_provider)   Mode  Cnt       Score       Error  Units
JmhCipherEncodingBenchmark.encode  AES/CBC/PKCS5Padding              128           ARRAY           JDK  thrpt   10  628124.584 ±  3399.299  ops/s
JmhCipherEncodingBenchmark.encode  AES/CBC/PKCS5Padding              128           ARRAY     CONSCRYPT  thrpt   10  314394.165 ± 32997.656  ops/s
JmhCipherEncodingBenchmark.encode  AES/CBC/PKCS5Padding              128       HEAP_HEAP           JDK  thrpt   10  625497.657 ±  4731.143  ops/s
JmhCipherEncodingBenchmark.encode  AES/CBC/PKCS5Padding              128       HEAP_HEAP     CONSCRYPT  thrpt   10  336824.484 ± 37102.882  ops/s
JmhCipherEncodingBenchmark.encode  AES/CBC/PKCS5Padding              128     HEAP_DIRECT           JDK  thrpt   10  611264.564 ±  4793.583  ops/s
JmhCipherEncodingBenchmark.encode  AES/CBC/PKCS5Padding              128     HEAP_DIRECT     CONSCRYPT  thrpt   10  341128.836 ±  6019.438  ops/s
JmhCipherEncodingBenchmark.encode  AES/CBC/PKCS5Padding              128   DIRECT_DIRECT           JDK  thrpt   10  599686.552 ± 44808.829  ops/s
JmhCipherEncodingBenchmark.encode  AES/CBC/PKCS5Padding              128   DIRECT_DIRECT     CONSCRYPT  thrpt   10  325130.078 ±  5237.395  ops/s
JmhCipherEncodingBenchmark.encode  AES/CBC/PKCS5Padding              128     DIRECT_HEAP           JDK  thrpt   10  619990.716 ±  6252.780  ops/s
JmhCipherEncodingBenchmark.encode  AES/CBC/PKCS5Padding              128     DIRECT_HEAP     CONSCRYPT  thrpt   10  334116.501 ± 29918.501  ops/s
JmhCipherEncodingBenchmark.encode  AES/CBC/PKCS5Padding             1024           ARRAY           JDK  thrpt   10  362166.009 ±  3142.189  ops/s
JmhCipherEncodingBenchmark.encode  AES/CBC/PKCS5Padding             1024           ARRAY     CONSCRYPT  thrpt   10  244401.263 ±  2320.821  ops/s
JmhCipherEncodingBenchmark.encode  AES/CBC/PKCS5Padding             1024       HEAP_HEAP           JDK  thrpt   10  361092.135 ±  2986.658  ops/s
JmhCipherEncodingBenchmark.encode  AES/CBC/PKCS5Padding             1024       HEAP_HEAP     CONSCRYPT  thrpt   10  234621.340 ± 13126.338  ops/s
JmhCipherEncodingBenchmark.encode  AES/CBC/PKCS5Padding             1024     HEAP_DIRECT           JDK  thrpt   10  330040.433 ± 30038.779  ops/s
JmhCipherEncodingBenchmark.encode  AES/CBC/PKCS5Padding             1024     HEAP_DIRECT     CONSCRYPT  thrpt   10  233212.531 ± 13510.316  ops/s
JmhCipherEncodingBenchmark.encode  AES/CBC/PKCS5Padding             1024   DIRECT_DIRECT           JDK  thrpt   10  328395.853 ±  1587.912  ops/s
JmhCipherEncodingBenchmark.encode  AES/CBC/PKCS5Padding             1024   DIRECT_DIRECT     CONSCRYPT  thrpt   10  227399.272 ±  2417.525  ops/s
JmhCipherEncodingBenchmark.encode  AES/CBC/PKCS5Padding             1024     DIRECT_HEAP           JDK  thrpt   10  344565.644 ±  2133.463  ops/s
JmhCipherEncodingBenchmark.encode  AES/CBC/PKCS5Padding             1024     DIRECT_HEAP     CONSCRYPT  thrpt   10  233239.491 ±  4160.059  ops/s

private static final String ALGORITHM = "AES";
private static final int KEY_SIZE = 128;

public enum BufferType { ARRAY, HEAP, DIRECT }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: IIRC ther eis some code that behaves differently if the source and destination are heap vs non heap. For the byte buffer, you might consider having separate source and destination HEAP_DIRECT, HEAP_HEAP, DIRECT_HEAP, and DIRECT_DIRECT cases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would really blow up the benchmark matrix ... not sure it's worth it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at the CipherSpi.engineDoFinal, you can see they have 3 disctinct cases based on if the buffer is array backed or not. I think it would be worth the extra cases, since the existing implementation treats each one differently.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ... I've updated the benchmark results. Nothing too unexpected.

@kruton

kruton commented Sep 14, 2017 via email

Copy link
Copy Markdown
Contributor

@nmittler

Copy link
Copy Markdown
Contributor Author

@kruton

Something is funny here; the results don't line up with results from actual
usage

It should be noted that we're only calling the methods where there is both an input and output. Perhaps normal usage calls a different version of the methods?

What version of JDK are you using?

Using OpenJDK 8 (our internal version)

you should probably BlackHole the result.

done. Although I'm not seeing much of a difference in the results.

I'd explicitly set the ALGORITHM as well. I wonder if AES/CTR/NoPadding is the same?

What's the best way to do what you're suggesting?

@carl-mastrangelo carl-mastrangelo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No other comments from me.

Thanks for looking into this.

Supporting perf work for google#317
@nmittler

Copy link
Copy Markdown
Contributor Author

@flooey the AppVeyor build is broken when downloading cmake. Do we have to update the cmake version we're using? The surprising thing is that I had another PR that didn't have this problem.

import javax.crypto.KeyGenerator;

/**
* Benchmark for comparing cipher encoding performance.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should swap "encode" with "encrypt" throughout this class, the latter is orders of magnitude more commonly used when talking about what ciphers do.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@nmittler
nmittler merged commit 98afed6 into google:master Sep 18, 2017
nmittler pushed a commit that referenced this pull request Sep 25, 2017
Supporting perf work for #317
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants