pub struct TrackConsumersPool<I> { /* private fields */ }
Expand description
A MemoryPool
that tracks the consumers that have
reserved memory within the inner memory pool.
By tracking memory reservations more carefully this pool can provide better error messages on the largest memory users when memory allocation fails.
Tracking is per hashed MemoryConsumer
, not per MemoryReservation
.
The same consumer can have multiple reservations.
§Automatic Usage via RuntimeEnvBuilder
The easiest way to use TrackConsumersPool
is via
RuntimeEnvBuilder::with_memory_limit()
.
§Usage Examples
For more examples of using TrackConsumersPool
, see the memory_pool_tracking.rs example
Implementations§
Source§impl<I: MemoryPool> TrackConsumersPool<I>
impl<I: MemoryPool> TrackConsumersPool<I>
Sourcepub fn new(inner: I, top: NonZeroUsize) -> Self
pub fn new(inner: I, top: NonZeroUsize) -> Self
Creates a new TrackConsumersPool
.
§Arguments
inner
- The underlying memory pool that handles actual memory allocationtop
- The number of top memory consumers to include in error messages
§Note
In most cases, you should use RuntimeEnvBuilder::with_memory_limit()
instead of creating this pool manually, as it automatically sets up tracking with
sensible defaults (top 5 consumers).
§Example
use std::num::NonZeroUsize;
use datafusion_execution::memory_pool::{TrackConsumersPool, GreedyMemoryPool, FairSpillPool};
// Create with a greedy pool backend, reporting top 3 consumers in error messages
let tracked_greedy = TrackConsumersPool::new(
GreedyMemoryPool::new(1024 * 1024), // 1MB limit
NonZeroUsize::new(3).unwrap(),
);
// Create with a fair spill pool backend, reporting top 5 consumers in error messages
let tracked_fair = TrackConsumersPool::new(
FairSpillPool::new(2 * 1024 * 1024), // 2MB limit
NonZeroUsize::new(5).unwrap(),
);
§Impact on Error Messages
The top
determines how many Top K MemoryConsumer
s to include
in the reported DataFusionError::ResourcesExhausted
.
Sourcepub fn report_top(&self, top: usize) -> String
pub fn report_top(&self, top: usize) -> String
Returns a formatted string with the top memory consumers.
Trait Implementations§
Source§impl<I: Debug> Debug for TrackConsumersPool<I>
impl<I: Debug> Debug for TrackConsumersPool<I>
Source§impl<I: MemoryPool> MemoryPool for TrackConsumersPool<I>
impl<I: MemoryPool> MemoryPool for TrackConsumersPool<I>
Source§fn register(&self, consumer: &MemoryConsumer)
fn register(&self, consumer: &MemoryConsumer)
MemoryConsumer
Read moreSource§fn unregister(&self, consumer: &MemoryConsumer)
fn unregister(&self, consumer: &MemoryConsumer)
Source§fn grow(&self, reservation: &MemoryReservation, additional: usize)
fn grow(&self, reservation: &MemoryReservation, additional: usize)
Source§fn shrink(&self, reservation: &MemoryReservation, shrink: usize)
fn shrink(&self, reservation: &MemoryReservation, shrink: usize)
reservation
by shrink
bytesSource§fn memory_limit(&self) -> MemoryLimit
fn memory_limit(&self) -> MemoryLimit
Auto Trait Implementations§
impl<I> !Freeze for TrackConsumersPool<I>
impl<I> !RefUnwindSafe for TrackConsumersPool<I>
impl<I> Send for TrackConsumersPool<I>where
I: Send,
impl<I> Sync for TrackConsumersPool<I>where
I: Sync,
impl<I> Unpin for TrackConsumersPool<I>where
I: Unpin,
impl<I> UnwindSafe for TrackConsumersPool<I>where
I: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more