pub struct MemoryController { /* private fields */ }Expand description
Global memory controller for query execution
Manages a shared memory budget across all operators in a query. Thread-safe and supports concurrent reservations.
§Example
use std::sync::Arc;
use vibesql_executor::memory::{MemoryController, MemoryConfig};
let controller = Arc::new(MemoryController::new(MemoryConfig::with_budget(1024 * 1024 * 1024)));
// Create a reservation for a sort operator
let mut reservation = controller.create_reservation();
// Try to reserve memory for sorted runs
assert!(reservation.try_grow(1024 * 1024)); // Should succeed with 1GB budget
assert_eq!(reservation.reserved(), 1024 * 1024);Implementations§
Source§impl MemoryController
impl MemoryController
Sourcepub fn new(config: MemoryConfig) -> Self
pub fn new(config: MemoryConfig) -> Self
Create a new memory controller with the given configuration
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a memory controller with default configuration
Sourcepub fn with_budget(budget_bytes: usize) -> Self
pub fn with_budget(budget_bytes: usize) -> Self
Create a memory controller with a specific budget
Sourcepub fn spill_threshold_bytes(&self) -> usize
pub fn spill_threshold_bytes(&self) -> usize
Get the spill threshold in bytes
Sourcepub fn should_spill(&self) -> bool
pub fn should_spill(&self) -> bool
Check if memory pressure is high (above spill threshold)
Sourcepub fn temp_directory(&self) -> &PathBuf
pub fn temp_directory(&self) -> &PathBuf
Get the temporary directory for spill files
Sourcepub fn target_partition_bytes(&self) -> usize
pub fn target_partition_bytes(&self) -> usize
Get the target partition size for external operators
Sourcepub fn create_reservation(self: &Arc<Self>) -> MemoryReservation
pub fn create_reservation(self: &Arc<Self>) -> MemoryReservation
Create a new memory reservation
Returns a reservation handle that tracks memory for a single operator. When the reservation is dropped, its memory is released.
Sourcepub fn record_spill(&self, bytes: usize)
pub fn record_spill(&self, bytes: usize)
Record that bytes were spilled to disk (for metrics)
Sourcepub fn bytes_spilled(&self) -> usize
pub fn bytes_spilled(&self) -> usize
Get total bytes spilled to disk
Sourcepub fn spill_count(&self) -> usize
pub fn spill_count(&self) -> usize
Get number of spill operations
Sourcepub fn peak_memory(&self) -> usize
pub fn peak_memory(&self) -> usize
Get peak memory usage
Sourcepub fn active_reservations(&self) -> usize
pub fn active_reservations(&self) -> usize
Get number of active reservations
Sourcepub fn stats(&self) -> MemoryStats
pub fn stats(&self) -> MemoryStats
Get comprehensive statistics snapshot
Trait Implementations§
impl Send for MemoryController
impl Sync for MemoryController
Auto Trait Implementations§
impl !Freeze for MemoryController
impl RefUnwindSafe for MemoryController
impl Unpin for MemoryController
impl UnwindSafe for MemoryController
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