Skip to content

grpc: introduce new DialOption and ServerOption to configure initial window size without disabling BDP estimation. #8283

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

Merged
merged 42 commits into from
Jun 2, 2025

Conversation

vinothkumarr227
Copy link
Contributor

@vinothkumarr227 vinothkumarr227 commented May 2, 2025

Part of: #7923

RELEASE NOTES:

  • grpc: introduce new DialOptions and ServerOptions (WithStaticStreamWindowSize, WithStaticConnWindowSize, StaticStreamWindowSize, StaticConnWindowSize) that force fixed window sizes for all HTTP/2 connections. By default, gRPC uses dynamic sizing of these windows based upon a BDP estimation algorithm. The existing options (WithInitialWindowSize, etc) also disable BDP estimation, but this behavior will be changed in a following release.

Copy link

codecov bot commented May 2, 2025

Codecov Report

Attention: Patch coverage is 33.33333% with 18 lines in your changes missing coverage. Please review.

Project coverage is 82.17%. Comparing base (32e57de) to head (6d355fb).
Report is 11 commits behind head on master.

Files with missing lines Patch % Lines
dialoptions.go 25.00% 9 Missing ⚠️
server.go 30.76% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8283      +/-   ##
==========================================
- Coverage   82.35%   82.17%   -0.18%     
==========================================
  Files         419      419              
  Lines       42034    42073      +39     
==========================================
- Hits        34615    34572      -43     
- Misses       5968     6029      +61     
- Partials     1451     1472      +21     
Files with missing lines Coverage Δ
internal/transport/http2_client.go 92.64% <100.00%> (+0.48%) ⬆️
internal/transport/http2_server.go 91.59% <100.00%> (+0.50%) ⬆️
internal/transport/transport.go 91.56% <ø> (ø)
dialoptions.go 87.40% <25.00%> (-3.40%) ⬇️
server.go 81.45% <30.76%> (-1.46%) ⬇️

... and 27 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@arjan-bal
Copy link
Contributor

Is this the same as #8279? Should the original PR be closed?

@vinothkumarr227
Copy link
Contributor Author

Is this the same as #8279? Should the original PR be closed?
Yeah, you can close this PR: #8279.

@vinothkumarr227
Copy link
Contributor Author

@dfawley Can you please review this when you get a chance?

@purnesh42H purnesh42H requested a review from dfawley May 9, 2025 11:17
@purnesh42H purnesh42H assigned dfawley and unassigned vinothkumarr227 May 9, 2025
Copy link
Member

@dfawley dfawley left a comment

Choose a reason for hiding this comment

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

This PR should implement just (1) from #7923.

It should not mark the old options as deprecated.

  • Please improve the PR title ("the size"?)
  • Please write release notes

Thanks!

@dfawley dfawley assigned vinothkumarr227 and unassigned dfawley May 9, 2025
@vinothkumarr227 vinothkumarr227 changed the title Add new Dial/ServerOptions to set the size grpc: add DialOption and ServerOption to configure initial window size without disabling BDP estimation May 12, 2025
@vinothkumarr227 vinothkumarr227 requested a review from dfawley May 13, 2025 06:25
@purnesh42H purnesh42H changed the title grpc: add DialOption and ServerOption to configure initial window size without disabling BDP estimation grpc: introduce new DialOption and ServerOption to configure initial window size without disabling BDP estimation. May 13, 2025
@purnesh42H purnesh42H added Type: Feature New features or improvements in behavior Area: RPC Features Includes Compression, Encoding, Attributes/Metadata, Interceptors. and removed Status: Requires Reporter Clarification labels May 13, 2025
@purnesh42H purnesh42H added this to the 1.73 Release milestone May 13, 2025
@vinothkumarr227
Copy link
Contributor Author

vinothkumarr227 commented May 13, 2025

This PR should implement just (1) from #7923.

It should not mark the old options as deprecated.

  • Please improve the PR title ("the size"?)
  • Please write release notes

Thanks!

@dfawley Could you please re-review this PR? I've made the changes also updated the PR title and added the release notes as suggested.

Copy link
Member

@dfawley dfawley left a comment

Choose a reason for hiding this comment

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

And please update the first comment and release notes in this PR accordingly.

Comment on lines 151 to 153
// TestJoinDialOption_StaticConnAndStreamWindowSizes verifies that both static
// stream and connection window sizes set via joined dial options are correctly
// applied.
Copy link
Member

Choose a reason for hiding this comment

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

Is there some special interaction here with these and Join? I don't think there's much need for this test, since it just tests Join, but we already have a test for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

dialoptions.go Outdated
Comment on lines 228 to 229
// WithStaticStreamWindowSize returns a DialOption to set the static initial
// stream window size.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// WithStaticStreamWindowSize returns a DialOption to set the static initial
// stream window size.
// WithStaticStreamWindowSize returns a DialOption which sets the initial
// stream window size to the value provided and prevents dynamic flow control
// from adjusting it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

dialoptions.go Outdated
Comment on lines 230 to 232
// WithStaticStreamWindowSize returns a DialOption which sets the initial
// stream window size to the value provided and prevents dynamic flow control
// from adjusting it
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// WithStaticStreamWindowSize returns a DialOption which sets the initial
// stream window size to the value provided and prevents dynamic flow control
// from adjusting it
// WithStaticStreamWindowSize returns a DialOption which sets the initial
// stream window size to the value provided and disables dynamic flow control.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

dialoptions.go Outdated
Comment on lines 240 to 242
// WithStaticConnWindowSize returns a DialOption which sets the initial
// connection window size to the value provided and prevents dynamic flow control
// from adjusting it
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// WithStaticConnWindowSize returns a DialOption which sets the initial
// connection window size to the value provided and prevents dynamic flow control
// from adjusting it
// WithStaticConnWindowSize returns a DialOption which sets the initial
// connection window size to the value provided and disables dynamic flow control.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 508 to 509
// BdpEstimationEnabled controls whether dynamic window sizing is enabled.
BdpEstimationEnabled bool
Copy link
Member

Choose a reason for hiding this comment

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

If you are adding this boolean, then you should leave the names of the other fields as Initial. This boolean will now determine whether they are initial or static. I was picturing ending up with four variables, two for initial and two for static, but this way is probably better - just needs better naming.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

Choose a reason for hiding this comment

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

Please address first part of this comment and change the variables back form static to initial

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done the changes

server.go Outdated
Comment on lines 296 to 298
// StaticStreamWindowSize returns a ServerOption to set the initial stream
// window size to the value provided and prevents dynamic flow control
// from adjusting it.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// StaticStreamWindowSize returns a ServerOption to set the initial stream
// window size to the value provided and prevents dynamic flow control
// from adjusting it.
// StaticStreamWindowSize returns a ServerOption to set the initial stream
// window size to the value provided and disables dynamic flow control.
// The lower bound for window size is 64K and any value smaller than that
// will be ignored.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

server.go Outdated
Comment on lines 306 to 308
// StaticConnWindowSize returns a ServerOption to set the initial connection
// window size to the value provided and prevents dynamic flow control
// from adjusting it.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// StaticConnWindowSize returns a ServerOption to set the initial connection
// window size to the value provided and prevents dynamic flow control
// from adjusting it.
// StaticConnWindowSize returns a ServerOption to set the initial connection
// window size to the value provided and disables dynamic flow control.
// The lower bound for window size is 64K and any value smaller than that
// will be ignored.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@dfawley dfawley removed their assignment May 27, 2025
@vinothkumarr227 vinothkumarr227 requested a review from dfawley May 28, 2025 12:03
server.go Outdated
Comment on lines 173 to 174
staticWindowSize int32
staticConnWindowSize int32
Copy link
Member

Choose a reason for hiding this comment

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

Please remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 313 to 317
icwz := int32(initialWindowSize)
if opts.InitialConnWindowSize >= defaultWindowSize {
icwz = opts.InitialConnWindowSize
dynamicWindow = false
dynamicWindow = opts.UseDynamicWindowSizing
}
Copy link
Member

Choose a reason for hiding this comment

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

This logic is wrong now.

dynamicWindow can be removed, and opts.Use... can be used in its place. Same on the server.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I've updated the code accordingly

@dfawley dfawley assigned vinothkumarr227 and unassigned dfawley May 29, 2025
@vinothkumarr227 vinothkumarr227 requested a review from dfawley May 29, 2025 17:36
@@ -309,11 +309,11 @@ func NewHTTP2Client(connectCtx, ctx context.Context, addr resolver.Address, opts
scheme = "https"
}
}
dynamicWindow := true
opts.UseDynamicWindowSizing = true
Copy link
Member

Choose a reason for hiding this comment

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

Don't alter the setting here. It's already set from the user. Setting this undoes it.

Did you run into problems with tests? Those tests would need to set this option accordingly. Also the below suggestion might help some, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I was facing issues in the tests. I've now removed the setting and updated the tests to set the option explicitly as needed.

MaxHeaderListSize *uint32
HeaderTableSize *uint32
BufferPool mem.BufferPool
UseDynamicWindowSizing bool
Copy link
Member

Choose a reason for hiding this comment

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

The problem with this name is the default behavior (disabled) is not our current default (enabled).

So let's rename these to StaticWindowSize please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback!, I've renamed it to StaticWindowSize for clarity and to better reflect the actual default behavior. The code has been updated accordingly.

@vinothkumarr227 vinothkumarr227 requested a review from dfawley June 2, 2025 08:25
dialoptions.go Outdated
@@ -213,6 +213,7 @@ func WithReadBufferSize(s int) DialOption {
func WithInitialWindowSize(s int32) DialOption {
return newFuncDialOption(func(o *dialOptions) {
o.copts.InitialWindowSize = s
o.copts.StaticWindowSize = false
Copy link
Member

Choose a reason for hiding this comment

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

These (4) need to be true or you will be changing behavior, which is not what we want yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the clarification!, I've updated the code so that all four values are set to true

icwz := int32(initialWindowSize)
if opts.InitialConnWindowSize >= defaultWindowSize {
icwz = opts.InitialConnWindowSize
dynamicWindow = false
opts.StaticWindowSize = false
Copy link
Member

Choose a reason for hiding this comment

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

Don't alter the setting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}
if dynamicWindow {
if opts.StaticWindowSize {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if opts.StaticWindowSize {
if !opts.StaticWindowSize {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@vinothkumarr227 vinothkumarr227 requested a review from dfawley June 2, 2025 18:24
Copy link
Member

@dfawley dfawley left a comment

Choose a reason for hiding this comment

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

Thank you!

@dfawley dfawley merged commit 9b7bd34 into grpc:master Jun 2, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: RPC Features Includes Compression, Encoding, Attributes/Metadata, Interceptors. Type: Feature New features or improvements in behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants