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

Use linear buckets in some places #3384

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions linera-base/src/data_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
use thiserror::Error;

#[cfg(with_metrics)]
use crate::prometheus_util::{bucket_latencies, register_histogram_vec, MeasureLatency};
use crate::prometheus_util::{
exponential_bucket_latencies, register_histogram_vec, MeasureLatency,
};
use crate::{
crypto::{BcsHashable, CryptoHash},
doc_scalar, hex_debug, http,
Expand Down Expand Up @@ -1168,7 +1170,7 @@ static BYTECODE_COMPRESSION_LATENCY: LazyLock<HistogramVec> = LazyLock::new(|| {
"bytecode_compression_latency",
"Bytecode compression latency",
&[],
bucket_latencies(10.0),
exponential_bucket_latencies(10.0),
)
});

Expand All @@ -1179,7 +1181,7 @@ static BYTECODE_DECOMPRESSION_LATENCY: LazyLock<HistogramVec> = LazyLock::new(||
"bytecode_decompression_latency",
"Bytecode decompression latency",
&[],
bucket_latencies(10.0),
exponential_bucket_latencies(10.0),
)
});

Expand Down
29 changes: 22 additions & 7 deletions linera-base/src/prometheus_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
//! This module defines utility functions for interacting with Prometheus (logging metrics, etc)
use prometheus::{
exponential_buckets, histogram_opts, register_histogram_vec, register_int_counter_vec,
HistogramVec, IntCounterVec, Opts,
exponential_buckets, histogram_opts, linear_buckets, register_histogram_vec,
register_int_counter_vec, HistogramVec, IntCounterVec, Opts,
};

use crate::time::Instant;
Expand Down Expand Up @@ -38,8 +38,8 @@ pub fn register_histogram_vec(
register_histogram_vec!(histogram_opts, label_names).expect("Histogram can be created")
}

/// Construct the bucket interval starting from a value and an ending value.
pub fn bucket_interval(start_value: f64, end_value: f64) -> Option<Vec<f64>> {
/// Construct the bucket interval exponentially starting from a value and an ending value.
pub fn exponential_bucket_interval(start_value: f64, end_value: f64) -> Option<Vec<f64>> {
let quot = end_value / start_value;
let factor = 3.0_f64;
let count_approx = quot.ln() / factor.ln();
Expand All @@ -54,9 +54,24 @@ pub fn bucket_interval(start_value: f64, end_value: f64) -> Option<Vec<f64>> {
Some(buckets)
}

/// Construct the latencies starting from 0.0001 and ending at the maximum latency
pub fn bucket_latencies(max_latency: f64) -> Option<Vec<f64>> {
bucket_interval(0.0001_f64, max_latency)
/// Construct the latencies exponentially starting from 0.001 and ending at the maximum latency
pub fn exponential_bucket_latencies(max_latency: f64) -> Option<Vec<f64>> {
exponential_bucket_interval(0.001_f64, max_latency)
}

/// Construct the bucket interval linearly starting from a value and an ending value.
pub fn linear_bucket_interval(start_value: f64, width: f64, end_value: f64) -> Option<Vec<f64>> {
let count = (end_value - start_value) / width;
let count = count.ceil() as usize;
Some(
linear_buckets(start_value, width, count)
.expect("Linear buckets creation should not fail!"),
)
}

/// Construct the latencies linearly starting from 1 and ending at the maximum latency
pub fn linear_bucket_latencies(max_latency: f64) -> Option<Vec<f64>> {
linear_bucket_interval(1.0, 50.0, max_latency)
}

/// A guard for an active latency measurement.
Expand Down
20 changes: 10 additions & 10 deletions linera-chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ mod chain_tests;
#[cfg(with_metrics)]
use {
linera_base::prometheus_util::{
bucket_interval, bucket_latencies, register_histogram_vec, register_int_counter_vec,
MeasureLatency,
exponential_bucket_interval, exponential_bucket_latencies, register_histogram_vec,
register_int_counter_vec, MeasureLatency,
},
prometheus::{HistogramVec, IntCounterVec},
};
Expand All @@ -77,7 +77,7 @@ static BLOCK_EXECUTION_LATENCY: LazyLock<HistogramVec> = LazyLock::new(|| {
"block_execution_latency",
"Block execution latency",
&[],
bucket_latencies(50.0),
exponential_bucket_latencies(50.0),
)
});

Expand All @@ -87,7 +87,7 @@ static MESSAGE_EXECUTION_LATENCY: LazyLock<HistogramVec> = LazyLock::new(|| {
"message_execution_latency",
"Message execution latency",
&[],
bucket_latencies(2.5),
exponential_bucket_latencies(2.5),
)
});

Expand All @@ -97,7 +97,7 @@ static OPERATION_EXECUTION_LATENCY: LazyLock<HistogramVec> = LazyLock::new(|| {
"operation_execution_latency",
"Operation execution latency",
&[],
bucket_latencies(2.5),
exponential_bucket_latencies(2.5),
)
});

Expand All @@ -107,7 +107,7 @@ static WASM_FUEL_USED_PER_BLOCK: LazyLock<HistogramVec> = LazyLock::new(|| {
"wasm_fuel_used_per_block",
"Wasm fuel used per block",
&[],
bucket_interval(10.0, 500_000.0),
exponential_bucket_interval(10.0, 500_000.0),
)
});

Expand All @@ -117,7 +117,7 @@ static WASM_NUM_READS_PER_BLOCK: LazyLock<HistogramVec> = LazyLock::new(|| {
"wasm_num_reads_per_block",
"Wasm number of reads per block",
&[],
bucket_interval(0.1, 100.0),
exponential_bucket_interval(0.1, 100.0),
)
});

Expand All @@ -127,7 +127,7 @@ static WASM_BYTES_READ_PER_BLOCK: LazyLock<HistogramVec> = LazyLock::new(|| {
"wasm_bytes_read_per_block",
"Wasm number of bytes read per block",
&[],
bucket_interval(0.1, 10_000_000.0),
exponential_bucket_interval(0.1, 10_000_000.0),
)
});

Expand All @@ -137,7 +137,7 @@ static WASM_BYTES_WRITTEN_PER_BLOCK: LazyLock<HistogramVec> = LazyLock::new(|| {
"wasm_bytes_written_per_block",
"Wasm number of bytes written per block",
&[],
bucket_interval(0.1, 10_000_000.0),
exponential_bucket_interval(0.1, 10_000_000.0),
)
});

Expand All @@ -147,7 +147,7 @@ static STATE_HASH_COMPUTATION_LATENCY: LazyLock<HistogramVec> = LazyLock::new(||
"state_hash_computation_latency",
"Time to recompute the state hash",
&[],
bucket_latencies(5.0),
exponential_bucket_latencies(5.0),
)
});

Expand Down
12 changes: 6 additions & 6 deletions linera-core/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ mod client_tests;
mod metrics {
use std::sync::LazyLock;

use linera_base::prometheus_util::{bucket_latencies, register_histogram_vec};
use linera_base::prometheus_util::{exponential_bucket_latencies, register_histogram_vec};
use prometheus::HistogramVec;

pub static PROCESS_INBOX_WITHOUT_PREPARE_LATENCY: LazyLock<HistogramVec> =
Expand All @@ -103,7 +103,7 @@ mod metrics {
"process_inbox_latency",
"process_inbox latency",
&[],
bucket_latencies(500.0),
exponential_bucket_latencies(500.0),
)
});

Expand All @@ -112,7 +112,7 @@ mod metrics {
"prepare_chain_latency",
"prepare_chain latency",
&[],
bucket_latencies(500.0),
exponential_bucket_latencies(500.0),
)
});

Expand All @@ -121,7 +121,7 @@ mod metrics {
"synchronize_chain_state_latency",
"synchronize_chain_state latency",
&[],
bucket_latencies(500.0),
exponential_bucket_latencies(500.0),
)
});

Expand All @@ -130,7 +130,7 @@ mod metrics {
"execute_block_latency",
"execute_block latency",
&[],
bucket_latencies(500.0),
exponential_bucket_latencies(500.0),
)
});

Expand All @@ -139,7 +139,7 @@ mod metrics {
"find_received_certificates_latency",
"find_received_certificates latency",
&[],
bucket_latencies(500.0),
exponential_bucket_latencies(500.0),
)
});
}
Expand Down
6 changes: 3 additions & 3 deletions linera-core/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use tracing::{error, instrument, trace, warn, Instrument as _};
#[cfg(with_metrics)]
use {
linera_base::prometheus_util::{
bucket_interval, register_histogram_vec, register_int_counter_vec,
exponential_bucket_interval, register_histogram_vec, register_int_counter_vec,
},
prometheus::{HistogramVec, IntCounterVec},
std::sync::LazyLock,
Expand All @@ -66,7 +66,7 @@ static NUM_ROUNDS_IN_CERTIFICATE: LazyLock<HistogramVec> = LazyLock::new(|| {
"num_rounds_in_certificate",
"Number of rounds in certificate",
&["certificate_value", "round_type"],
bucket_interval(0.1, 50.0),
exponential_bucket_interval(0.1, 50.0),
)
});

Expand All @@ -76,7 +76,7 @@ static NUM_ROUNDS_IN_BLOCK_PROPOSAL: LazyLock<HistogramVec> = LazyLock::new(|| {
"num_rounds_in_block_proposal",
"Number of rounds in block proposal",
&["round_type"],
bucket_interval(0.1, 50.0),
exponential_bucket_interval(0.1, 50.0),
)
});

Expand Down
8 changes: 5 additions & 3 deletions linera-execution/src/execution_state_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use std::sync::LazyLock;
use custom_debug_derive::Debug;
use futures::channel::mpsc;
#[cfg(with_metrics)]
use linera_base::prometheus_util::{bucket_latencies, register_histogram_vec, MeasureLatency as _};
use linera_base::prometheus_util::{
exponential_bucket_latencies, register_histogram_vec, MeasureLatency as _,
};
use linera_base::{
data_types::{Amount, ApplicationPermissions, BlobContent, Timestamp},
hex_debug, hex_vec_debug, http,
Expand Down Expand Up @@ -37,7 +39,7 @@ static LOAD_CONTRACT_LATENCY: LazyLock<HistogramVec> = LazyLock::new(|| {
"load_contract_latency",
"Load contract latency",
&[],
bucket_latencies(250.0),
exponential_bucket_latencies(250.0),
)
});

Expand All @@ -48,7 +50,7 @@ static LOAD_SERVICE_LATENCY: LazyLock<HistogramVec> = LazyLock::new(|| {
"load_service_latency",
"Load service latency",
&[],
bucket_latencies(250.0),
exponential_bucket_latencies(250.0),
)
});

Expand Down
8 changes: 5 additions & 3 deletions linera-execution/src/revm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ use revm_primitives::{ExecutionResult, HaltReason, Log, Output, TxKind};
use thiserror::Error;
#[cfg(with_metrics)]
use {
linera_base::prometheus_util::{bucket_latencies, register_histogram_vec, MeasureLatency as _},
linera_base::prometheus_util::{
exponential_bucket_latencies, register_histogram_vec, MeasureLatency as _,
},
prometheus::HistogramVec,
std::sync::LazyLock,
};
Expand Down Expand Up @@ -59,7 +61,7 @@ static CONTRACT_INSTANTIATION_LATENCY: LazyLock<HistogramVec> = LazyLock::new(||
"evm_contract_instantiation_latency",
"Evm contract instantiation latency",
&[],
bucket_latencies(1.0),
exponential_bucket_latencies(1.0),
)
});

Expand All @@ -69,7 +71,7 @@ static SERVICE_INSTANTIATION_LATENCY: LazyLock<HistogramVec> = LazyLock::new(||
"evm_service_instantiation_latency",
"Evm service instantiation latency",
&[],
bucket_latencies(1.0),
exponential_bucket_latencies(1.0),
)
});

Expand Down
8 changes: 5 additions & 3 deletions linera-execution/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ use wasmer::{WasmerContractInstance, WasmerServiceInstance};
use wasmtime::{WasmtimeContractInstance, WasmtimeServiceInstance};
#[cfg(with_metrics)]
use {
linera_base::prometheus_util::{bucket_latencies, register_histogram_vec, MeasureLatency as _},
linera_base::prometheus_util::{
exponential_bucket_latencies, register_histogram_vec, MeasureLatency as _,
},
prometheus::HistogramVec,
std::sync::LazyLock,
};
Expand All @@ -49,7 +51,7 @@ static CONTRACT_INSTANTIATION_LATENCY: LazyLock<HistogramVec> = LazyLock::new(||
"wasm_contract_instantiation_latency",
"Wasm contract instantiation latency",
&[],
bucket_latencies(1.0),
exponential_bucket_latencies(1.0),
)
});

Expand All @@ -59,7 +61,7 @@ static SERVICE_INSTANTIATION_LATENCY: LazyLock<HistogramVec> = LazyLock::new(||
"wasm_service_instantiation_latency",
"Wasm service instantiation latency",
&[],
bucket_latencies(1.0),
exponential_bucket_latencies(1.0),
)
});

Expand Down
6 changes: 3 additions & 3 deletions linera-rpc/src/grpc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use tracing::{debug, error, info, instrument, trace, warn};
#[cfg(with_metrics)]
use {
linera_base::prometheus_util::{
bucket_interval, register_histogram_vec, register_int_counter_vec,
linear_bucket_interval, register_histogram_vec, register_int_counter_vec,
},
prometheus::{HistogramVec, IntCounterVec},
};
Expand Down Expand Up @@ -63,7 +63,7 @@ static SERVER_REQUEST_LATENCY: LazyLock<HistogramVec> = LazyLock::new(|| {
"server_request_latency",
"Server request latency",
&[],
bucket_interval(1.0, 200.0),
linear_bucket_interval(1.0, 25.0, 200.0),
)
});

Expand Down Expand Up @@ -95,7 +95,7 @@ static SERVER_REQUEST_LATENCY_PER_REQUEST_TYPE: LazyLock<HistogramVec> = LazyLoc
"server_request_latency_per_request_type",
"Server request latency per request type",
&["method_name"],
bucket_interval(1.0, 200.0),
linear_bucket_interval(1.0, 25.0, 200.0),
)
});

Expand Down
4 changes: 2 additions & 2 deletions linera-service/src/proxy/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use tracing::{debug, info, instrument, Instrument as _, Level};
#[cfg(with_metrics)]
use {
linera_base::prometheus_util::{
bucket_interval, register_histogram_vec, register_int_counter_vec,
linear_bucket_interval, register_histogram_vec, register_int_counter_vec,
},
prometheus::{HistogramVec, IntCounterVec},
};
Expand All @@ -71,7 +71,7 @@ static PROXY_REQUEST_LATENCY: LazyLock<HistogramVec> = LazyLock::new(|| {
"proxy_request_latency",
"Proxy request latency",
&[],
bucket_interval(1.0, 500.0),
linear_bucket_interval(1.0, 50.0, 500.0),
)
});

Expand Down
5 changes: 3 additions & 2 deletions linera-storage/src/db_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ use {
#[cfg(with_metrics)]
use {
linera_base::prometheus_util::{
bucket_latencies, register_histogram_vec, register_int_counter_vec, MeasureLatency,
exponential_bucket_latencies, register_histogram_vec, register_int_counter_vec,
MeasureLatency,
},
prometheus::{HistogramVec, IntCounterVec},
};
Expand Down Expand Up @@ -181,7 +182,7 @@ pub static LOAD_CHAIN_LATENCY: LazyLock<HistogramVec> = LazyLock::new(|| {
"load_chain_latency",
"The latency to load a chain state",
&[],
bucket_latencies(1.0),
exponential_bucket_latencies(1.0),
)
});

Expand Down
Loading