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 example for h2 keep alive #2203

Merged
merged 6 commits into from
May 6, 2022
Merged

Conversation

Scottmitch
Copy link
Member

Motivation:
Add an example demonstrating how the HTTP/2 transport keep alive feature can be used for gRPC clients and servers.

@Scottmitch
Copy link
Member Author

This PR depends upon #2204

try (BlockingStreamingGreeterClient client = GrpcClients.forAddress("localhost", 8080)
.initializeHttp(httpBuilder -> httpBuilder.protocols(
// 4 second timeout is typically much shorter than necessary, but demonstrates PING frame traffic.
// Using the default value is suitable in most scenarios, but if you want to customize the value
Copy link
Contributor

Choose a reason for hiding this comment

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

The improved comments will really help.

h2().keepAlivePolicy(new KeepAlivePolicyBuilder().build())

is needed to configure the default. Perhaps a constant defaultKeepAlive() or useDefaults() for configuring the default.

Copy link
Member Author

Choose a reason for hiding this comment

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

Since we expose the builder type I don't think the static factory helper methods provide much value and add duplication.

Copy link
Contributor

Choose a reason for hiding this comment

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

True, but I had to spend a couple minutes figuring out that there was no default object and how to make one (the Builder docs don't mention that default values will be use if not supplied). Oddly, we provide a constant for disabling keep alive which is the default behaviour (not clear why you would ever needed it except to be explicit). Some mechanism or doc suggestion assistance of how to get a default keep alive policy would help IMO.

Copy link
Member Author

Choose a reason for hiding this comment

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

Lets consider this for a followup PR to make any changes more explicit. I would prefer to remove the disabled() API and just use null if we need a default (one less API, no special "by reference" comparison required).

Copy link
Contributor

Choose a reason for hiding this comment

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

All are fine approaches, whatever ensures users don't have to read the source to figure out how to get the default.

Motivation:
Add an example demonstrating how the HTTP/2 transport keep alive feature can be used for gRPC clients and servers.
@Scottmitch Scottmitch merged commit 7cd1c78 into apple:main May 6, 2022
@Scottmitch Scottmitch deleted the keepalive_example branch May 6, 2022 22:19
Copy link
Member

@idelpivnitskiy idelpivnitskiy left a comment

Choose a reason for hiding this comment

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

Late LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants