aspnet / HttpAbstractions

[Archived] HTTP abstractions such as HttpRequest, HttpResponse, and HttpContext, as well as common web utilities. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
382 stars 194 forks source link

Adds PipeWriterAdapter #1065

Closed jkotalik closed 5 years ago

jkotalik commented 5 years ago

Half of https://github.com/aspnet/AspNetCore/issues/3966.

Few questions:

Tests

Performance

Current performance numbers:

Method Mean Error StdDev Median Op/s Gen 0/1k Op Gen 1/1k Op Gen 2/1k Op Allocated Memory/Op
WriteHelloWorld 6.280 us 0.1119 us 1.033 us 5.965 us 159,246.75 - - - 4.72 KB
WriteHelloWorldLargeNumberOfWrites 2,515.595 us 23.2819 us 222.184 us 2,512.710 us 397.52 - - - 4256.74 KB
WriteHelloWorldLargeWrite 22.644 us 0.3660 us 3.410 us 22.165 us 44,162.09 - - - 117.45 KB
WriteHelloWorldLargeNumberOfLargeWrites 16,120.442 us 70.6716 us 652.178 us 15,988.595 us 62.03 1000.0000 1000.0000 1000.0000 28904.27 KB
jkotalik commented 5 years ago

Better perf numbers.


BenchmarkDotNet=v0.10.13, OS=Windows 10.0.17134
Intel Xeon CPU E5-1650 v4 3.60GHz, 1 CPU, 12 logical cores and 6 physical cores
.NET Core SDK=2.2.100-preview2-009404
  [Host]     : .NET Core 2.2.0-preview2-26905-02 (CoreCLR 4.6.26905.03, CoreFX 4.6.26905.02), 64bit RyuJIT
  Job-MVJLBU : .NET Core 2.2.0-preview2-26905-02 (CoreCLR 4.6.26905.03, CoreFX 4.6.26905.02), 64bit RyuJIT

Runtime=Core  Server=True  Toolchain=.NET Core 2.2  
RunStrategy=Throughput  
Method Mean Error StdDev Op/s Allocated
WriteHelloWorld 149.7 ns 2.952 ns 4.327 ns 6,679,947.5 32 B
WriteHelloWorldLargeWrite 60,649.7 ns 812.198 ns 759.731 ns 16,488.1 100002 B
jkotalik commented 5 years ago

Perf numbers:

Using Memory and MemoryPool:

Method Mean Error StdDev Op/s Allocated
WriteHelloWorld 200.1 ns 3.846 ns 4.579 ns 4,998,578.2 32 B
WriteHelloWorldLargeWrite 61,825.2 ns 1,081.980 ns 959.147 ns 16,174.6 100003 B

Using byte[] and ArrayPool:

Method Mean Error StdDev Op/s Allocated
WriteHelloWorld 149.7 ns 2.952 ns 4.327 ns 6,679,947.5 32 B
WriteHelloWorldLargeWrite 60,649.7 ns 812.198 ns 759.731 ns 16,488.1 100002 B
davidfowl commented 5 years ago

https://github.com/aspnet/HttpAbstractions/pull/1065#issuecomment-438898235

These numbers don't sit well with me. I don't see how the allocated bytes can be that similar.

pakrym commented 5 years ago

What are the latest perf results?

jkotalik commented 5 years ago

Removed the MemoryStream and made an underlying noop stream instead.

Method Mean Error StdDev Op/s Allocated
WriteHelloWorld 179.2 ns 3.603 ns 6.404 ns 5,580,116.0 0 B
WriteHelloWorldLargeWrite 2,029.8 ns 40.592 ns 94.883 ns 492,654.3 0 B