Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Improve the performance of connection filters - #1021

Merged
halter73 merged 3 commits into
devfrom
halter73/better-filters
Aug 3, 2016
Merged

halter73 merged 3 commits into
devfrom
halter73/better-filters

Conversation

@halter73

Copy link
Copy Markdown
Member

Fixes #768

@halter73

Copy link
Copy Markdown
Member Author
> dotnet run -- -n plaintext -s http://adx-3u-perfsvr:5001 -c http://adx-3u-svr02:5002 -o  "KestrelHttpServer@halter73/noop-filter-old" -o "Benchmarks@halter73/noop-filter"
Project Repository (.NETStandard,Version=v1.0) was previously compiled. Skipping compilation.
Project Benchmarks.ClientJob (.NETStandard,Version=v1.0) was previously compiled. Skipping compilation.
Project Benchmarks.ServerJob (.NETStandard,Version=v1.0) was previously compiled. Skipping compilation.
Project BenchmarksDriver (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
[05:01:53.027] Starting scenario Plaintext on benchmark server...
[05:02:19.695] Warmup
[05:02:19.704] Starting scenario Plaintext on benchmark client...
[05:02:30.772] Scenario Plaintext completed on benchmark client
[05:02:30.772] RPS: 890318.48
[05:02:30.772] Stopping scenario Plaintext on benchmark client...
[05:02:30.774] Benchmark
[05:02:30.774] Starting scenario Plaintext on benchmark client...
[05:02:41.812] Scenario Plaintext completed on benchmark client
[05:02:41.812] RPS: 927072.76
[05:02:41.812] Stopping scenario Plaintext on benchmark client...
[05:02:41.814] Stopping scenario Plaintext on benchmark server...
> dotnet run -- -n plaintext -s http://adx-3u-perfsvr:5001 -c http://adx-3u-svr02:5002 -o  "KestrelHttpServer@halter73/noop-filter" -o "Benchmarks@halter73/noop-filter"
Project Repository (.NETStandard,Version=v1.0) was previously compiled. Skipping compilation.
Project Benchmarks.ClientJob (.NETStandard,Version=v1.0) was previously compiled. Skipping compilation.
Project Benchmarks.ServerJob (.NETStandard,Version=v1.0) was previously compiled. Skipping compilation.
Project BenchmarksDriver (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
[05:04:05.286] Starting scenario Plaintext on benchmark server...
[05:04:26.974] Warmup
[05:04:26.987] Starting scenario Plaintext on benchmark client...
[05:04:38.139] Scenario Plaintext completed on benchmark client
[05:04:38.139] RPS: 915294.73
[05:04:38.139] Stopping scenario Plaintext on benchmark client...
[05:04:38.141] Benchmark
[05:04:38.141] Starting scenario Plaintext on benchmark client...
[05:04:49.178] Scenario Plaintext completed on benchmark client
[05:04:49.178] RPS: 977263.77
[05:04:49.178] Stopping scenario Plaintext on benchmark client...
[05:04:49.180] Stopping scenario Plaintext on benchmark server...

Not a super drastic improvement. It looks like wrapping SocketOutput is having a much larger impact on perf than wrapping SocketInput. I haven't yet come up with a great way to improve StreamSocketOutput yet.

{
public static class SocketInputExtensions
{
public static void IncomingData(this SocketInput input, byte[] buffer, int offset, int count)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So lazy...

@davidfowl

Copy link
Copy Markdown
Member

:shipit:

@mikeharder

mikeharder commented Jul 30, 2016 •

Copy link
Copy Markdown
Contributor

@halter73: Please wait until I've added this scenario to Benchmarks (aspnet/Benchmarks#109) so we can see the perf improvement in our automated results. PR is ready, just needs a :shipit:.

@mikeharder

mikeharder commented Aug 1, 2016 •

Copy link
Copy Markdown
Contributor

It's hard to tell since the results have a lot of variance, but I'm not seeing a clear improvement from this change:

Before  After
------  -----
876     935
964     847
860     942
919     891
855     910
878     862

Mean(Before): 892
Mean(After):  896

Before: dotnet run -- -n plaintext --connectionFilter Benchmarks.PassthroughConnectionFilter -o KestrelHttpServer@2244f19
After:  dotnet run -- -n plaintext --connectionFilter Benchmarks.PassthroughConnectionFilter -o KestrelHttpServer@halter73/better-filters

@benaadams

benaadams commented Aug 1, 2016 •

Copy link
Copy Markdown
Contributor

Does it fix the ssl async-over-sync on full framework as suggested?

If so I'd take it regardless... as it ties capacity to min threadpool threads

@mikeharder

Copy link
Copy Markdown
Contributor

@benaadams: How would one test the "ssl async-over-sync"? Just benchmark plaintext over HTTPS using full framework rather than core?

@benaadams

benaadams commented Aug 2, 2016 •

Copy link
Copy Markdown
Contributor

@mikeharder try plaintext over HTTPS on full framework, but switch the Invoke for

Redacted, now tested

/// </summary>
public void Start()
{
Reset();

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.

Why did you move this here? It was bad in the ctor so I like that you moved it here, but just wondering if there were other reasons.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Mostly so we don't have to call it in Connection.ApplyConnectionFilter().

@cesarblum

Copy link
Copy Markdown
Contributor

lgtm 🚢 (but wait for @mikeharder 😄 )

@davidfowl

Copy link
Copy Markdown
Member

Regardless of the performance improvement, the code is better and fixes some problems (async await FTW)

@mikeharder

Copy link
Copy Markdown
Contributor

I'm not opposed to the change, just wanted to make it clear I don't see a perf benefit in Plaintext. I'll test JSON as well.

@benaadams

Copy link
Copy Markdown
Contributor

Not seeing any difference with https on full framework with the above middleware (pre and post)?

@mikeharder

Copy link
Copy Markdown
Contributor

@benaadams Haven't tested full framework yet, will try today.

@halter73

halter73 commented Aug 3, 2016 •

Copy link
Copy Markdown
Member Author

The benchmarks show that SSL on full framework is much better (read less broken) after this change. The BenchmarksDriver doesn't support full framework atm, so I ran some tests on my dev machine. This was enough to show a big difference. Basically after the change, Kestrel doesn't fall over with a bunch of HTTPS connections on full framework:

[shalter@shalter-arch wrk]$ ./wrk -c 64 -t 8 -d 10 -s pipeline.lua https://winhost:5001 -- 16
Running 10s test @ https://winhost:5001
  8 threads and 64 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     0.00us    0.00us   0.00us    -nan%
    Req/Sec     0.00      0.00     0.00      -nan%
  0 requests in 10.10s, 0.00B read
Requests/sec:      0.00
Transfer/sec:       0.00B
[shalter@shalter-arch wrk]$ ./wrk -c 16 -t 8 -d 10 -s pipeline.lua https://winhost:5001 -- 16
Running 10s test @ https://winhost:5001
  8 threads and 16 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    13.31ms   26.70ms 386.70ms   92.22%
    Req/Sec     2.03k   551.20     4.10k    70.57%
  128749 requests in 10.07s, 16.33MB read
Requests/sec:  12782.50
Transfer/sec:      1.62MB
[shalter@shalter-arch wrk]$ ./wrk -c 64 -t 8 -d 10 -s pipeline.lua https://winhost:5001 -- 16
Running 10s test @ https://winhost:5001
  8 threads and 64 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     0.00us    0.00us   0.00us    -nan%
    Req/Sec     0.00      0.00     0.00      -nan%
  0 requests in 10.10s, 0.00B read
Requests/sec:      0.00
Transfer/sec:       0.00B

halter73/better-filters below

[shalter@shalter-arch wrk]$ ./wrk -c 64 -t 8 -d 10 -s pipeline.lua https://winhost:5001 -- 16
Running 10s test @ https://winhost:5001
  8 threads and 64 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    33.01ms   39.10ms 469.31ms   92.12%
    Req/Sec     2.76k   547.24     6.31k    79.97%
  215326 requests in 10.05s, 27.31MB read
Requests/sec:  21417.80
Transfer/sec:      2.72MB
[shalter@shalter-arch wrk]$ ./wrk -c 256 -t 8 -d 10 -s pipeline.lua https://winhost:5001 -- 16
Running 10s test @ https://winhost:5001
  8 threads and 256 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    99.78ms   60.76ms   1.11s    47.64%
    Req/Sec     2.55k   828.66     5.83k    74.93%
  197129 requests in 10.08s, 25.00MB read
  Socket errors: connect 0, read 0, write 0, timeout 12
Requests/sec:  19549.64
Transfer/sec:      2.48MB
[shalter@shalter-arch wrk]$ ./wrk -c 1024 -t 8 -d 10 -s pipeline.lua https://winhost:5001 -- 16
Running 10s test @ https://winhost:5001
  8 threads and 1024 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   387.93ms  233.96ms   1.98s    28.72%
    Req/Sec     2.24k     1.58k    7.27k    69.36%
  150779 requests in 10.08s, 19.12MB read
  Socket errors: connect 11, read 0, write 0, timeout 12
Requests/sec:  14956.46
Transfer/sec:      1.90MB

- Add Begin/End Write methods to FrameResponseStream
- Fix state check of Begin/End Read methods in FrameRequestStream
- Buffer connection filter input less by using ProducingStart/Complete
- Simplify FilteredStreamAdapter
@halter73
halter73 force-pushed the halter73/better-filters branch from c7a2eda to 9727a4d Compare August 3, 2016 23:46
@benaadams

benaadams commented Aug 3, 2016 •

Copy link
Copy Markdown
Contributor

I thought it might make a difference in a big way.

Current, full framework workaround is to set the environment variable

set COMPlus_ThreadPool_ForceMinWorkerThreads=500

Though that isn't a very good solution; have removed the example code.

🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants