Skip to content

In-memory Engine: optimize auto evict to reduce latency spike#18130

Merged
ti-chi-bot[bot] merged 10 commits intotikv:masterfrom
overvenus:ime/fix-auto-load-evict-bounce
Jan 23, 2025
Merged

In-memory Engine: optimize auto evict to reduce latency spike#18130
ti-chi-bot[bot] merged 10 commits intotikv:masterfrom
overvenus:ime/fix-auto-load-evict-bounce

Conversation

@overvenus
Copy link
Member

@overvenus overvenus commented Jan 16, 2025

What is changed and how it works?

Issue Number: Close #18093

What's Changed:

Tested with read-only workload.

Left: This PR
Right: nightly 2025-01-13

image
Optimize auto evict to minimize coprocessor request latency by avoiding
periodic eviction and loading of regions with high MVCC amplification.

* Do not evict cached regions when memory has not reached the
  `stop-load-threshold`.
* Replace MVCC amplification-based auto evict strategy with a simple
  moving average of coprocessor requests. This is because
  `RegionWriteCfCopDetail` only reflects MVCC amplification in IME,
  not in RocksDB, making low MVCC amplification a poor indicator for eviction.

Related changes

  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test

Release note

Optimize auto evict to minimize coprocessor request latency by avoiding periodic eviction and loading of regions with high MVCC amplification.

Signed-off-by: Neil Shen <overvenus@gmail.com>
Signed-off-by: Neil Shen <overvenus@gmail.com>
Signed-off-by: Neil Shen <overvenus@gmail.com>
Signed-off-by: Neil Shen <overvenus@gmail.com>
Signed-off-by: Neil Shen <overvenus@gmail.com>
Signed-off-by: Neil Shen <overvenus@gmail.com>
@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/needs-triage-completed dco-signoff: yes Indicates the PR's author has signed the dco. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed do-not-merge/needs-triage-completed labels Jan 16, 2025
Copy link
Contributor

@glorv glorv left a comment

Choose a reason for hiding this comment

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

most LGTM, but I think request count only is a very poor metrics for region eviction.

let is_cop_requests_low = crs.sma_cop_requests_avg
<= avg_cop_requests / SMA_COP_REQUEST_AVG_FILTER_FACTOR;

let is_cop_requests_reliable =
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean if a region has no reuqest, it can be evicted at all?

Copy link
Member Author

Choose a reason for hiding this comment

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

is_cop_requests_low means if a region has a few requests, then it will be an eviction candidate.
is_cop_requests_reliable means an eviction candidate can only be evicted if IME has sampled it three times (by default 30 minutes)

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you update the annotations with the above comments or incorporate them into the annotations? This would make the strategy for choosing eviction candidates clearer and easier to understand.

Copy link
Member Author

Choose a reason for hiding this comment

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

Comments are added in f263f5e

});
}

crss.sort_by(|a, b| {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally, we should cache regions which to most reqeusts * (avg_kv_per_req_before_cache - avg_kv_per_req_after_cache), this can largely reflect the resource usage save after load. Thus, I think QPS or request_count is an even poorer metrics here.

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 can iterative improve the eviction algorithm, after all the master implementation is inaccurate, and this PR can reduce spike as tests show.

in_gc: AtomicBool::new(source_meta.in_gc.load(Ordering::Relaxed)),
is_written: AtomicBool::new(source_meta.is_written.load(Ordering::Relaxed)),
evict_info: None,
average_cop_requests: Arc::new(Mutex::new(Default::default())),
Copy link
Contributor

Choose a reason for hiding this comment

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

So after region split, all child region's stats will be reset. Better derive the stats data from parent region.

#[derive(Debug)]
/// Estimates the smoothed coprocessor request rate over the last hour using a
/// simple moving average.
pub(crate) type CopRequestsSMA = Smoother<f64, COP_REQUEST_SMA_RECORD_COUNT, ONE_HOUR_IN_SECS, 0>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub(crate) type CopRequestsSMA = Smoother<f64, COP_REQUEST_SMA_RECORD_COUNT, ONE_HOUR_IN_SECS, 0>;
pub(crate) type CopRequestsSma = Smoother<f64, COP_REQUEST_SMA_RECORD_COUNT, ONE_HOUR_IN_SECS, 0>;

Follow the rust naming convension

Copy link
Contributor

@LykxSassinator LykxSassinator left a comment

Choose a reason for hiding this comment

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

Overall LGTM

Signed-off-by: Neil Shen <overvenus@gmail.com>
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jan 22, 2025
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Jan 22, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: glorv, LykxSassinator

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [LykxSassinator,glorv]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jan 22, 2025
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Jan 22, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-01-22 03:44:05.550732613 +0000 UTC m=+238772.881652012: ☑️ agreed by glorv.
  • 2025-01-22 06:57:58.086839174 +0000 UTC m=+250405.417758573: ☑️ agreed by LykxSassinator.

@LykxSassinator
Copy link
Contributor

/retest

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Jan 22, 2025

@overvenus: Your PR was out of date, I have automatically updated it for you.

If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@overvenus
Copy link
Member Author

/test pull-unit-test

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Jan 23, 2025

@overvenus: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

/test pull-unit-test

The following commands are available to trigger optional jobs:

/debug pull-integration-test

Use /test all to run the following jobs that were automatically triggered:

tikv/tikv/pull_unit_test
Details

In response to this:

/test pull-unit-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@overvenus
Copy link
Member Author

/test all

@glorv
Copy link
Contributor

glorv commented Jan 23, 2025

@overvenus there is a lint error

Signed-off-by: Neil Shen <overvenus@gmail.com>
…into ime/fix-auto-load-evict-bounce

Signed-off-by: Neil Shen <overvenus@gmail.com>
@overvenus
Copy link
Member Author

/merge

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Jan 23, 2025

@overvenus: We have migrated to builtin LGTM and approve plugins for reviewing.

👉 Please use /approve when you want approve this pull request.

The changes announcement: Proposal: Strengthen configuration change approval.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot ti-chi-bot bot merged commit 743fbd6 into tikv:master Jan 23, 2025
8 checks passed
@ti-chi-bot ti-chi-bot bot added this to the Pool milestone Jan 23, 2025
@overvenus overvenus added the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Feb 18, 2025
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.5: #18228.

ti-chi-bot bot pushed a commit that referenced this pull request Apr 1, 2025
#18228)

close #18093

Optimize auto evict to minimize coprocessor request latency by avoiding
periodic eviction and loading of regions with high MVCC amplification.

* Do not evict cached regions when memory has not reached the
  `stop-load-threshold`.
* Replace MVCC amplification-based auto evict strategy with a simple
  moving average of coprocessor requests. This is because
  `RegionWriteCfCopDetail` only reflects MVCC amplification in IME,
  not in RocksDB, making low MVCC amplification a poor indicator for eviction.

Signed-off-by: Neil Shen <overvenus@gmail.com>

Co-authored-by: Neil Shen <overvenus@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved dco-signoff: yes Indicates the PR's author has signed the dco. lgtm needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In-memory Engine: regions periodically evict and load which may lead to latency jitter

4 participants