Skip to content

Commit

Permalink
Consolidating metrics declaration in storage/seg crate into a single …
Browse files Browse the repository at this point in the history
…module (#483)

* move all seg metrics into its own module, add item_allocate

* moving the last few
  • Loading branch information
Yao Yue authored Oct 25, 2022
1 parent cd08eb5 commit 777b275
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 76 deletions.
23 changes: 0 additions & 23 deletions src/storage/seg/src/hashtable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,29 +82,6 @@ mod hash_bucket;

pub(crate) use hash_bucket::*;

counter!(HASH_TAG_COLLISION, "number of partial hash collisions");
counter!(HASH_INSERT, "number of inserts into the hash table");
counter!(
HASH_INSERT_EX,
"number of hash table inserts which failed, likely due to capacity"
);
counter!(
HASH_REMOVE,
"number of hash table entries which have been removed"
);
counter!(
HASH_LOOKUP,
"total number of lookups against the hash table"
);
counter!(
ITEM_RELINK,
"number of times items have been relinked to different locations"
);
counter!(ITEM_REPLACE, "number of times items have been replaced");
counter!(ITEM_DELETE, "number of items removed from the hash table");
counter!(ITEM_EXPIRE, "number of items removed due to expiration");
counter!(ITEM_EVICT, "number of items removed due to eviction");

#[derive(Debug)]
struct IterState {
bucket_id: usize,
Expand Down
3 changes: 2 additions & 1 deletion src/storage/seg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ extern crate logger;

// external crate includes
use common::time::Seconds;
use rustcommon_metrics::*;

// includes from core/std
use core::hash::{BuildHasher, Hasher};
Expand All @@ -44,6 +43,7 @@ mod error;
mod eviction;
mod hashtable;
mod item;
mod metrics;
mod rand;
mod seg;
mod segments;
Expand Down Expand Up @@ -71,6 +71,7 @@ pub(crate) type Instant = common::time::Instant<Seconds<u32>>;
pub(crate) use crate::rand::*;
pub(crate) use hashtable::*;
pub(crate) use item::*;
pub(crate) use metrics::*;
pub(crate) use segments::*;
pub(crate) use ttl_buckets::*;

Expand Down
79 changes: 79 additions & 0 deletions src/storage/seg/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright 2022 Twitter, Inc.
// Licensed under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0

// All metrics for the Seg crate

use rustcommon_metrics::*;

// segment related
counter!(SEGMENT_REQUEST, "number of segment allocation attempts");
counter!(
SEGMENT_REQUEST_FAILURE,
"number of segment allocation attempts which failed"
);
counter!(
SEGMENT_REQUEST_SUCCESS,
"number of segment allocation attempts which were successful"
);
counter!(SEGMENT_EVICT, "number of segments evicted");
counter!(
SEGMENT_EVICT_EX,
"number of exceptions while evicting segments"
);
counter!(
SEGMENT_RETURN,
"total number of segments returned to the free pool"
);
counter!(SEGMENT_MERGE, "total number of segments merged");
counter!(SEGMENT_CLEAR, "number of segments cleared");
counter!(SEGMENT_EXPIRE, "number of segments expired");
counter!(
CLEAR_TIME,
"amount of time, in nanoseconds, spent clearing segments"
);
counter!(
EXPIRE_TIME,
"amount of time, in nanoseconds, spent expiring segments"
);
gauge!(EVICT_TIME, "time, in nanoseconds, spent evicting segments");
gauge!(SEGMENT_FREE, "current number of free segments");
gauge!(SEGMENT_CURRENT, "current number of segments");

// hash table related
counter!(HASH_TAG_COLLISION, "number of partial hash collisions");
counter!(HASH_INSERT, "number of inserts into the hash table");
counter!(
HASH_INSERT_EX,
"number of hash table inserts which failed, likely due to capacity"
);
counter!(
HASH_REMOVE,
"number of hash table entries which have been removed"
);
counter!(
HASH_LOOKUP,
"total number of lookups against the hash table"
);
counter!(
ITEM_RELINK,
"number of times items have been relinked to different locations"
);

// item related
counter!(ITEM_ALLOCATE, "number of times items have been allocated");
counter!(ITEM_REPLACE, "number of times items have been replaced");
counter!(ITEM_DELETE, "number of items removed from the hash table");
counter!(ITEM_EXPIRE, "number of items removed due to expiration");
counter!(ITEM_EVICT, "number of items removed due to eviction");
counter!(ITEM_COMPACTED, "number of items which have been compacted");
gauge!(ITEM_CURRENT, "current number of live items");
gauge!(
ITEM_CURRENT_BYTES,
"current number of live bytes for storing items"
);
gauge!(ITEM_DEAD, "current number of dead items");
gauge!(
ITEM_DEAD_BYTES,
"current number of dead bytes for storing items"
);
10 changes: 0 additions & 10 deletions src/storage/seg/src/seg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ use std::cmp::min;

const RESERVE_RETRIES: usize = 3;

counter!(SEGMENT_REQUEST, "number of segment allocation attempts");
counter!(
SEGMENT_REQUEST_FAILURE,
"number of segment allocation attempts which failed"
);
counter!(
SEGMENT_REQUEST_SUCCESS,
"number of segment allocation attempts which were successful"
);

/// A pre-allocated key-value store with eager expiration. It uses a
/// segment-structured design that stores data in fixed-size segments, grouping
/// objects with nearby expiration time into the same segment, and lifting most
Expand Down
13 changes: 1 addition & 12 deletions src/storage/seg/src/segments/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@ use super::{SegmentHeader, SegmentsError};
use crate::*;
use core::num::NonZeroU32;

gauge!(ITEM_CURRENT, "current number of live items");
gauge!(
ITEM_CURRENT_BYTES,
"current number of live bytes for storing items"
);
gauge!(ITEM_DEAD, "current number of dead items");
gauge!(
ITEM_DEAD_BYTES,
"current number of dead bytes for storing items"
);
counter!(ITEM_COMPACTED, "number of items which have been compacted");

pub const SEG_MAGIC: u64 = 0xBADC0FFEEBADCAFE;

/// A `Segment` is a contiguous allocation of bytes and an associated header
Expand Down Expand Up @@ -289,6 +277,7 @@ impl<'a> Segment<'a> {
pub(crate) fn alloc_item(&mut self, size: i32) -> RawItem {
let offset = self.write_offset() as usize;
self.incr_item(size);
ITEM_ALLOCATE.increment();
ITEM_CURRENT.increment();
ITEM_CURRENT_BYTES.add(size as _);

Expand Down
15 changes: 0 additions & 15 deletions src/storage/seg/src/segments/segments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,10 @@

use crate::eviction::*;
use crate::item::*;
use crate::seg::{SEGMENT_REQUEST, SEGMENT_REQUEST_SUCCESS};
use crate::segments::*;
use core::num::NonZeroU32;
use datapool::*;

gauge!(EVICT_TIME, "time, in nanoseconds, spent evicting segments");
counter!(SEGMENT_EVICT, "number of segments evicted");
counter!(
SEGMENT_EVICT_EX,
"number of exceptions while evicting segments"
);
counter!(
SEGMENT_RETURN,
"total number of segments returned to the free pool"
);
gauge!(SEGMENT_FREE, "current number of free segments");
counter!(SEGMENT_MERGE, "total number of segments merged");
gauge!(SEGMENT_CURRENT, "current number of segments");

/// `Segments` contain all items within the cache. This struct is a collection
/// of individual `Segment`s which are represented by a `SegmentHeader` and a
/// subslice of bytes from a contiguous heap allocation.
Expand Down
13 changes: 0 additions & 13 deletions src/storage/seg/src/ttl_buckets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,3 @@ mod tests;
pub use error::TtlBucketsError;
pub use ttl_bucket::TtlBucket;
pub use ttl_buckets::TtlBuckets;

use rustcommon_metrics::*;

counter!(SEGMENT_CLEAR, "number of segments cleared");
counter!(SEGMENT_EXPIRE, "number of segments expired");
counter!(
CLEAR_TIME,
"amount of time, in nanoseconds, spent clearing segments"
);
counter!(
EXPIRE_TIME,
"amount of time, in nanoseconds, spent expiring segments"
);
1 change: 0 additions & 1 deletion src/storage/seg/src/ttl_buckets/ttl_bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
//! └──────────────────────────────────────────────────────────┘
//! ```
use super::{SEGMENT_CLEAR, SEGMENT_EXPIRE};
use crate::*;
use core::num::NonZeroU32;

Expand Down
1 change: 0 additions & 1 deletion src/storage/seg/src/ttl_buckets/ttl_buckets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
//! [Segcache paper](https://www.usenix.org/system/files/nsdi21-yang.pdf) for
//! more detail.
use super::{CLEAR_TIME, EXPIRE_TIME};
use crate::*;

const N_BUCKET_PER_STEP_N_BIT: usize = 8;
Expand Down

0 comments on commit 777b275

Please sign in to comment.