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

--consolidator-query-waiter-cap to set the max number of waiter for consolidated query #17244

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jwangace
Copy link
Contributor

@jwangace jwangace commented Nov 16, 2024

Description

This PR proposed to use config ConsolidatorQueryWaiterCap to set the max number of clients Wait() for all consolidated queries, more same queries will fall back to use getConn() where is protected by connection pools.

With configureable ConsolidatorQueryWaiterCap (default to 0 means unlimit, user can adjust this value accordingly), when properly set would help to prevent when the Result of first query been returned, same Result would be sent concurrently to large number of clients, cause memory abruptly went high.

Related Issue(s)

Issue: #17243
Documentation: vitessio/website#1900

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Deployment Notes

Copy link
Contributor

vitess-bot bot commented Nov 16, 2024

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@vitess-bot vitess-bot bot added NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels Nov 16, 2024
@github-actions github-actions bot added this to the v22.0.0 milestone Nov 16, 2024
@harshit-gangal harshit-gangal added the release notes (needs details) This PR needs to be listed in the release notes in a dedicated section (deprecation notice, etc...) label Nov 20, 2024
Copy link
Member

@harshit-gangal harshit-gangal left a comment

Choose a reason for hiding this comment

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

This would also require addition to summary notes for v22 over https://github.com/vitessio/vitess/blob/main/changelog/22.0/22.0.0/summary.md

You can see v21 summary notes to see the template to add new configuration to release notes

@harshit-gangal
Copy link
Member

@harshit-gangal harshit-gangal added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: Query Serving and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Nov 20, 2024
@jwangace
Copy link
Contributor Author

This would also require addition to summary notes for v22 over https://github.com/vitessio/vitess/blob/main/changelog/22.0/22.0.0/summary.md

You can see v21 summary notes to see the template to add new configuration to release notes

Updated.

@jwangace
Copy link
Contributor Author

jwangace commented Nov 21, 2024

Website docs would also need an update https://vitess.io/docs/22.0/user-guides/configuration-advanced/query-consolidation/

Hi @harshit-gangal This is not in this repo, is it?

Copy link

codecov bot commented Nov 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.51%. Comparing base (45192d2) to head (e5cdf1a).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17244      +/-   ##
==========================================
- Coverage   67.52%   67.51%   -0.02%     
==========================================
  Files        1581     1581              
  Lines      253948   253958      +10     
==========================================
- Hits       171480   171454      -26     
- Misses      82468    82504      +36     

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

@jwangace jwangace force-pushed the issues_17243 branch 4 times, most recently from 48f184e to 7cb8366 Compare November 21, 2024 03:32
@jwangace jwangace force-pushed the issues_17243 branch 6 times, most recently from 6739ea6 to 8a5715e Compare November 29, 2024 21:36
@jwangace jwangace changed the title --consolidator-query-waiter-cap to set the max number of clients waiting for consolidated query --consolidator-query-waiter-cap to set the max number of waiter for consolidated query Nov 30, 2024
@jwangace
Copy link
Contributor Author

This can lead to slowness in query serving path. Either we make it an absolute count than per query count or we add a benchmark test for it.

Pushed new solution to use absolute count.

@jwangace jwangace force-pushed the issues_17243 branch 2 times, most recently from 3317e4a to 2d8cf24 Compare December 2, 2024 17:01
@@ -1014,6 +1016,7 @@ var defaultConfig = TabletConfig{
Consolidator: Enable,
ConsolidatorStreamTotalSize: 128 * 1024 * 1024,
ConsolidatorStreamQuerySize: 2 * 1024 * 1024,
ConsolidatorQueryWaiterCap: 0,
Copy link
Member

Choose a reason for hiding this comment

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

nit: this can be ignored to be kept in default config for 0 as default

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I dropped this line and use 0 as default in the flag.

Comment on lines 721 to 725
waiterCap := qre.tsv.config.ConsolidatorQueryWaiterCap
if waiterCap == 0 || c.WaiterCountOfTotal() <= waiterCap {
qre.logStats.QuerySources |= tabletenv.QuerySourceConsolidator
startTime := time.Now()
q.Wait()
qre.tsv.stats.WaitTimings.Record("Consolidations", startTime)
}
Copy link
Member

Choose a reason for hiding this comment

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

Adding the waiter in Record is too late. As the wait is already complete in q.Wait().
Post that q.Result() returns the stored result.

c.WaiterCountOfTotal() <= waiterCap - This check will allow concurrent threads to go through without respecting the limit.

Copy link
Contributor Author

@jwangace jwangace Dec 4, 2024

Choose a reason for hiding this comment

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

Hi @harshit-gangal Could you please let me know if I understand correctly regarding your concern.

c.WaiterCountOfTotal() <= waiterCap - This check will allow concurrent threads to go through without respecting the limit.

  • Same query won't run concurrently, because q is a same *pendingResult object

  • Different queries when run concurrently (for those following same queries), this solution uses totalWaiterCount and only record those queries that use Wait() for *pendingResult. For example, if there are 2 different queries, and:
    -- select a from A (1 running, 100 waiting)
    -- select b from B (1 running, 100 waiting)
    Then totalWaiterCount is 100+100=200, I added testCase on this, which is concurrently update totalWaiterCount and verify above theory is correct also verify no data race when on concurrent.

  • Uniq queries should only enter if original {...} path, so it does not run c.WaiterCountOfTotal() <= waiterCap check.

c.WaiterCountOfTotal() <= waiterCap - This check will allow concurrent threads to go through without respecting the limit.

WaiterCountOfTotal() is a concurrent safe, so it should be respected the limit.

func (co *consolidator) WaiterCountOfTotal() int64 {
	return atomic.LoadInt64(co.totalWaiterCount)
}

Adding the waiter in Record is too late. As the wait is already complete in q.Wait().
Post that q.Result() returns the stored result.

Record is already used to increase the count of query, for queries passed c.WaiterCountOfTotal() <= waiterCap check, seems a good space to increase totalWaiterCount as well.

@jwangace jwangace force-pushed the issues_17243 branch 8 times, most recently from c526b3a to 8e62c33 Compare December 4, 2024 07:41
@@ -7,6 +7,9 @@
- **[Prefer not promoting a replica that is currently taking a backup](#reparents-prefer-not-backing-up)**
- **[VTOrc Config File Changes](#vtorc-config-file-changes)**

- **[Minor Changes](#minor-changes)**
- **[VTTablet](#vttablet)**
- [VTTablet: New ResetSequences RPC](#vttablet-consolidator-query-waiter-cap)
Copy link
Member

Choose a reason for hiding this comment

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

VTTablet: New ResetSequences RPC -> Query Consolidation Waiter Cap

Comment on lines 721 to 723
if waiterCap == 0 || c.WaiterCountOfTotal() <= waiterCap {
qre.logStats.QuerySources |= tabletenv.QuerySourceConsolidator
startTime := time.Now()
q.Wait()
Copy link
Member

Choose a reason for hiding this comment

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

The waiter count increases on calling the q.Wait() method.
If you run 10s or 100s of request, they can still pass the check c.WaiterCountOfTotal() <= waiterCap before any new waiter not getting consolidated.
A concurrent test will help test if the waiter count exceeds the maximum allowed waiter.

I think the better place to update the wait counter will be in create call

@jwangace jwangace force-pushed the issues_17243 branch 3 times, most recently from 404ac98 to 2926cb0 Compare December 15, 2024 02:32
Signed-off-by: Jun Wang <[email protected]>
@jwangace
Copy link
Contributor Author

I will resolve the conflicts once this solution has been approved, to avoid more conflicts.

@harshit-gangal harshit-gangal removed the release notes (needs details) This PR needs to be listed in the release notes in a dedicated section (deprecation notice, etc...) label Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Query Serving Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants