Struct cadence::AsyncMetricSink [] [src]

pub struct AsyncMetricSink<T: 'static + MetricSink + Send + Sync> { /* fields omitted */ }
Deprecated since 0.10.0

: Replaced with QueuingMetricSink. This will be removed in version 0.11.0

Implementation of a MetricSink that wraps another implementation and uses it to emit metrics asynchronously with a thread pool.

The wrapped implementation can by any thread safe (Send + Sync) MetricSink implementation. Results from the wrapped implementation will be discarded.

Because this MetricSink implementation uses a thread pool, the sink itself cannot be shared between threads. Instead, callers may opt to create a .clone() for each thread that needs to emit metrics. This of course requires that the wrapped sink implements the Clone trait (all of the sinks that are part of Cadence implement Clone).

When cloned, the new instance of this sink will have a cloned thread pool instance that submits jobs to the same worker threads as the original pool and a reference (Arc) to the wrapped sink. If you plan on cloning this sink, the thread pool should be sized appropriately to be used by all expected sink instances.

Methods

impl<T: 'static + MetricSink + Send + Sync> AsyncMetricSink<T>
[src]

Construct a new AsyncMetricSink instance wrapping another sink implementation.

The .emit() method of the wrapped sink will be executed in a different thread via a thread pool. The wrapped sink should be thread safe (Send + Sync).

The default thread pool size is four threads. Callers can use more or fewer threads by making use of the with_threadpool constructor.

UDP Sink Example

In this example we wrap the basic UDP sink to execute it in a different thread.

use std::net::UdpSocket;
use cadence::{UdpMetricSink, AsyncMetricSink, DEFAULT_PORT};

let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
let host = ("metrics.example.com", DEFAULT_PORT);
let udp_sink = UdpMetricSink::from(host, socket).unwrap();
let async_sink = AsyncMetricSink::from(udp_sink);

Buffered UDP Sink Example

This example uses the buffered UDP sink, wrapped in the async metric sink.

use std::net::UdpSocket;
use cadence::{BufferedUdpMetricSink, AsyncMetricSink, DEFAULT_PORT};

let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
let host = ("metrics.example.com", DEFAULT_PORT);
let udp_sink = BufferedUdpMetricSink::from(host, socket).unwrap();
let async_sink = AsyncMetricSink::from(udp_sink);

Construct a new AsyncMetricSink instance wrapping another sink implementation that will use the provided thread pool for asynchronous execution.

The .emit() method of the wrapped sink will be executed in a different thread via a thread pool. The wrapped sink should be thread safe (Send + Sync).

Buffered UDP Sink With a Single Threaded Pool

use std::net::UdpSocket;
use threadpool::ThreadPool;
use cadence::{BufferedUdpMetricSink, AsyncMetricSink, DEFAULT_PORT};

let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
let host = ("metrics.example.com", DEFAULT_PORT);
let udp_sink = BufferedUdpMetricSink::from(host, socket).unwrap();
let async_sink = AsyncMetricSink::with_threadpool(
    udp_sink, ThreadPool::new(1));

Trait Implementations

impl<T: Debug + 'static + MetricSink + Send + Sync> Debug for AsyncMetricSink<T>
[src]

Formats the value using the given formatter.

impl<T: Clone + 'static + MetricSink + Send + Sync> Clone for AsyncMetricSink<T>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T: 'static + MetricSink + Send + Sync> MetricSink for AsyncMetricSink<T>
[src]

Send the Statsd metric using this sink and return the number of bytes written or an I/O error. Read more