GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: add flow control for message publishing by plamut · Pull Request #96 · googleapis/python-pubsub

This repository was archived by the owner on Oct 13, 2026. It is now read-only.

Conversation

@plamut

@plamut plamut commented May 7, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Closes #16.
Closes #72.

This PR adds flow control settings to publisher client, similar to what was added to the Java client recently.

The PR does not interfere with existing publish logic (sequencers, ordering keys, batching...). Instead, it acts like a valve placed in front of the publish pipeline, and taking the configured action if it detects excessive message flow.

Things left to do / discuss

  • A system test for this? Although not sure how feasible would it be, as we would have to publish massive amounts of data on fast connection to have a chance of triggering the flow control error...
  • If the desired behavior is BLOCK, should blocking also support timeouts? However, every publish future gets resolved sooner or later be done (even if due to an error/timeout), and will release the corresponding message from the flow controller then.
  • Unlike Java, the FlowControl settings are placed under PublisherOptions, and not BatchSettings. They fit there much more naturally IMO, but I can change this.
  • What should be the default FlowControl values (the thresholds, specifically)? I set the message count and byte size to 10x the defaults in BatchSettings, would that be fine for most users?
  • Documenting the new feature more extensively than docstring updates in this PR? Can in principle also be done in a separate PR.

PR checklist

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
plamut added 2 commits May 7, 2020 10:36
@plamut
feat: add publish flow control settings
e6d27b1
@plamut
Add flow control logic to publisher client
7e78317
@plamut
plamut requested review from kamalaboulhosn and pradn May 7, 2020 13:52
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label May 7, 2020
This was referenced May 7, 2020
PubSub Publisher 504 Deadline Exceeded when sending bulk messages #72
Closed
Pubsub: Consider a blocking publisher to prevent OOMing #16
Closed
kamalaboulhosn
kamalaboulhosn suggested changes May 7, 2020
View reviewed changes
Comment thread google/cloud/pubsub_v1/publisher/client.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/pubsub_v1/publisher/flow_controller.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

pradn
pradn reviewed May 8, 2020
View reviewed changes
Comment thread google/cloud/pubsub_v1/publisher/flow_controller.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/pubsub_v1/publisher/client.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@plamut plamut added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label May 8, 2020
@plamut
plamut force-pushed the iss-72 branch from b4aba10 to f729fdf Compare May 11, 2020 14:18
@plamut

plamut commented May 11, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

I added support for multithreaded add(), including the logic to prevent threads adding large messages from starving.

Things left:

  • Improve debug log messages (include info on the current flow controller capacity)
  • ERROR path: raise overflow errors through the publish future, not directly.
  • Add a smoke system test - probably using the ERROR path, as triggering a timeout would be too difficult on reasonably fast connection (we don't want to DOS the infrastructure, after all).
    Added a unit test covering the same, just without hitting the backend (doesn't matter for the flow controller, as this is past it in the pipeline).
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

plamut
plamut commented May 11, 2020
View reviewed changes
Comment thread google/cloud/pubsub_v1/publisher/flow_controller.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

plamut added 2 commits May 12, 2020 08:29
@plamut
Add flow control support for multiple add() threads
2fe776f
@plamut
Raise publish flow control errors through futures
ac9af40
@plamut
plamut force-pushed the iss-72 branch from f729fdf to ac9af40 Compare May 12, 2020 07:54
@plamut
Include load info in debug log messages
6d79cba
@plamut
plamut marked this pull request as ready for review May 12, 2020 09:06
@plamut
plamut requested review from kamalaboulhosn and pradn May 12, 2020 09:06
plamut
plamut commented May 12, 2020
View reviewed changes
Comment thread tests/unit/pubsub_v1/publisher/test_flow_controller.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

plamut added 2 commits May 12, 2020 13:13
@plamut
Remove incorrect comment in a test
64fd9a1
@plamut
Merge branch 'master' into iss-72
5036c86
@plamut plamut mentioned this pull request May 13, 2020
docs: Changed Python 2 EOL notice from future to present #98
Closed
@plamut
Merge branch 'master' into iss-72
3ea8df0
kamalaboulhosn
kamalaboulhosn approved these changes May 21, 2020
View reviewed changes
Comment thread google/cloud/pubsub_v1/publisher/client.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@plamut
Remove comment about an error not directly raised
b7a40f8
@plamut

plamut commented May 28, 2020

Copy link
Copy Markdown
Contributor Author

@pradn Do you have anything to add here, or are we good to merge?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

pradn
pradn suggested changes May 28, 2020
View reviewed changes
Comment thread google/cloud/pubsub_v1/publisher/flow_controller.py Outdated
error_msg = "Flow control limits too low for the message - {}.".format(
load_info
)
raise exceptions.PermanentlyBlockedError(error_msg)

@pradn pradn May 28, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

"WouldPermanentlyBlockError" makes more sense, because it's not already permanently blocked.

Even better, I think we can simply omit the details about blocking and say something more generic: FlowControlMessageTooLargeError

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@plamut plamut May 28, 2020

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Makes sense, I will rename the exception.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@plamut plamut May 29, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I eventually opted for the generic FlowControlLimitError for a few reasons:

  • FlowControlMessageTooLargeError could be confusing, as there already exists a similarly named MessageTooLargeError for the messages that would exceed the limits on the backend.
  • A message could block permanently for reasons other than its size, e.g. if flow control's max messages is set to 0 or some other non-sensible value. Mentioning the size would actually be misleading in such case, but a generic FlowControlLimitsError would semantically still be correct.
  • One less exception type to keep track of.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google/cloud/pubsub_v1/publisher/flow_controller.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/pubsub_v1/publisher/flow_controller.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@plamut
Remove redundant check for reservation exsistence
6bcd9ce
plamut added 2 commits May 29, 2020 11:32
@plamut
Change exception for publishing too large a message
3689228
@plamut
Add internal sanity check for byte reservations
a0c771a
pradn
pradn suggested changes May 29, 2020
View reviewed changes
Comment thread google/cloud/pubsub_v1/publisher/flow_controller.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/pubsub_v1/publisher/flow_controller.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@plamut
Reword the docstring on flow control limits error
f8d6c60
@plamut

plamut commented Jun 2, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

@pradn If there's nothing else left, please just give an approval to unblock the merge, thanks! :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

pradn
pradn approved these changes Jun 2, 2020
View reviewed changes
@plamut
plamut merged commit 06085c4 into googleapis:master Jun 2, 2020
@plamut
plamut deleted the iss-72 branch June 2, 2020 19:09
gcf-merge-on-green Bot pushed a commit that referenced this pull request Jun 9, 2020
@release-please
chore: release 1.6.0 (#117)
60fe71a
## [1.6.0](https://www.github.com/googleapis/python-pubsub/compare/v1.5.0...v1.6.0) (2020-06-09)

### Features

* Add flow control for message publishing ([#96](https://www.github.com/googleapis/python-pubsub/issues/96)) ([06085c4](https://www.github.com/googleapis/python-pubsub/commit/06085c4083b9dccdd50383257799904510bbf3a0))


### Bug Fixes

* Fix PubSub incompatibility with api-core 1.17.0+ ([#103](https://www.github.com/googleapis/python-pubsub/issues/103)) ([c02060f](https://www.github.com/googleapis/python-pubsub/commit/c02060fbbe6e2ca4664bee08d2de10665d41dc0b))


### Documentation
- Clarify that Schedulers shouldn't be used with multiple SubscriberClients ([#100](#100)) ([cf9e87c](cf9e87c))
- Fix update subscription/snapshot/topic samples ([#113](#113)) ([e62c38b](e62c38b))


### Internal / Testing Changes
- Re-generated service implementaton using synth: removed experimental notes from the RetryPolicy and filtering features in anticipation of GA, added DetachSubscription (experimental) ([#114](#114)) ([0132a46](0132a46))
- Incorporate will_accept() checks into publish() ([#108](#108)) ([6c7677e](6c7677e))
@hongalex hongalex mentioned this pull request Nov 14, 2020
pubsub: add flow control support to publisher googleapis/google-cloud-go#3210
Closed
@quartzmo quartzmo mentioned this pull request May 14, 2021
feat(pubsub): Add Publisher Flow Control googleapis/google-cloud-ruby#11383
Merged
@release-please release-please Bot mentioned this pull request Aug 11, 2022
chore(main): release 2.13.6 #761
Merged
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

2 more reviewers
@pradn pradn pradn approved these changes
@kamalaboulhosn kamalaboulhosn kamalaboulhosn approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cla: yes This human has signed the Contributor License Agreement. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

PubSub Publisher 504 Deadline Exceeded when sending bulk messages Pubsub: Consider a blocking publisher to prevent OOMing

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@plamut @pradn @kamalaboulhosn @googlebot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.