pub struct QueryMemoryLedger { /* private fields */ }Implementations§
Source§impl QueryMemoryLedger
impl QueryMemoryLedger
pub fn new(budget_bytes: NonZeroUsize) -> Self
Sourcepub fn new_with_budget_option(
budget_bytes: NonZeroUsize,
budget_option: &'static str,
) -> Self
pub fn new_with_budget_option( budget_bytes: NonZeroUsize, budget_option: &'static str, ) -> Self
Names the configuration option or runtime grant supplying this limit.
pub fn account( &self, class: QueryMemoryClass, owner: impl Into<Arc<str>>, budget_bytes: NonZeroUsize, ) -> QueryMemoryAccount
Sourcepub fn account_with_budget_option(
&self,
class: QueryMemoryClass,
owner: impl Into<Arc<str>>,
budget_bytes: NonZeroUsize,
budget_option: &'static str,
) -> QueryMemoryAccount
pub fn account_with_budget_option( &self, class: QueryMemoryClass, owner: impl Into<Arc<str>>, budget_bytes: NonZeroUsize, budget_option: &'static str, ) -> QueryMemoryAccount
Creates an account with an explicit origin for its effective byte limit.
Sourcepub fn snapshot(&self) -> QueryMemoryLedgerSnapshot
pub fn snapshot(&self) -> QueryMemoryLedgerSnapshot
Examples found in repository?
examples/spill_resource_probe.rs (line 199)
115fn query(
116 index: usize,
117 rows: usize,
118 width: usize,
119 blocking: usize,
120 barrier: &Barrier,
121 governor: Option<&RuntimeGovernor>,
122) -> Result<Measurement> {
123 let directory =
124 std::env::temp_dir().join(format!("hawdb-spill-probe-{}-{index}", std::process::id()));
125 let memory = ExecutionMemoryConfig {
126 query_memory_bytes: NonZeroUsize::new(16 * 1024 * 1024).unwrap(),
127 blocking_operator_bytes: NonZeroUsize::new(blocking).unwrap(),
128 batch_payload_bytes: NonZeroUsize::new(64 * 1024).unwrap(),
129 max_spill_runs: NonZeroUsize::new(4096).unwrap(),
130 max_total_spill_runs: NonZeroUsize::new(16384).unwrap(),
131 max_spill_bytes: NonZeroU64::new(1024 * 1024 * 1024).unwrap(),
132 min_spill_free_bytes: NonZeroU64::MIN,
133 spill_directory: directory.clone(),
134 ..ExecutionMemoryConfig::default()
135 };
136 let permit = governor.map(|governor| {
137 governor
138 .try_admit(RuntimeWorkRequest::foreground_query(16 * 1024 * 1024, 0))
139 .unwrap()
140 });
141 let task = permit
142 .as_ref()
143 .map(|permit| permit.bind_task_context(RuntimeTaskContext::default()));
144 let ledger = QueryMemoryLedger::for_query(&memory, task.as_ref())?;
145 let observer = QueryExecutionObserver::default();
146 let catalog = Catalog::default();
147 let items = [SortItem {
148 key: SortKey::Column("key".into()),
149 direction: SortDirection::Asc,
150 }];
151 let mut source = Rows { count: rows, width };
152 let mut measurement = Measurement::default();
153 let mut previous = None;
154 barrier.wait();
155 barrier.wait();
156 stream_sort_batches(
157 &PhysicalPlan::EmptyExec,
158 &items,
159 &mut source,
160 BatchExecutionContext {
161 catalog: &catalog,
162 memory: &memory,
163 memory_ledger: &ledger,
164 task_context: task.as_ref(),
165 observer: &observer,
166 },
167 ExecutionLimit::unlimited(),
168 &mut |batch| {
169 for binding in batch {
170 let Value::Int(key) = binding.values["key"] else {
171 panic!("missing key")
172 };
173 let Value::Int(ordinal) = binding.values["ordinal"] else {
174 panic!("missing ordinal")
175 };
176 assert!(
177 previous.is_none_or(|previous| previous < (key, ordinal)),
178 "stable ordering changed"
179 );
180 previous = Some((key, ordinal));
181 let Value::List(payload) = &binding.values["payload"] else {
182 panic!("missing payload")
183 };
184 let Value::Map(payload) = &payload[0] else {
185 panic!("missing payload map")
186 };
187 let Value::String(body) = &payload["body"] else {
188 panic!("missing body")
189 };
190 assert_eq!(body.len(), width);
191 measurement.checksum = measurement.checksum.wrapping_add(ordinal as u64);
192 measurement.rows += 1;
193 }
194 Ok(BatchControl::Continue)
195 },
196 )?;
197 assert_eq!(measurement.rows, rows);
198 assert_eq!(measurement.checksum, (rows as u64) * (rows as u64 - 1) / 2);
199 assert_eq!(ledger.snapshot().used_bytes, 0);
200 assert_eq!(memory.spill_pool_snapshot()?.active_bytes, 0);
201 measurement.ledger_peak = ledger.snapshot().peak_bytes;
202 for report in observer.into_reports().blocking_memory {
203 measurement.spill_bytes += report.spilled_bytes;
204 measurement.runs += report.spill_run_count;
205 }
206 if directory.exists() {
207 std::fs::remove_dir_all(directory).unwrap();
208 }
209 Ok(measurement)
210}Trait Implementations§
Source§impl Clone for QueryMemoryLedger
impl Clone for QueryMemoryLedger
Auto Trait Implementations§
impl Freeze for QueryMemoryLedger
impl RefUnwindSafe for QueryMemoryLedger
impl Send for QueryMemoryLedger
impl Sync for QueryMemoryLedger
impl Unpin for QueryMemoryLedger
impl UnsafeUnpin for QueryMemoryLedger
impl UnwindSafe for QueryMemoryLedger
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
Converts
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> ⓘ
Converts
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