Browse Source

benchmarks for how long influx.send(..) takes in different situations

master
Jonathan Strong 3 years ago
parent
commit
e6f35d6a61
2 changed files with 66 additions and 3 deletions
  1. +3
    -0
      justfile
  2. +63
    -3
      src/lib.rs

+ 3
- 0
justfile View File

@@ -7,6 +7,9 @@ cargo +args='':
check +args='': check +args='':
@just cargo check {{args}} @just cargo check {{args}}


bench +args='':
@just cargo bench {{args}}

build name +args='': build name +args='':
@just cargo build --bin {{name}} {{args}} @just cargo build --bin {{name}} {{args}}




+ 63
- 3
src/lib.rs View File

@@ -302,7 +302,6 @@ impl Default for InfluxWriter {


impl Clone for InfluxWriter { impl Clone for InfluxWriter {
fn clone(&self) -> Self { fn clone(&self) -> Self {
debug_assert!(self.thread.is_some());
let thread = self.thread.as_ref().map(|x| Arc::clone(x)); let thread = self.thread.as_ref().map(|x| Arc::clone(x));
InfluxWriter { InfluxWriter {
host: self.host.to_string(), host: self.host.to_string(),
@@ -322,7 +321,12 @@ impl InfluxWriter {
/// ///
#[inline] #[inline]
pub fn send(&self, m: OwnedMeasurement) -> Result<(), SendError<Option<OwnedMeasurement>>> { pub fn send(&self, m: OwnedMeasurement) -> Result<(), SendError<Option<OwnedMeasurement>>> {
self.tx.send(Some(m))
//if self.thread.is_none() {
// let _ = self.tx.try_send(Some(m));
// Ok(())
//} else {
self.tx.send(Some(m))
//}
} }


#[inline] #[inline]
@@ -354,8 +358,9 @@ impl InfluxWriter {
#[inline] #[inline]
pub fn is_full(&self) -> bool { self.tx.is_full() } pub fn is_full(&self) -> bool { self.tx.is_full() }


/// provides a shell interface that immediately drops measurements sent to it
pub fn placeholder() -> Self { pub fn placeholder() -> Self {
let (tx, _) = bounded(1024);
let (tx, _) = bounded(1);
Self { Self {
host: String::new(), host: String::new(),
db: String::new(), db: String::new(),
@@ -364,6 +369,10 @@ impl InfluxWriter {
} }
} }


pub fn is_placeholder(&self) -> bool {
self.thread.is_none() && self.host == ""
}

pub fn new(host: &str, db: &str) -> Self { pub fn new(host: &str, db: &str) -> Self {
let noop_logger = slog::Logger::root(slog::Discard.fuse(), o!()); let noop_logger = slog::Logger::root(slog::Discard.fuse(), o!());
Self::with_logger_and_opt_creds(host, db, None, &noop_logger) Self::with_logger_and_opt_creds(host, db, None, &noop_logger)
@@ -1166,6 +1175,57 @@ mod tests {
#[cfg(feature = "unstable")] #[cfg(feature = "unstable")]
use test::{black_box, Bencher}; use test::{black_box, Bencher};



#[cfg(feature = "unstable")]
#[bench]
fn send_to_disconnected_channel(b: &mut Bencher) {
let (tx, _): (Sender<Option<OwnedMeasurement>>, Receiver<Option<OwnedMeasurement>>) = bounded(1);
let time = now();
b.iter(|| {
const VERSION: &str = "1.0.0";
let color = "red";
let m = measure!(@make_meas test, i(n, 1), t(color), v(VERSION), tm(time));
tx.send(Some(m))
})
}

#[cfg(feature = "unstable")]
#[bench]
fn try_send_to_disconnected_channel(b: &mut Bencher) {
let (tx, _): (Sender<Option<OwnedMeasurement>>, Receiver<Option<OwnedMeasurement>>) = bounded(1);
let time = now();
b.iter(|| {
const VERSION: &str = "1.0.0";
let color = "red";
let m = measure!(@make_meas test, i(n, 1), t(color), v(VERSION), tm(time));
tx.try_send(Some(m))
})
}

#[cfg(feature = "unstable")]
#[bench]
fn send_to_disconnected_channel_via_placeholder(b: &mut Bencher) {
let time = now();
let influx = InfluxWriter::placeholder();
b.iter(|| {
const VERSION: &str = "1.0.0";
let color = "red";
measure!(influx, test, i(n, 1), t(color), v(VERSION), tm(time));
})
}

#[cfg(feature = "unstable")]
#[bench]
fn send_to_connected_channel_via_measure(b: &mut Bencher) {
let time = now();
let influx = InfluxWriter::new("localhost", "test");
b.iter(|| {
const VERSION: &str = "1.0.0";
let color = "red";
measure!(influx, bench, i(n, 1), t(color), v(VERSION), tm(time));
})
}

#[ignore] #[ignore]
#[cfg(feature = "unstable")] #[cfg(feature = "unstable")]
#[bench] #[bench]


Loading…
Cancel
Save