Skip to content

Commit 22d81ee

Browse files
authored
Merge pull request #1669 from tursodatabase/tokio-runtime-metrics
expose basic tokio runtime metrics
2 parents 6ba85b4 + f6fe40d commit 22d81ee

5 files changed

Lines changed: 84 additions & 7 deletions

File tree

.github/workflows/nemesis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
if: github.repository == 'tursodatabase/libsql'
1919
name: Run Nemesis Tests
2020
env:
21-
RUSTFLAGS: -D warnings
21+
RUSTFLAGS: -D warnings --cfg tokio_unstable
2222
steps:
2323
- uses: hecrj/setup-rust-action@v2
2424

.github/workflows/rust.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
runs-on: ubuntu-latest
2424
name: Run Checks
2525
env:
26-
RUSTFLAGS: -D warnings
26+
RUSTFLAGS: -D warnings --cfg tokio_unstable
2727
steps:
2828
- uses: hecrj/setup-rust-action@v2
2929

@@ -80,15 +80,15 @@ jobs:
8080
- uses: taiki-e/install-action@cargo-udeps
8181
- uses: Swatinem/rust-cache@v2
8282
- run: cargo +nightly hack udeps -p libsql --each-feature
83-
- run: RUSTFLAGS="-D warnings" cargo check -p libsql --no-default-features --features core
84-
- run: RUSTFLAGS="-D warnings" cargo check -p libsql --no-default-features --features replication
85-
- run: RUSTFLAGS="-D warnings" cargo check -p libsql --no-default-features --features remote
83+
- run: RUSTFLAGS="-D warnings --cfg tokio_unstable" cargo check -p libsql --no-default-features --features core
84+
- run: RUSTFLAGS="-D warnings --cfg tokio_unstable" cargo check -p libsql --no-default-features --features replication
85+
- run: RUSTFLAGS="-D warnings --cfg tokio_unstable" cargo check -p libsql --no-default-features --features remote
8686

8787
test:
8888
runs-on: ubuntu-latest
8989
name: Run Tests
9090
env:
91-
RUSTFLAGS: -D warnings
91+
RUSTFLAGS: -D warnings --cfg tokio_unstable
9292
steps:
9393
- uses: hecrj/setup-rust-action@v2
9494

libsql-server/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ default-run = "sqld"
88
name = "sqld"
99
path = "src/main.rs"
1010

11+
[build]
12+
rustflags = ["--cfg", "tokio_unstable"]
13+
1114
[dependencies]
1215
anyhow = "1.0.66"
1316
async-lock = "2.6.0"

libsql-server/src/http/admin/mod.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,29 @@ where
9393

9494
tokio::task::spawn(async move {
9595
loop {
96-
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
96+
let runtime = tokio::runtime::Handle::current();
97+
let metrics = runtime.metrics();
98+
crate::metrics::TOKIO_RUNTIME_BLOCKING_QUEUE_DEPTH
99+
.set(metrics.blocking_queue_depth() as f64);
100+
crate::metrics::TOKIO_RUNTIME_INJECTION_QUEUE_DEPTH
101+
.set(metrics.injection_queue_depth() as f64);
102+
crate::metrics::TOKIO_RUNTIME_NUM_BLOCKING_THREADS
103+
.set(metrics.num_blocking_threads() as f64);
104+
crate::metrics::TOKIO_RUNTIME_NUM_IDLE_BLOCKING_THREADS
105+
.set(metrics.num_idle_blocking_threads() as f64);
106+
crate::metrics::TOKIO_RUNTIME_NUM_WORKERS.set(metrics.num_workers() as f64);
107+
108+
crate::metrics::TOKIO_RUNTIME_IO_DRIVER_FD_DEREGISTERED_COUNT
109+
.absolute(metrics.io_driver_fd_deregistered_count() as u64);
110+
crate::metrics::TOKIO_RUNTIME_IO_DRIVER_FD_REGISTERED_COUNT
111+
.absolute(metrics.io_driver_fd_registered_count() as u64);
112+
crate::metrics::TOKIO_RUNTIME_IO_DRIVER_READY_COUNT
113+
.absolute(metrics.io_driver_ready_count() as u64);
114+
crate::metrics::TOKIO_RUNTIME_REMOTE_SCHEDULE_COUNT
115+
.absolute(metrics.remote_schedule_count() as u64);
97116

98117
crate::metrics::SERVER_COUNT.set(1.0);
118+
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
99119
}
100120
});
101121

libsql-server/src/metrics.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,57 @@ pub static QUERY_CANCELED: Lazy<Counter> = Lazy::new(|| {
158158
describe_counter!(NAME, "Number of canceled queries");
159159
register_counter!(NAME)
160160
});
161+
162+
pub static TOKIO_RUNTIME_BLOCKING_QUEUE_DEPTH: Lazy<Gauge> = Lazy::new(|| {
163+
const NAME: &str = "tokio_runtime_blocking_queue_depth";
164+
describe_gauge!(NAME, "tokio runtime blocking_queue_depth");
165+
register_gauge!(NAME)
166+
});
167+
168+
pub static TOKIO_RUNTIME_INJECTION_QUEUE_DEPTH: Lazy<Gauge> = Lazy::new(|| {
169+
const NAME: &str = "tokio_runtime_injection_queue_depth";
170+
describe_gauge!(NAME, "tokio runtime injection_queue_depth");
171+
register_gauge!(NAME)
172+
});
173+
174+
pub static TOKIO_RUNTIME_NUM_BLOCKING_THREADS: Lazy<Gauge> = Lazy::new(|| {
175+
const NAME: &str = "tokio_runtime_num_blocking_threads";
176+
describe_gauge!(NAME, "tokio runtime num_blocking_threads");
177+
register_gauge!(NAME)
178+
});
179+
180+
pub static TOKIO_RUNTIME_NUM_IDLE_BLOCKING_THREADS: Lazy<Gauge> = Lazy::new(|| {
181+
const NAME: &str = "tokio_runtime_num_idle_blocking_threads";
182+
describe_gauge!(NAME, "tokio runtime num_idle_blocking_threads");
183+
register_gauge!(NAME)
184+
});
185+
186+
pub static TOKIO_RUNTIME_NUM_WORKERS: Lazy<Gauge> = Lazy::new(|| {
187+
const NAME: &str = "tokio_runtime_num_workers";
188+
describe_gauge!(NAME, "tokio runtime num_workers");
189+
register_gauge!(NAME)
190+
});
191+
192+
pub static TOKIO_RUNTIME_IO_DRIVER_FD_DEREGISTERED_COUNT: Lazy<Counter> = Lazy::new(|| {
193+
const NAME: &str = "tokio_runtime_io_driver_fd_deregistered_count";
194+
describe_counter!(NAME, "tokio runtime io_driver_fd_deregistered_count");
195+
register_counter!(NAME)
196+
});
197+
198+
pub static TOKIO_RUNTIME_IO_DRIVER_FD_REGISTERED_COUNT: Lazy<Counter> = Lazy::new(|| {
199+
const NAME: &str = "tokio_runtime_io_driver_fd_registered_count";
200+
describe_counter!(NAME, "tokio runtime io_driver_fd_registered_count");
201+
register_counter!(NAME)
202+
});
203+
204+
pub static TOKIO_RUNTIME_IO_DRIVER_READY_COUNT: Lazy<Counter> = Lazy::new(|| {
205+
const NAME: &str = "tokio_runtime_io_driver_ready_count";
206+
describe_counter!(NAME, "tokio runtime io_driver_ready_count");
207+
register_counter!(NAME)
208+
});
209+
210+
pub static TOKIO_RUNTIME_REMOTE_SCHEDULE_COUNT: Lazy<Counter> = Lazy::new(|| {
211+
const NAME: &str = "tokio_runtime_remote_schedule_count";
212+
describe_gauge!(NAME, "tokio runtime remote_schedule_count");
213+
register_counter!(NAME)
214+
});

0 commit comments

Comments
 (0)