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

feat(pubsub): add publisher flow control support #4292

Merged
merged 26 commits into from Sep 8, 2021

Conversation

hongalex
Copy link
Member

@hongalex hongalex commented Jun 22, 2021

This PR adds publisher flow control support, similar to the subscriber flow control. This is different in that the settings are part of topic.PublishSettings.FlowControlSettings. Similar to the subscriber flow control, these settings are locked-in on the first Publish call and subsequent modifications will not have any effect. In the FlowControlSettings.LimitExceededBehavior = FlowControlSignalError mode, oversized messages will result in an error from calling publishResult.Get, but oversized messages in other modes (Block/Ignore), will treat the message as the largest possible message size.

FlowControlSettings.MaxOutstandingBytes has a small overlap with the existing PublishSettings.BufferedByteLimit, which specifies an upper bound of bytes to keep in memory before throwing an error. This PR addresses this by adding a deprecation notice to BufferedByteLimit, but both will continue to be supported until a major version release. If MaxOutstandingBytes is passed in, it will override BufferedByteLimit.

The integration tests are largely based on the Java implementation. One difference between this and the Ruby/Python/Java implementations is that the semaphores enforce the queueing system. Specifically, large acquires will stay at head of line which avoids deadlocking.

Fixes #3210

@hongalex hongalex requested review from a team as code owners June 22, 2021 05:33
@product-auto-label product-auto-label bot added the api: pubsub Issues related to the Pub/Sub API. label Jun 22, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Jun 22, 2021
switch flowController to struct not pointer

fix more comments

fix more comments
pubsub/topic.go Outdated
FlowControlSettings: FlowControlSettings{
MaxOutstandingMessages: 1000,
MaxOutstandingBytes: 10 * MaxPublishRequestBytes,
LimitExceededBehavior: FlowControlBlock,
Copy link
Contributor

Choose a reason for hiding this comment

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

With BufferedByteLimit, what was the behavior by default? Was it to block? Either way, we should probably make sure that we don't introduce blocking due to MaxOutstandingMessages. That means we may either want to set MaxOutstandingMessages effectively to infinity or set the LimitExceededBehavior to Ignore by default.

Copy link
Member Author

@hongalex hongalex Jul 9, 2021

Choose a reason for hiding this comment

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

The default behavior of BufferedByteLimit is returning an error. Yeah, I think in retrospect, MaxOutstandingMessages should be disabled by default. Right now, I have some logic determining if these values have been set by the user, but that's probably too complicated.

Copy link
Contributor

Choose a reason for hiding this comment

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

So should we change this in that case?

Copy link
Member Author

Choose a reason for hiding this comment

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

What's the default for other languages? I defaulted to block because I thought that makes more sense, but consistency is probably more important.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok it seems like the default is ignore for Java, and I think I'll stick with this.

pubsub/topic.go Show resolved Hide resolved
pubsub/topic.go Outdated
FlowControlSettings: FlowControlSettings{
MaxOutstandingMessages: 1000,
MaxOutstandingBytes: 10 * MaxPublishRequestBytes,
LimitExceededBehavior: FlowControlBlock,
Copy link
Contributor

Choose a reason for hiding this comment

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

So should we change this in that case?

@hongalex hongalex changed the title feat(pubsub): add flow control support feat(pubsub): add publisher flow control support Sep 3, 2021
@hongalex hongalex merged commit bff24c3 into googleapis:master Sep 8, 2021
@hongalex hongalex deleted the pubsub-publish-fc branch September 8, 2021 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the Pub/Sub API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pubsub: add flow control support to publisher
2 participants