Skip to content
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

Add SocketTransportOption to enable/disable WaitForData #19396

Merged
merged 6 commits into from
Mar 18, 2020

Conversation

tmds
Copy link
Member

@tmds tmds commented Feb 27, 2020

This allows to opt-out of the zero-byte read that is performed to reduce memory usage for idle connections.
This read has a measurable impact on TE JSON benchmark.

cc @halter73 @davidfowl @sebastienros @adamsitnik

Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

LGTM.

I confirm that making this optional can improve throughput and latency. Moreover, it's mandatory to make batching with Linux AIO work (it does not support 0 bytes reads)

Co-Authored-By: Adam Sitnik <adam.sitnik@gmail.com>
Copy link
Member

@Tratcher Tratcher left a comment

Choose a reason for hiding this comment

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

The ref assemblies need updating.
https://github.com/dotnet/aspnetcore/blob/master/docs/ReferenceAssemblies.md

What are the actual benchmark numbers?

@@ -16,6 +16,14 @@ public class SocketTransportOptions
/// </remarks>
public int IOQueueCount { get; set; } = Math.Min(Environment.ProcessorCount, 16);

/// <summary>
/// Wait until there is data available to allocate a buffer. Set this to true to reduce memory used for idle connections.
Copy link
Member

@Tratcher Tratcher Feb 27, 2020

Choose a reason for hiding this comment

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

Setting this to false can increase throughput at the cost of increased memory usage.

@tmds
Copy link
Member Author

tmds commented Feb 27, 2020

What are the actual benchmark numbers?

Can we run a benchmark using the Citrine infrastructure?

Should I make a change to some files to make the benchmark run with WaitForDataBeforeAllocatingBuffer=false?

@davidfowl
Copy link
Member

/azp run pr-benchmark

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@analogrelay analogrelay added this to the 5.0.0-preview2 milestone Feb 27, 2020
@analogrelay analogrelay added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Feb 27, 2020
@analogrelay
Copy link
Contributor

FYI, this will need API review (should be quick and easy though) as it adds a new public API.

@tmds
Copy link
Member Author

tmds commented Feb 27, 2020

I set the default to false to ensure that is what used by benchmarks.
I'll change it back to true before this is merged.

@adamsitnik
Copy link
Member

Benchmark results using Citrine:

JSON

WaitForData enabled:

--jobs "..\Benchmarks\benchmarks.json.json" --scenario "Json"
RequestsPerSecond:           840,803
Max CPU (%):                 100
WorkingSet (MB):             417
Avg. Latency (ms):           0.86
Startup (ms):                504
First Request (ms):          44.64
Latency (ms):                0.11
Total Requests:              12,696,202
Duration: (ms)               15,100
Socket Errors:               0
Bad Responses:               0
Build Time (ms):             3,001
Published Size (KB):         26,065
SDK:                         5.0.100-preview.2.20120.3
Runtime:                     5.0.0-preview.2.20125.16
ASP.NET Core:                5.0.0-preview.2.20126.7

WaitForData disabled:

--jobs "..\Benchmarks\benchmarks.json.json" --scenario "Json"
RequestsPerSecond:           861,744
Max CPU (%):                 100
WorkingSet (MB):             436
Avg. Latency (ms):           0.83
Startup (ms):                303
First Request (ms):          51.51
Latency (ms):                0.1
Total Requests:              13,012,363
Duration: (ms)               15,100
Socket Errors:               0
Bad Responses:               0
Build Time (ms):             4,001
Published Size (KB):         119,145
SDK:                         5.0.100-preview.2.20120.3
Runtime:                     5.0.0-preview.2.20125.16
ASP.NET Core:                5.0.0-preview.2.20126.7

For Plaintext there is no visible difference - both settings give me 86XYk RPS

@sebastienros
Copy link
Member

Did you set --self-contained on both runs, or use a custom build on each run to ensure that self-contained is implicitly set? If not then the displayed versions are misleading as the sdk's shared runtimes would prevail.

@adamsitnik
Copy link
Member

@sebastienros For the disabled case, I've compiled this dll locally and sent it using --output-file option. For the enabled, I've not provided any extra arguments

@sebastienros
Copy link
Member

In the case you don't provide any argument then you need to use --self-contained. I force it on all the CI runs, and it's also a default on the new driver. It might not change anything as we updated the sdk recently in the aspnet repos.

@tmds
Copy link
Member Author

tmds commented Mar 2, 2020

@sebastienros @halter73 where can we set WaitForDataBeforeAllocatingBuffer to false for the benchmarks?

@tmds
Copy link
Member Author

tmds commented Mar 18, 2020

@sebastienros @halter73 where can we set WaitForDataBeforeAllocatingBuffer to false for the benchmarks?

I guess it is in https://github.com/aspnet/Benchmarks once this change has rippled through.

@anurse @halter73 is this good to merge?

@halter73
Copy link
Member

Normally our API reviews are on Monday, but it got canceled this week. I'll try to get it through next Monday. Sorry for the delay.

@halter73 halter73 removed the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Mar 18, 2020
@halter73 halter73 added the api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews label Mar 18, 2020
@ghost
Copy link

ghost commented Mar 18, 2020

Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:

  • The PR contains changes to the reference-assembly that describe the API change. Or, you have included a snippet of reference-assembly-style code that illustrates the API change.
  • The PR describes the impact to users, both positive (useful new APIs) and negative (breaking changes).
  • Someone is assigned to "champion" this change in the meeting, and they understand the impact and design of the change.

@sebastienros
Copy link
Member

If the goal is only for benchmarking, you can do a local build that would use an ENV, or hard code the switch, and share the lib to use it instead.

@halter73 halter73 added api-approved API was approved in API review, it can be implemented and removed api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews labels Mar 18, 2020
@halter73
Copy link
Member

halter73 commented Mar 18, 2020

This got approved via email, so no need to wait 😄 Thanks!

@benaadams
Copy link
Member

As follow up to this call GetMemory() prior to calling FlushAsync() as otherwise there is contention on the Pipeline between reader and writer #22201

@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-approved API was approved in API review, it can be implemented area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants