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: pull query bandwidth based throttling #7738

Merged
merged 15 commits into from
Jul 1, 2021

Conversation

cprasad1
Copy link
Member

@cprasad1 cprasad1 commented Jun 28, 2021

Description

Limits the amount of bandwidth used by Pull Queries using a Sliding Window Log. The limit (in MB per hour) can be set using the ksql.query.pull.max.hourly.bandwidth config. Once the limit is hit, pull queries will fail immediately.

Testing done

  • Manual Testing
  • Unit testing
  • Integration testing

Reviewer checklist

  • Ensure docs are updated if necessary. (eg. if a user visible feature is being added or changed).
  • Ensure relevant issues are linked (description should include text like "Fixes #")

@cprasad1 cprasad1 requested a review from a team as a code owner June 28, 2021 23:29
@cprasad1 cprasad1 merged commit 8f01ad9 into confluentinc:master Jul 1, 2021
@cprasad1 cprasad1 deleted the pull_band_limit branch July 1, 2021 00:28
Copy link
Contributor

@guozhangwang guozhangwang left a comment

Choose a reason for hiding this comment

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

Hey @cprasad1 sorry I'm late on this. I made a quick pass on the non-testing part and just left some quick comments. Please feel free to ignore as the PR is already merged anyways.

checkArgument(responseSizeInBytes >= 0,
"Response size can't be negative.");

responseSizesLog.add(new Pair<>(timestamp, responseSizeInBytes));
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wearing my paranoid window processing interviewer hat here :) Just in case we may have a time shift from Time.SYSTEM.milliseconds(), maybe do a quick sorted insert from the head than blinding adding at the head? In practice most of it would just end at the head so perf-wise it should be fine.

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 the purpose of the RateLimiter was to bound the bandwidth usage approximately over the span of an hour (on that time-scale, I don't see a significant time shift happening), I think the current algorithm will work just fine. Do you think it is worth making this optimization?

@@ -218,6 +224,7 @@ private QueryPublisher createPullQueryPublisher(
metrics.recordRowsProcessed(
Optional.ofNullable(r).map(PullQueryResult::getTotalRowsProcessed).orElse(0L),
sourceType, planType, routingNodeType);
pullBandRateLimiter.add(responseBytes);
Copy link
Contributor

Choose a reason for hiding this comment

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

We would need to call system time to record metrics above, maybe we can just get one system time once to save the number of currentSystimeMillis?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto for other add calls where we would potentially get systemTime multiple times.

Copy link
Member Author

Choose a reason for hiding this comment

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

Keeping the logic of getting the systemTime internal to the pullBandRateLimiter seemed like a cleaner design. That way the common method interface is simpler and someone cannot pass in a bad value. It does come at the expense of potentially multiple redundant function calls.

It is also an attempt at decoupling the metrics reporting logic and bandwidth limiting logic. We are already piggy-backing on the metrics reporting framework for limiting the bandwidth, and I did not want further coupling between the two.

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