Skip to content

Commit

Permalink
instr(buffer): Measure envelope size (#4153)
Browse files Browse the repository at this point in the history
Collect a histogram metric for the size of the envelopes that get pushed
into the envelope buffer. This will help us tune batch sizes for
writing.

We already have a metric for item sizes in the request handler, but we
want one for the entire envelope & restrict it to envelopes that
actually make it to the buffer (exclude rate limited).
  • Loading branch information
jjbayer authored Oct 18, 2024
1 parent 6a76476 commit a100236
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions relay-server/src/services/buffer/envelope_buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use relay_config::Config;
use tokio::time::{timeout, Instant};

use crate::envelope::Envelope;
use crate::envelope::Item;
use crate::services::buffer::common::ProjectKeyPair;
use crate::services::buffer::envelope_stack::sqlite::SqliteEnvelopeStackError;
use crate::services::buffer::envelope_stack::EnvelopeStack;
Expand Down Expand Up @@ -78,6 +79,11 @@ impl PolymorphicEnvelopeBuffer {

/// Adds an envelope to the buffer.
pub async fn push(&mut self, envelope: Box<Envelope>) -> Result<(), EnvelopeBufferError> {
relay_statsd::metric!(
histogram(RelayHistograms::BufferEnvelopeBodySize) =
envelope.items().map(Item::len).sum::<usize>() as u64
);

relay_statsd::metric!(timer(RelayTimers::BufferPush), {
match self {
Self::Sqlite(buffer) => buffer.push(envelope).await,
Expand Down
6 changes: 6 additions & 0 deletions relay-server/src/statsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ pub enum RelayHistograms {
/// Number of envelopes in the backpressure buffer between the envelope buffer
/// and the project cache.
BufferBackpressureEnvelopesCount,
/// The amount of bytes in the item payloads of an envelope pushed to the envelope buffer.
///
/// This is not quite the same as the actual size of a serialized envelope, because it ignores
/// the envelope header and item headers.
BufferEnvelopeBodySize,
/// The number of batches emitted per partition.
BatchesPerPartition,
/// The number of buckets in a batch emitted.
Expand Down Expand Up @@ -309,6 +314,7 @@ impl HistogramMetric for RelayHistograms {
RelayHistograms::BufferBackpressureEnvelopesCount => {
"buffer.backpressure_envelopes_count"
}
RelayHistograms::BufferEnvelopeBodySize => "buffer.envelope_body_size",
RelayHistograms::ProjectStatePending => "project_state.pending",
RelayHistograms::ProjectStateAttempts => "project_state.attempts",
RelayHistograms::ProjectStateRequestBatchSize => "project_state.request.batch_size",
Expand Down

0 comments on commit a100236

Please sign in to comment.