-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Merge HTTP/2 and HTTP/3 request cookies on Kestrel #41591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge HTTP/2 and HTTP/3 request cookies on Kestrel #41591
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Just some comments and style cleanup now.
src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a performance run before merge
Hi all, following @halter73 suggestion, I unified the 2 implementations by re-implementing it in the |
Looking at the impl, they look like they're doing the smart thing and allocating a single string and copying the values into that new string. |
Command run: crank --config https://raw.githubusercontent.com/aspnet/Benchmarks/main/build/ci.profile.yml --config https://raw.githubusercontent.com/aspnet/Benchmarks/main/scenarios/grpc.benchmarks.yml --scenario grpcaspnetcoreserver-h2loadclient --profile intel-lin-app --profile intel-load-load --variable streams=70 --variable connections=1 --variable threads=1 --variable protocol=h2c --variable body=AAAAAAcKBVdvcmxk --variable path=/grpc.testing.BenchmarkService/UnaryCall --application.framework net7.0 --application.options.collectCounters true --application.aspNetCoreVersion 7.0.0-preview.5.22259.9 --application.runtimeVersion 7.0.0-preview.5.22259.4 --application.sdkVersion 7.0.100-preview.5.22258.1 Before my changes:
After my changes
I did some crank testing (results are above). So, there is definitely a slow down, so I will try the |
Sorry, messed up the rebase |
e377ffb
to
0b6b561
Compare
Good news! Looks like crank was just showing noise (see below). Does anybody have any other suggestions before I merge this? Running the Http2ConnectionBenchmark tests with my change
Before the change
System configBenchmarkDotNet=v0.13.0, OS=Windows 10.0.19043.1706 (21H1/May2021Update) Server=True Toolchain=.NET Core 7.0 RunStrategy=Throughput |
While doing these Http2ConnectionBenchmark tests, I found an NRE and discovered that the test was broken. So, Stephen helped me fix it. I just pushed the commits to avoid these issues from affecting other people. EDIT: Oh, and I added params to test cookies. |
src/Servers/Kestrel/perf/Microbenchmarks/Http2/Http2ConnectionBenchmarkBase.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/perf/Microbenchmarks/Http2/Http2ConnectionBenchmarkBase.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/perf/Microbenchmarks/Http2/Http2ConnectionBenchmarkBase.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/perf/Microbenchmarks/Http2/Http2ConnectionBenchmarkBase.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Chris Ross <[email protected]>
How is "Allocated" the same before and after the change in the 3-cookie case at 408 bytes per operation? After the change, it has to allocate the extra array and string per request, right? I don't expect the header value caching would work in this case. |
src/Servers/Kestrel/perf/Microbenchmarks/Http2/Http2ConnectionBenchmarkBase.cs
Outdated
Show resolved
Hide resolved
…citly convert to StringValues rather than via the cast
I agree, this is quite strange. Is there a chance that this statistic is being rounded? Or, perhaps it is not measuring all allocations? I am currently re-running the benchmark to double check the output. |
I did some testing and found some interesting results (see below). I think this boils down to inaccuracies in the test as, when I had the computer do a lot of other heavy work (install windows on virtualbox), seems like C# allocated more memory than during tests where the computer was not doing anything besides the benchmark. As you can see, in the test with my changes, the delta between 1 and 2 cookies is non-existent (and the value is 409B) but the delta between 2 and 3 cookies is huge. So, I think the reason is probably just the GC and other performance optimizations that I did not touch are creating noise. @halter73 what do you make of this? I ran a few other tests that were more fair but they seemed to have the same issue. I think these 2 just show the issue more nicely. Without my changes (while running a heavy load simultaneously)
With my changes (with computer not doing anything else)
|
src/Servers/Kestrel/perf/Microbenchmarks/Http2/Http2ConnectionBenchmarkBase.cs
Outdated
Show resolved
Hide resolved
d85deaa
to
28e767d
Compare
The allocation measurements are usually very consistent and accurate in my experience. I think the issue with the previous benchmark was calling the LINQ Append method wasn't mutating the StringValues, so all the tests were really identical. All of them were sending a single cookie. Once you updated the setup to assign the appended value back to
In most benchmarks, this should not happen. You'll see identical allocations per operation every single run no matter what's going on with the rest of the environment. This benchmarks is a little unique in that it is allocating some on background threads, so the environment causing a small variation in allocations per operation is explainable. The difference between 409 bytes and 411 bytes or even 409 bytes and 416 bytes isn't huge. The difference between 596 B and 641 B is more significant but completely expected since we're now allocating an additional array and string in this case. This is what I wanted to see before but wasn't because the We really should try to keep the environment as similar as possible between runs though. It makes apples-to-apples comparisons easier. |
Ohhh, ok then everything makes sense. I didn't know that |
I've learned the hard way to add a |
src/Servers/Kestrel/perf/Microbenchmarks/Http2/Http2ConnectionBenchmarkBase.cs
Outdated
Show resolved
Hide resolved
…BenchmarkBase.cs Co-authored-by: Stephen Halter <[email protected]>
Merge HTTP/2 and HTTP/3 request cookies on Kestrel
Description
Added a check to squash request cookies into a single cookie string delimited by
;
as per the HTTP/2 and HTTP/3 specs. I also added unit tests to make sure we don't regress this in the future.Fixes: #26461