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

impl(bigtable): add MutateRowsLimiter #13079

Merged
merged 2 commits into from
Nov 9, 2023

Conversation

dbolduc
Copy link
Member

@dbolduc dbolduc commented Nov 8, 2023

Part of the work for #12959

Add a wrapper over RateLimiter which knows how to update the limiter's rate as decreed by the server.

I do not plan to expose any of initial_period, min_period, max_period, min_factor, or max_factor. But I want to abstract them so our tests do not break if we tweak the defaults.


Also the reviewer may notice that there is both a sync and async version of Table::BulkApply() (aka BigtableStub::MutateRows). But the MutateRowsLimiter can only sleep in band.

The plan is to complete throttling for the synchronous API then worry about how it looks with the async API after.


This change is Reviewable

@product-auto-label product-auto-label bot added the api: bigtable Issues related to the Bigtable API. label Nov 8, 2023
Copy link

codecov bot commented Nov 9, 2023

Codecov Report

Attention: 11 lines in your changes are missing coverage. Please review.

Comparison is base (df6677d) 92.99% compared to head (1c82250) 92.99%.
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13079      +/-   ##
==========================================
- Coverage   92.99%   92.99%   -0.01%     
==========================================
  Files        2131     2134       +3     
  Lines      185409   185559     +150     
==========================================
+ Hits       172423   172560     +137     
- Misses      12986    12999      +13     
Files Coverage Δ
...gle/cloud/bigtable/internal/mutate_rows_limiter.cc 100.00% <100.00%> (ø)
...ogle/cloud/bigtable/internal/mutate_rows_limiter.h 100.00% <100.00%> (ø)
...loud/bigtable/internal/mutate_rows_limiter_test.cc 90.67% <90.67%> (ø)

... and 5 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dbolduc dbolduc marked this pull request as ready for review November 9, 2023 00:44
@dbolduc dbolduc requested a review from a team as a code owner November 9, 2023 00:44
/// A Bigtable-specific wrapper over the more generic `RateLimiter`
class MutateRowsLimiter {
public:
virtual void acquire() = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

s/acquire/Acquire/?

Copy link
Member Author

Choose a reason for hiding this comment

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

Capitalized on the opportunity

std::chrono::duration<Rep1, Period1> initial_period,
std::chrono::duration<Rep2, Period2> min_period,
std::chrono::duration<Rep3, Period3> max_period, double min_factor,
double max_factor)
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

TIL... do I need to change the variable to max_factor_tm ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you do max_factor™? 😊

public:
virtual void acquire() = 0;
virtual void Update(
google::bigtable::v2::MutateRowsResponse const& response) = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this whole thing be divorced from MutateRows() by taking a google::bigtable::v2::RateLimitInfo instead, just making it bigtable_internal::RateLimiter? RateLimitInfo might be used in others calls in the future. (I guess the mutate-rows Update() call would become conditional.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Should this whole thing be divorced from MutateRows()... RateLimitInfo might be used in others calls in the future.

This is a good question. RateLimitInfo is defined inside MutateRowsResponse though: https://github.com/googleapis/googleapis/blob/92a6b0fc959905f68e567dd60f766167772594bd/google/bigtable/v2/bigtable.proto#L513

The Bigtable team mentioned that the ReadRows API could be worthy of throttling. But I don't think they plan to add that. This feature is really aimed at heavy write jobs.

Moreover, the flags to enable things are called mutate_rows_rate_limit[0-9]*

https://github.com/googleapis/googleapis/blob/92a6b0fc959905f68e567dd60f766167772594bd/google/bigtable/v2/feature_flags.proto#L40-L48

(I guess the mutate-rows Update() call would become conditional.)

Yeah. This was my main motivation, although it's not a big deal.

Copy link
Contributor

Choose a reason for hiding this comment

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

RateLimitInfo is defined inside MutateRowsResponse though

That's not what I see, hence the suggestion.

Moreover, the flags to enable things are called mutate_rows_rate_limit[0-9]*

I don't think that's indicative of anything other than they are the flags for MutateRows(). If RateLimitInfo was used elsewhere, presumably that might get its own flags.

(I guess the mutate-rows Update() call would become conditional.)

Yeah. This was my main motivation, although it's not a big deal.

I agree that it's not a big deal, and therefore not a good main motivation. That is, it seems a shame to specialize the interface for that.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's not what I see, hence the suggestion.

D'oh. I can't read.

Still this class is internal. We can easily change it later.

Copy link
Contributor

Choose a reason for hiding this comment

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

We can easily change it later.

True enough, although I think we suffer a little from we-can-change-it-later-itis.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't disagree... but observation:

It will take as much effort to change it now as it will to change it later... and we might not need to change it later.

Copy link
Member Author

Choose a reason for hiding this comment

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

We run into trouble when we do this a bunch, and then we need to change N of them at the same time. 🫨

public:
virtual void acquire() = 0;
virtual void Update(
google::bigtable::v2::MutateRowsResponse const& response) = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

We can easily change it later.

True enough, although I think we suffer a little from we-can-change-it-later-itis.

@dbolduc dbolduc merged commit 5561ec4 into googleapis:main Nov 9, 2023
@dbolduc dbolduc deleted the bigtable-mutate-rows-rate-limiter branch November 9, 2023 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigtable Issues related to the Bigtable API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants