Back to Rerun

re_quota_channel

crates/utils/re_quota_channel/README.md

0.31.41.3 KB
Original Source

re_quota_channel

Part of the Rerun project.

A mpsc channel that applies backpressure based on byte size.

Overview

This crate provides a multi-producer, single-consumer channel that limits throughput based on the total byte size of messages in the channel, rather than just the number of messages.

When the byte capacity is exceeded:

  • Native platforms: The send method blocks until space is available
  • WebAssembly: Blocking is not possible, so a warning is logged and the message is sent anyway

Usage

rust
use re_quota_channel::channel;

// Create a channel with 1MB capacity
let (tx, rx) = channel::<Vec<u8>>("my_channel", 1_000_000);

// Send a message with its size
let data = vec![0u8; 1000];
tx.send(data.clone()).unwrap();

// Receive the message
let received = rx.recv().unwrap();

Special cases

If a message is larger than the total channel capacity, a warning is logged and the channel waits until it's completely empty before sending (to minimize memory usage).