Skip to content

Commit

Permalink
add inflight req metric
Browse files Browse the repository at this point in the history
  • Loading branch information
longbowlu committed Feb 2, 2023
1 parent 9e10407 commit ac0dfe8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/sui-json-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ futures = "0.3.23"
tokio = { workspace = true, features = ["full"] }
signature = "1.6.0"
thiserror = "1.0.37"
scopeguard = "1.1"
bcs = "0.1.4"

tap = "1.0"
Expand Down
31 changes: 28 additions & 3 deletions crates/sui-json-rpc/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use hyper::{body, http, Body, Request, Response};
use jsonrpsee::core::__reexports::serde_json;
use jsonrpsee::types::error::ErrorCode;
use prometheus::{
register_histogram_vec_with_registry, register_int_counter_vec_with_registry, HistogramVec,
IntCounterVec,
register_histogram_vec_with_registry, register_int_counter_vec_with_registry,
register_int_gauge_vec_with_registry, HistogramVec, IntCounterVec, IntGaugeVec,
};
use serde::Deserialize;
use tokio::time::Instant;
Expand All @@ -37,6 +37,13 @@ impl MetricsLayer {
registry,
)
.unwrap(),
inflight_requests_by_route: register_int_gauge_vec_with_registry!(
"inflight_rpc_requests_by_route",
"Number of inflight requests by route",
&["route"],
registry,
)
.unwrap(),
req_latency_by_route: register_histogram_vec_with_registry!(
"req_latency_by_route",
"Latency of a request by route",
Expand Down Expand Up @@ -80,6 +87,8 @@ pub struct JsonRpcMetricService<S> {
pub struct Metrics {
/// Counter of requests, route is a label (ie separate timeseries per route)
requests_by_route: IntCounterVec,
/// Gauge of inflight requests, route is a label (ie separate timeseries per route)
inflight_requests_by_route: IntGaugeVec,
/// Request latency, route is a label
req_latency_by_route: HistogramVec,
/// Failed requests by route
Expand Down Expand Up @@ -145,14 +154,30 @@ where
(None, req)
};

let _inflight_guard = if let Some(name) = &rpc_name {
if whitelist.contains(name) {
metrics.requests_by_route.with_label_values(&[name]).inc();
let in_flight = metrics
.inflight_requests_by_route
.with_label_values(&[name]);
in_flight.inc();
Some(scopeguard::guard(in_flight, |in_flight| {
in_flight.dec();
}))
} else {
None
}
} else {
None
};

let fut = inner.call(req);
let res: Response<Body> = fut.await.map_err(|err| err.into())?;

// Record metrics if the request is a http RPC request.
if let Some(name) = rpc_name {
if whitelist.contains(&name) {
let req_latency_secs = (Instant::now() - started_at).as_secs_f64();
metrics.requests_by_route.with_label_values(&[&name]).inc();
metrics
.req_latency_by_route
.with_label_values(&[&name])
Expand Down

2 comments on commit ac0dfe8

@vercel
Copy link

@vercel vercel bot commented on ac0dfe8 Feb 2, 2023

Choose a reason for hiding this comment

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

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

4 Validators 500/s Owned Transactions Benchmark Results

Benchmark Report:
+-------------+-----+--------+---------------+---------------+---------------+
| duration(s) | tps | error% | latency (min) | latency (p50) | latency (p99) |
+============================================================================+
| 60          | 500 | 0      | 11            | 24            | 52            |
Stress Performance Report:
+-----------+-----+-----+
| metric    | p50 | p99 |
+=======================+
| cpu usage | 32  | 41  |

4 Validators 500/s Shared Transactions Benchmark Results

Benchmark Report:
+-------------+-----+--------+---------------+---------------+---------------+
| duration(s) | tps | error% | latency (min) | latency (p50) | latency (p99) |
+============================================================================+
| 60          | 496 | 0      | 13            | 431           | 713           |
Stress Performance Report:
+-----------+-----+-----+
| metric    | p50 | p99 |
+=======================+
| cpu usage | 33  | 44  |

20 Validators 50/s Owned Transactions Benchmark Results

Benchmark Report:
+-------------+-----+--------+---------------+---------------+---------------+
| duration(s) | tps | error% | latency (min) | latency (p50) | latency (p99) |
+============================================================================+
| 60          | 148 | 0      | 125           | 620           | 1117          |
Stress Performance Report:
+-----------+-----+-----+
| metric    | p50 | p99 |
+=======================+
| cpu usage | 72  | 85  |

20 Validators 50/s Shared Transactions Benchmark Results

Benchmark Report:
+-------------+-----+--------+---------------+---------------+---------------+
| duration(s) | tps | error% | latency (min) | latency (p50) | latency (p99) |
+============================================================================+
| 60          | 48  | 0      | 357           | 819           | 7771          |
Stress Performance Report:
+-----------+-----+-----+
| metric    | p50 | p99 |
+=======================+
| cpu usage | 61  | 87  |

Narwhal Benchmark Results

 SUMMARY:
-----------------------------------------
 + CONFIG:
 Faults: 0 node(s)
 Committee size: 4 node(s)
 Worker(s) per node: 1 worker(s)
 Collocate primary and workers: True
 Input rate: 50,000 tx/s
 Transaction size: 512 B
 Execution time: 58 s

 Header number of batches threshold: 32 digests
 Header maximum number of batches: 1,000 digests
 Max header delay: 2,000 ms
 GC depth: 50 round(s)
 Sync retry delay: 10,000 ms
 Sync retry nodes: 3 node(s)
 batch size: 500,000 B
 Max batch delay: 200 ms
 Max concurrent requests: 500,000 

 + RESULTS:
 Batch creation avg latency: 77 ms
 Header creation avg latency: 1,901 ms
 	Batch to header avg latency: 1,144 ms
 Header to certificate avg latency: 7 ms
 	Request vote outbound avg latency: 3 ms
 Certificate commit avg latency: 2,856 ms

 Consensus TPS: 48,873 tx/s
 Consensus BPS: 25,023,181 B/s
 Consensus latency: 3,198 ms

 End-to-end TPS: 47,401 tx/s
 End-to-end BPS: 24,269,106 B/s
 End-to-end latency: 4,120 ms
-----------------------------------------

Please sign in to comment.