Skip to content
Merged
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
23 changes: 20 additions & 3 deletions stress/src/metrics_histogram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,30 @@ lazy_static! {
thread_local! {
/// Store random number generator for each thread
static CURRENT_RNG: RefCell<rngs::SmallRng> = RefCell::new(rngs::SmallRng::from_entropy());

static PROVIDER_PER_THREAD: SdkMeterProvider = SdkMeterProvider::builder()
.with_reader(ManualReader::builder().build())
Copy link
Member

Choose a reason for hiding this comment

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

will need to try one with PeriodicReader and see how it impacts resources, given its going to spawn new thread for each instance.

.build();

static HISTOGRAM_PER_THREAD: Histogram<u64> = PROVIDER_PER_THREAD.with(|h|h.meter("test").u64_histogram("hello").build());
}

fn main() {
throughput::test_throughput(test_histogram);
match std::env::args().find(|arg| arg == "--per-thread") {
None => throughput::test_throughput(test_histogram_shared),
Some(_) => throughput::test_throughput(test_histogram_per_thread),
}
}

fn test_histogram_shared() {
test_histogram(&HISTOGRAM);
}

fn test_histogram_per_thread() {
HISTOGRAM_PER_THREAD.with(|h| test_histogram(h));
}

fn test_histogram() {
fn test_histogram(histogram: &Histogram<u64>) {
let len = ATTRIBUTE_VALUES.len();
let rands = CURRENT_RNG.with(|rng| {
let mut rng = rng.borrow_mut();
Expand All @@ -58,7 +75,7 @@ fn test_histogram() {
let index_third_attribute = rands[2];

// each attribute has 10 possible values, so there are 1000 possible combinations (time-series)
HISTOGRAM.record(
histogram.record(
1,
&[
KeyValue::new("attribute1", ATTRIBUTE_VALUES[index_first_attribute]),
Expand Down