Struct tonic::codec::BufferSettings

source ·
pub struct BufferSettings { /* private fields */ }
Expand description

Settings for how tonic allocates and grows buffers.

Tonic eagerly allocates the buffer_size per RPC, and grows the buffer by buffer_size increments to handle larger messages. Buffer size defaults to 8KiB.

Example:

Buffer start:       | 8kb |
Message received:   |   24612 bytes    |
Buffer grows:       | 8kb | 8kb | 8kb | 8kb |

The buffer grows to the next largest buffer_size increment of 32768 to hold 24612 bytes, which is just slightly too large for the previous buffer increment of 24576.

If you use a smaller buffer size you will waste less memory, but you will allocate more frequently. If one way or the other matters more to you, you may wish to customize your tonic Codec (see codec_buffers example).

Yield threshold is an optimization for streaming rpcs. Sometimes you may have many small messages ready to send. When they are ready, it is a much more efficient use of system resources to batch them together into one larger send(). The yield threshold controls how much you want to bulk up such a batch of ready-to-send messages. The larger your yield threshold the more you will batch - and consequently allocate contiguous memory, which might be relevant if you’re considering large numbers here. If your server streaming rpc does not reach the yield threshold before it reaches Poll::Pending (meaning, it’s waiting for more data from wherever you’re streaming from) then Tonic will just send along a smaller batch. Yield threshold is an upper-bound, it will not affect the responsiveness of your streaming rpc (for reasonable sizes of yield threshold). Yield threshold defaults to 32 KiB.

Implementations§

source§

impl BufferSettings

source

pub fn new(buffer_size: usize, yield_threshold: usize) -> Self

Create a new BufferSettings

Trait Implementations§

source§

impl Clone for BufferSettings

source§

fn clone(&self) -> BufferSettings

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for BufferSettings

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for BufferSettings

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Copy for BufferSettings

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit #126799)
Performs copy-assignment from self to dst. Read more
source§

impl<T> CloneToUninit for T
where T: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit #126799)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FromRef<T> for T
where T: Clone,

source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more