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

*: add resource group for the read path #14001

Merged
merged 16 commits into from Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
91 changes: 83 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Expand Up @@ -139,6 +139,7 @@ raftstore = { workspace = true, features = ["engine_rocks"] }
raftstore-v2 = { workspace = true }
rand = "0.7.3"
regex = "1.3"
resource_control = { workspace = true }
resource_metering = { workspace = true }
rev_lines = "0.2.1"
seahash = "4.1.0"
Expand Down Expand Up @@ -267,6 +268,7 @@ members = [
"components/raftstore",
"components/raftstore-v2",
"components/resolved_ts",
"components/resource_control",
"components/resource_metering",
"components/security",
"components/server",
Expand Down Expand Up @@ -341,6 +343,7 @@ raft_log_engine = { path = "components/raft_log_engine" }
raftstore = { path = "components/raftstore", default-features = false }
raftstore-v2 = { path = "components/raftstore-v2", default-features = false }
resolved_ts = { path = "components/resolved_ts" }
resource_control = { path = "components/resource_control" }
resource_metering = { path = "components/resource_metering" }
security = { path = "components/security" }
server = { path = "components/server" }
Expand Down
20 changes: 20 additions & 0 deletions components/resource_control/Cargo.toml
@@ -0,0 +1,20 @@
[package]
name = "resource_control"
version = "0.0.1"
edition = "2021"
publish = false

[dependencies]
byteorder = "1.2"
crossbeam-skiplist = { git = "https://github.com/crossbeam-rs/crossbeam" }
dashmap = "5.1"
kvproto = { git = "https://github.com/pingcap/kvproto.git" }
lazy_static = "1.0"
online_config = { workspace = true }
pin-project = "1.0"
prometheus = { version = "0.13", features = ["nightly"] }
serde = { version = "1.0", features = ["derive"] }
slog = { version = "2.3", features = ["max_level_trace", "release_max_level_debug"] }
slog-global = { version = "0.1", git = "https://github.com/breeswish/slog-global.git", rev = "d592f88e4dbba5eb439998463054f1a44fbf17b9" }
tikv_util = { workspace = true }
yatp = { git = "https://github.com/tikv/yatp.git", branch = "master" }
46 changes: 46 additions & 0 deletions components/resource_control/src/future.rs
@@ -0,0 +1,46 @@
// Copyright 2022 TiKV Project Authors. Licensed under Apache-2.0.

use std::{
future::Future,
pin::Pin,
sync::Arc,
task::{Context, Poll},
};

use pin_project::pin_project;
use tikv_util::time::Instant;

use crate::resource_group::{ResourceConsumeType, ResourceController};

#[pin_project]
pub struct ControlledFuture<F> {
#[pin]
future: F,
controller: Arc<ResourceController>,
group_name: Vec<u8>,
}

impl<F> ControlledFuture<F> {
pub fn new(future: F, controller: Arc<ResourceController>, group_name: Vec<u8>) -> Self {
Self {
future,
controller,
group_name,
}
}
}

impl<F: Future> Future for ControlledFuture<F> {
type Output = F::Output;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.project();
let now = Instant::now();
let res = this.future.poll(cx);
this.controller.consume(
this.group_name,
ResourceConsumeType::CpuTime(now.saturating_elapsed()),
);
res
}
}
18 changes: 18 additions & 0 deletions components/resource_control/src/lib.rs
@@ -0,0 +1,18 @@
// Copyright 2022 TiKV Project Authors. Licensed under Apache-2.0.

use online_config::OnlineConfig;
use serde::{Deserialize, Serialize};

mod resource_group;
pub use resource_group::{ResourceController, ResourceGroupManager, MIN_PRIORITY_UPDATE_INTERVAL};

mod future;
pub use future::ControlledFuture;

#[derive(Clone, Serialize, Deserialize, PartialEq, Debug, OnlineConfig, Default)]
#[serde(default)]
#[serde(rename_all = "kebab-case")]
pub struct Config {
#[online_config(skip)]
pub enabled: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

please also add a sample in config-tempalte.toml

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Connor1996 PTAL, do you feel ok with this new config

Copy link
Member

Choose a reason for hiding this comment

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

looks good

Copy link
Member

Choose a reason for hiding this comment

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

Bad name. Should be enable.

}