Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions rust/lance-datafusion/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use std::{
collections::HashMap,
fmt::{self, Formatter},
num::NonZero,
sync::{Arc, Mutex, OnceLock},
time::Duration,
};
Expand All @@ -14,7 +15,6 @@ use chrono::{DateTime, Utc};

use arrow_array::RecordBatch;
use arrow_schema::Schema as ArrowSchema;
use datafusion::physical_plan::metrics::MetricType;
use datafusion::{
catalog::streaming::StreamingTable,
dataframe::DataFrame,
Expand All @@ -36,6 +36,7 @@ use datafusion::{
streaming::PartitionStream,
},
};
use datafusion::{execution::memory_pool::TrackConsumersPool, physical_plan::metrics::MetricType};
use datafusion_common::{DataFusionError, Statistics};
use datafusion_physical_expr::{EquivalenceProperties, Partitioning};

Expand Down Expand Up @@ -310,7 +311,7 @@ impl std::fmt::Debug for LanceExecutionOptions {
}
}

const DEFAULT_LANCE_MEM_POOL_SIZE_PER_PARTITION: u64 = 100 * 1024 * 1024;
const DEFAULT_LANCE_MEM_POOL_SIZE_PER_PARTITION: u64 = 150 * 1024 * 1024;
const DEFAULT_LANCE_MAX_TEMP_DIRECTORY_SIZE: u64 = 100 * 1024 * 1024 * 1024; // 100GB

impl LanceExecutionOptions {
Expand Down Expand Up @@ -366,12 +367,21 @@ pub fn new_session_context(options: &LanceExecutionOptions) -> SessionContext {
session_config = session_config.with_target_partitions(target_partition);
}
if options.use_spilling() {
// The default 10MB sort spill reservation seems to be too small for many common cases.
//
// There currently is no reasonable guidance provided by DataFusion for setting this value.
// We bump this to 40MB but try a smaller value if the mem pool is small.
let sort_spill_reservation_bytes =
(options.mem_pool_size() / 3).min(40 * 1024 * 1024) as usize;
session_config =
session_config.with_sort_spill_reservation_bytes(sort_spill_reservation_bytes);
let disk_manager_builder = DiskManagerBuilder::default()
.with_max_temp_directory_size(options.max_temp_directory_size());
runtime_env_builder = runtime_env_builder
.with_disk_manager_builder(disk_manager_builder)
.with_memory_pool(Arc::new(FairSpillPool::new(
options.mem_pool_size() as usize
.with_memory_pool(Arc::new(TrackConsumersPool::new(
FairSpillPool::new(options.mem_pool_size() as usize),
NonZero::try_from(16).unwrap(),
)));
}
let runtime_env = runtime_env_builder.build_arc().unwrap();
Expand Down
Loading