Skip to content

Commit

Permalink
statistics: resource metering (tikv#10155)
Browse files Browse the repository at this point in the history
* init req-cpu

Signed-off-by: Zhenchi <[email protected]>

* update

Signed-off-by: Zhenchi <[email protected]>

* tiny improve

Signed-off-by: Zhenchi <[email protected]>

* add metrics

Signed-off-by: Zhenchi <[email protected]>

* update configs

Signed-off-by: Zhenchi <[email protected]>

* Record txn cpu usage

Signed-off-by: Zhenchi <[email protected]>

* introduce collector trait

Signed-off-by: Zhenchi <[email protected]>

* fix imprecise recording

Signed-off-by: Zhenchi <[email protected]>

* global singleton

Signed-off-by: Zhenchi <[email protected]>

* add tests

Signed-off-by: Zhenchi <[email protected]>

* integration into server

Signed-off-by: Zhenchi <[email protected]>

* rename: RequestTag -> ResourceMeteringTag

Signed-off-by: Zhenchi <[email protected]>

* opt-in Arc

Signed-off-by: Zhenchi <[email protected]>

* better place to instrument

Signed-off-by: Zhenchi <[email protected]>

* misc

Signed-off-by: Zhenchi <[email protected]>

* some movement

Signed-off-by: Zhenchi <[email protected]>

* add config

Signed-off-by: Zhenchi <[email protected]>

* implement reporter

Signed-off-by: Zhenchi <[email protected]>

* remove clone

Signed-off-by: Zhenchi <[email protected]>

* misc

Signed-off-by: Zhenchi <[email protected]>

* fix test

Signed-off-by: Zhenchi <[email protected]>

* tiny refactor

Signed-off-by: Zhenchi <[email protected]>

* tiny fix

Signed-off-by: Zhenchi <[email protected]>

* bump grpcio

Signed-off-by: Zhenchi <[email protected]>

Co-authored-by: Ti Chi Robot <[email protected]>
  • Loading branch information
zhongzc and ti-chi-bot authored Jun 3, 2021
1 parent acbba9f commit 1b0841c
Show file tree
Hide file tree
Showing 56 changed files with 1,620 additions and 79 deletions.
38 changes: 37 additions & 1 deletion Cargo.lock

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

8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ protobuf-codec = [
"txn_types/protobuf-codec",
"grpcio-health/protobuf-codec",
"file_system/protobuf-codec",
"resource_metering/protobuf-codec",
"protobuf/bytes",
]
prost-codec = [
Expand Down Expand Up @@ -98,6 +99,7 @@ prost-codec = [
"txn_types/prost-codec",
"grpcio-health/prost-codec",
"file_system/prost-codec",
"resource_metering/prost-codec",
]
testexport = ["raftstore/testexport"]
test-engines-rocksdb = [
Expand Down Expand Up @@ -157,7 +159,7 @@ hyper-openssl = "0.8"
http = "0"
into_other = { path = "components/into_other", default-features = false }
keys = { path = "components/keys", default-features = false }
kvproto = { rev = "f42e582bf0bb6bc2aee647e5f4126d51ccf6d377", git = "https://github.com/pingcap/kvproto.git", default-features = false }
kvproto = { rev = "7a046020d1c091638e1e8aba623c8c1e8962219d", git = "https://github.com/pingcap/kvproto.git", default-features = false }
lazy_static = "1.3"
libc = "0.2"
libloading = "0.7"
Expand Down Expand Up @@ -220,6 +222,7 @@ url = "2"
uuid = { version = "0.8.1", features = ["serde", "v4"] }
walkdir = "2"
yatp = { git = "https://github.com/tikv/yatp.git", branch = "master" }
resource_metering = { path = "components/resource_metering" }

[dev-dependencies]
panic_hook = { path = "components/panic_hook" }
Expand Down Expand Up @@ -312,7 +315,8 @@ members = [
"components/file_system",
"components/collections",
"components/coprocessor_plugin_api",
"components/test_coprocessor_plugin/example_plugin"
"components/test_coprocessor_plugin/example_plugin",
"components/resource_metering",
]
default-members = ["cmd/tikv-server", "cmd/tikv-ctl"]

Expand Down
2 changes: 1 addition & 1 deletion cmd/tikv-ctl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ tokio = { version = "0.2", features = ["rt-threaded", "time"] }
grpcio = { version = "0.9", default-features = false, features = ["openssl-vendored"] }
hex = "0.4"
keys = { path = "../../components/keys", default-features = false }
kvproto = { rev = "f42e582bf0bb6bc2aee647e5f4126d51ccf6d377", git = "https://github.com/pingcap/kvproto.git", default-features = false }
kvproto = { rev = "7a046020d1c091638e1e8aba623c8c1e8962219d", git = "https://github.com/pingcap/kvproto.git", default-features = false }
libc = "0.2"
log = { version = "0.4", features = ["max_level_trace", "release_max_level_debug"] }
log_wrappers = { path = "../../components/log_wrappers" }
Expand Down
2 changes: 1 addition & 1 deletion components/backup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ futures-util = { version = "0.3", default-features = false, features = ["io"] }
grpcio = { version = "0.9", default-features = false, features = ["openssl-vendored"] }
hex = "0.4"
keys = { path = "../keys", default-features = false }
kvproto = { rev = "f42e582bf0bb6bc2aee647e5f4126d51ccf6d377", git = "https://github.com/pingcap/kvproto.git", default-features = false }
kvproto = { rev = "7a046020d1c091638e1e8aba623c8c1e8962219d", git = "https://github.com/pingcap/kvproto.git", default-features = false }
lazy_static = "1.3"
log_wrappers = { path = "../log_wrappers" }
pd_client = { path = "../pd_client", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion components/cdc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ engine_rocks = { path = "../engine_rocks", default-features = false }
engine_traits = { path = "../engine_traits", default-features = false }
futures = "0.3"
grpcio = { version = "0.9", default-features = false, features = ["openssl-vendored"] }
kvproto = { rev = "f42e582bf0bb6bc2aee647e5f4126d51ccf6d377", git = "https://github.com/pingcap/kvproto.git", default-features = false }
kvproto = { rev = "7a046020d1c091638e1e8aba623c8c1e8962219d", git = "https://github.com/pingcap/kvproto.git", default-features = false }
pd_client = { path = "../pd_client", default-features = false }
raft = { version = "0.6.0-alpha", default-features = false }
raftstore = { path = "../raftstore", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion components/cloud/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async-trait = "0.1"
derive_more = "0.99.3"
error_code = { path = "../error_code", default-features = false }
futures-io = "0.3"
kvproto = { rev = "f42e582bf0bb6bc2aee647e5f4126d51ccf6d377", git = "https://github.com/pingcap/kvproto.git", default-features = false }
kvproto = { rev = "7a046020d1c091638e1e8aba623c8c1e8962219d", git = "https://github.com/pingcap/kvproto.git", default-features = false }
openssl = "0.10"
protobuf = "2.8"
rusoto_core = "0.45.0"
Expand Down
2 changes: 1 addition & 1 deletion components/cloud/aws/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ grpcio = { version = "0.9", default-features = false, features = ["openssl-vend
http = "0.2.0"
hyper = "0.13.3"
hyper-tls = "0.4.1"
kvproto = { rev = "f42e582bf0bb6bc2aee647e5f4126d51ccf6d377", git = "https://github.com/pingcap/kvproto.git", default-features = false }
kvproto = { rev = "7a046020d1c091638e1e8aba623c8c1e8962219d", git = "https://github.com/pingcap/kvproto.git", default-features = false }
rusoto_core = "0.45.0"
rusoto_credential = "0.45.0"
rusoto_kms = { version = "0.45.0", features = ["serialize_structs"] }
Expand Down
2 changes: 1 addition & 1 deletion components/cloud/gcp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ futures-util = { version = "0.3", default-features = false, features = ["io"] }
http = "0.2.0"
hyper = "0.13.3"
hyper-tls = "0.4.1"
kvproto = { rev = "f42e582bf0bb6bc2aee647e5f4126d51ccf6d377", git = "https://github.com/pingcap/kvproto.git", default-features = false }
kvproto = { rev = "7a046020d1c091638e1e8aba623c8c1e8962219d", git = "https://github.com/pingcap/kvproto.git", default-features = false }
slog = { version = "2.3", features = ["max_level_trace", "release_max_level_debug"] }
# better to not use slog-global, but pass in the logger
slog-global = { version = "0.1", git = "https://github.com/breeswish/slog-global.git", rev = "d592f88e4dbba5eb439998463054f1a44fbf17b9" }
Expand Down
2 changes: 1 addition & 1 deletion components/encryption/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ lazy_static = "1.3"
prometheus = { version = "0.10", features = ["nightly"] }
futures-util = { version = "0.3", default-features = false, features = ["std", "io"] }
hex = "0.4.2"
kvproto = { rev = "f42e582bf0bb6bc2aee647e5f4126d51ccf6d377", git = "https://github.com/pingcap/kvproto.git", default-features = false }
kvproto = { rev = "7a046020d1c091638e1e8aba623c8c1e8962219d", git = "https://github.com/pingcap/kvproto.git", default-features = false }
openssl = "0.10"
protobuf = "2.8"
rand = "0.7"
Expand Down
2 changes: 1 addition & 1 deletion components/encryption/export/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ derive_more = "0.99.3"
encryption = { path = "../", default-features = false }
error_code = { path = "../../error_code", default-features = false }
file_system = { path = "../../file_system", default-features = false }
kvproto = { rev = "f42e582bf0bb6bc2aee647e5f4126d51ccf6d377", git = "https://github.com/pingcap/kvproto.git", default-features = false }
kvproto = { rev = "7a046020d1c091638e1e8aba623c8c1e8962219d", git = "https://github.com/pingcap/kvproto.git", default-features = false }
openssl = "0.10"
protobuf = "2.8"
slog = { version = "2.3", features = ["max_level_trace", "release_max_level_debug"] }
Expand Down
2 changes: 1 addition & 1 deletion components/engine_panic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ engine_traits = { path = "../engine_traits", default-features = false }
tikv_alloc = { path = "../tikv_alloc" }
# FIXME: Remove this dep from the engine_traits interface
tikv_util = { path = "../tikv_util", default-features = false }
kvproto = { rev = "f42e582bf0bb6bc2aee647e5f4126d51ccf6d377", git = "https://github.com/pingcap/kvproto.git", default-features = false }
kvproto = { rev = "7a046020d1c091638e1e8aba623c8c1e8962219d", git = "https://github.com/pingcap/kvproto.git", default-features = false }
raft = { version = "0.6.0-alpha", default-features = false }
txn_types = { path = "../txn_types", default-features = false }
4 changes: 2 additions & 2 deletions components/engine_rocks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ configuration = { path = "../configuration" }
tempfile = "3.0"
serde = "1.0"
serde_derive = "1.0"
kvproto = { rev = "f42e582bf0bb6bc2aee647e5f4126d51ccf6d377", git = "https://github.com/pingcap/kvproto.git", default-features = false }
kvproto = { rev = "7a046020d1c091638e1e8aba623c8c1e8962219d", git = "https://github.com/pingcap/kvproto.git", default-features = false }
raft = { version = "0.6.0-alpha", default-features = false }
protobuf = "2"
fail = "0.4"
Expand All @@ -75,6 +75,6 @@ package = "rocksdb"
features = ["encryption", "static_libcpp"]

[dev-dependencies]
kvproto = { rev = "f42e582bf0bb6bc2aee647e5f4126d51ccf6d377", git = "https://github.com/pingcap/kvproto.git", default-features = false }
kvproto = { rev = "7a046020d1c091638e1e8aba623c8c1e8962219d", git = "https://github.com/pingcap/kvproto.git", default-features = false }
rand = "0.7"
toml = "0.5"
2 changes: 1 addition & 1 deletion components/engine_traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ txn_types = { path = "../txn_types", default-features = false }
serde = "1.0"
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" }
kvproto = { rev = "f42e582bf0bb6bc2aee647e5f4126d51ccf6d377", git = "https://github.com/pingcap/kvproto.git", default-features = false }
kvproto = { rev = "7a046020d1c091638e1e8aba623c8c1e8962219d", git = "https://github.com/pingcap/kvproto.git", default-features = false }
raft = { version = "0.6.0-alpha", default-features = false }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion components/error_code/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ path = "bin.rs"
[dependencies]
lazy_static = "1.3"
raft = { version = "0.6.0-alpha", default-features = false }
kvproto = { rev = "f42e582bf0bb6bc2aee647e5f4126d51ccf6d377", git = "https://github.com/pingcap/kvproto.git", default-features = false }
kvproto = { rev = "7a046020d1c091638e1e8aba623c8c1e8962219d", git = "https://github.com/pingcap/kvproto.git", default-features = false }
tikv_alloc = { path = "../tikv_alloc" }
grpcio = { version = "0.9", default-features = false, features = ["openssl-vendored"] }
toml = "0.5"
Expand Down
2 changes: 1 addition & 1 deletion components/external_storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ futures-executor = "0.3"
futures-io = "0.3"
futures-util = { version = "0.3", default-features = false, features = ["io"] }
grpcio = { optional = true, version = "0.9", default-features = false, features = ["openssl-vendored"] }
kvproto = { rev = "f42e582bf0bb6bc2aee647e5f4126d51ccf6d377", git = "https://github.com/pingcap/kvproto.git", default-features = false }
kvproto = { rev = "7a046020d1c091638e1e8aba623c8c1e8962219d", git = "https://github.com/pingcap/kvproto.git", default-features = false }
lazy_static = "1.3"
libloading = { optional = true, version = "0.7.0" }
prometheus = { version = "0.10", default-features = false, features = ["nightly", "push"] }
Expand Down
2 changes: 1 addition & 1 deletion components/external_storage/export/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ futures = { optional = true, version = "0.3" }
futures-executor = { optional = true, version = "0.3" }
futures-io = { version = "0.3" }
futures-util = { version = "0.3", default-features = false, features = ["io"] }
kvproto = { rev = "f42e582bf0bb6bc2aee647e5f4126d51ccf6d377", git = "https://github.com/pingcap/kvproto.git", default-features = false }
kvproto = { rev = "7a046020d1c091638e1e8aba623c8c1e8962219d", git = "https://github.com/pingcap/kvproto.git", default-features = false }
libloading = { optional = true, version = "0.7.0" }
once_cell = { optional = true, version = "1.3.1" }
protobuf = { optional = true, version = "2" }
Expand Down
2 changes: 1 addition & 1 deletion components/into_other/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ prost-codec = [

[dependencies]
engine_traits = { path = "../engine_traits", default-features = false }
kvproto = { rev = "f42e582bf0bb6bc2aee647e5f4126d51ccf6d377", git = "https://github.com/pingcap/kvproto.git", default-features = false }
kvproto = { rev = "7a046020d1c091638e1e8aba623c8c1e8962219d", git = "https://github.com/pingcap/kvproto.git", default-features = false }
raft = { version = "0.6.0-alpha", default-features = false }
2 changes: 1 addition & 1 deletion components/keys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ prost-codec = [

[dependencies]
byteorder = "1.2"
kvproto = { rev = "f42e582bf0bb6bc2aee647e5f4126d51ccf6d377", git = "https://github.com/pingcap/kvproto.git", default-features = false }
kvproto = { rev = "7a046020d1c091638e1e8aba623c8c1e8962219d", git = "https://github.com/pingcap/kvproto.git", default-features = false }
log_wrappers = { path = "../log_wrappers" }
thiserror = "1.0"
tikv_alloc = { path = "../tikv_alloc" }
Expand Down
2 changes: 1 addition & 1 deletion components/pd_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ failpoints = ["fail/failpoints"]
error_code = { path = "../error_code", default-features = false }
futures = "0.3"
grpcio = { version = "0.9", default-features = false, features = ["openssl-vendored"] }
kvproto = { rev = "f42e582bf0bb6bc2aee647e5f4126d51ccf6d377", git = "https://github.com/pingcap/kvproto.git", default-features = false }
kvproto = { rev = "7a046020d1c091638e1e8aba623c8c1e8962219d", git = "https://github.com/pingcap/kvproto.git", default-features = false }
lazy_static = "1.3"
log = { version = "0.4", features = ["max_level_trace", "release_max_level_debug"] }
log_wrappers = { path = "../log_wrappers" }
Expand Down
2 changes: 1 addition & 1 deletion components/raft_log_engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ time = "0.1"
configuration = { path = "../configuration" }
serde = "1.0"
serde_derive = "1.0"
kvproto = { rev = "f42e582bf0bb6bc2aee647e5f4126d51ccf6d377", git = "https://github.com/pingcap/kvproto.git", default-features = false }
kvproto = { rev = "7a046020d1c091638e1e8aba623c8c1e8962219d", git = "https://github.com/pingcap/kvproto.git", default-features = false }
raft = { version = "0.6.0-alpha", default-features = false }
raft-engine = { git = "https://github.com/tikv/raft-engine", branch = "master" }
protobuf = "2"
2 changes: 1 addition & 1 deletion components/raftstore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ futures = "0.3"
futures-util = { version = "0.3.1", default-features = false, features = ["io"] }
into_other = { path = "../into_other", default-features = false }
keys = { path = "../keys", default-features = false }
kvproto = { rev = "f42e582bf0bb6bc2aee647e5f4126d51ccf6d377", git = "https://github.com/pingcap/kvproto.git", default-features = false }
kvproto = { rev = "7a046020d1c091638e1e8aba623c8c1e8962219d", git = "https://github.com/pingcap/kvproto.git", default-features = false }
lazy_static = "1.3"
log = { version = "0.4", features = ["max_level_trace", "release_max_level_debug"] }
log_wrappers = { path = "../log_wrappers" }
Expand Down
2 changes: 1 addition & 1 deletion components/resolved_ts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fail = "0.4"
futures = "0.3"
grpcio = { version = "0.9", default-features = false, features = ["openssl-vendored"] }
hex = "0.4"
kvproto = { rev = "f42e582bf0bb6bc2aee647e5f4126d51ccf6d377", git = "https://github.com/pingcap/kvproto.git", default-features = false }
kvproto = { rev = "7a046020d1c091638e1e8aba623c8c1e8962219d", git = "https://github.com/pingcap/kvproto.git", default-features = false }
lazy_static = "1.3"
log_wrappers = { path = "../log_wrappers" }
pd_client = { path = "../pd_client", default-features = false }
Expand Down
44 changes: 44 additions & 0 deletions components/resource_metering/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
name = "resource_metering"
version = "0.0.1"
edition = "2018"

[features]
default = ["protobuf-codec"]
protobuf-codec = [
"kvproto/protobuf-codec",
"grpcio/protobuf-codec",
"security/protobuf-codec",
]
prost-codec = [
"kvproto/prost-codec",
"grpcio/prost-codec",
"security/prost-codec",
]

[dependencies]
lazy_static = "1.3"
collections = { path = "../collections" }
libc = "0.2"
crossbeam = "0.8"
pin-project = "1.0"
prometheus = { version = "0.10", features = ["nightly"] }
prometheus-static-metric = "0.4"
kvproto = { rev = "7a046020d1c091638e1e8aba623c8c1e8962219d", git = "https://github.com/pingcap/kvproto.git", default-features = false }
tikv_util = { path = "../tikv_util" }
grpcio = { version = "0.9", default-features = false, features = ["openssl-vendored"] }
security = { path = "../security", default-features = false }
configuration = { path = "../configuration" }
serde = "1.0"
serde_derive = "1.0"
log = { version = "0.4", features = ["max_level_trace", "release_max_level_debug"] }
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" }
futures = "0.3"
pdqselect = "0.1"

[target.'cfg(target_os = "linux")'.dependencies]
procinfo = { git = "https://github.com/tikv/procinfo-rs", rev = "5125fc1a69496b73b26b3c08b6e8afc3c665a56e" }

[dev-dependencies]
rand = "0.8"
8 changes: 8 additions & 0 deletions components/resource_metering/src/cpu/collector/dummy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright 2021 TiKV Project Authors. Licensed under Apache-2.0.

use crate::cpu::collector::Collector;

pub struct CollectorHandle;
pub fn register_collector(_collector: Box<dyn Collector>) -> CollectorHandle {
CollectorHandle
}
Loading

0 comments on commit 1b0841c

Please sign in to comment.