Skip to content

Commit 9229266

Browse files
committed
perf(io): use local coalescing limits for local DataFusion reads
Limit local read gaps to 8 KiB and select the existing 4 MiB local request cap for the default DataFusion file reader. Remote stores keep their existing coalescing policy and custom reader factories remain authoritative. Signed-off-by: Joe Isaacs <[email protected]>
1 parent da10665 commit 9229266

3 files changed

Lines changed: 30 additions & 9 deletions

File tree

‎vortex-datafusion/src/persistent/reader.rs‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use datafusion_common::Result as DFResult;
1010
use datafusion_datasource::PartitionedFile;
1111
use object_store::ObjectStore;
1212
use vortex::array::memory::MemorySessionExt;
13+
use vortex::io::CoalesceConfig;
1314
use vortex::io::VortexReadAt;
1415
use vortex::io::object_store::ObjectStoreReadAt;
1516
use vortex::io::session::RuntimeSessionExt;
@@ -43,6 +44,7 @@ pub trait VortexReaderFactory: Debug + Send + Sync + 'static {
4344
#[derive(Debug)]
4445
pub struct DefaultVortexReaderFactory {
4546
object_store: Arc<dyn ObjectStore>,
47+
coalesce_config: Option<CoalesceConfig>,
4648
}
4749

4850
impl DefaultVortexReaderFactory {
@@ -59,7 +61,16 @@ impl DefaultVortexReaderFactory {
5961
/// # let _ = factory;
6062
/// ```
6163
pub fn new(object_store: Arc<dyn ObjectStore>) -> Self {
62-
Self { object_store }
64+
Self {
65+
object_store,
66+
coalesce_config: None,
67+
}
68+
}
69+
70+
/// Sets how nearby read requests are coalesced for this store.
71+
pub fn with_coalesce_config(mut self, config: CoalesceConfig) -> Self {
72+
self.coalesce_config = Some(config);
73+
self
6374
}
6475
}
6576

@@ -69,11 +80,15 @@ impl VortexReaderFactory for DefaultVortexReaderFactory {
6980
file: &PartitionedFile,
7081
session: &VortexSession,
7182
) -> DFResult<Arc<dyn VortexReadAt>> {
72-
Ok(Arc::new(ObjectStoreReadAt::new_with_allocator(
83+
let mut reader = ObjectStoreReadAt::new_with_allocator(
7384
Arc::clone(&self.object_store),
7485
file.path().clone(),
7586
session.handle(),
7687
session.allocator(),
77-
)) as _)
88+
);
89+
if let Some(config) = self.coalesce_config {
90+
reader = reader.with_coalesce_config(config);
91+
}
92+
Ok(Arc::new(reader) as _)
7893
}
7994
}

‎vortex-datafusion/src/persistent/source.rs‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use datafusion_datasource::file_groups::FileGroupPartitioner;
1515
use datafusion_datasource::file_scan_config::FileScanConfig;
1616
use datafusion_datasource::file_stream::FileOpener;
1717
use datafusion_execution::cache::cache_manager::FileMetadataCache;
18+
use datafusion_execution::object_store::ObjectStoreUrl;
1819
use datafusion_physical_expr::DynamicFilterTracking;
1920
use datafusion_physical_expr::EquivalenceProperties;
2021
use datafusion_physical_expr::LexOrdering;
@@ -35,6 +36,7 @@ use object_store::ObjectStore;
3536
use object_store::path::Path;
3637
use vortex::expr::Expression;
3738
use vortex::file::VORTEX_FILE_EXTENSION;
39+
use vortex::io::CoalesceConfig;
3840
use vortex::layout::LayoutReader;
3941
use vortex::layout::scan::v2::WeakScanCache;
4042
use vortex::layout::segments::SegmentSource;
@@ -356,10 +358,13 @@ impl VortexSource {
356358
.clone()
357359
.unwrap_or_else(|| Arc::new(DefaultPhysicalExprAdapterFactory));
358360

359-
let vortex_reader_factory = self
360-
.vortex_reader_factory
361-
.clone()
362-
.unwrap_or_else(|| Arc::new(DefaultVortexReaderFactory::new(object_store)));
361+
let vortex_reader_factory = self.vortex_reader_factory.clone().unwrap_or_else(|| {
362+
let mut factory = DefaultVortexReaderFactory::new(object_store);
363+
if base_config.object_store_url == ObjectStoreUrl::local_filesystem() {
364+
factory = factory.with_coalesce_config(CoalesceConfig::file());
365+
}
366+
Arc::new(factory)
367+
});
363368

364369
let opener = VortexOpener {
365370
partition,

‎vortex-io/src/read_at.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ impl CoalesceConfig {
6969

7070
/// Configuration appropriate for local filesystem access.
7171
pub const fn file() -> Self {
72-
Self::new(1 << 20, 4 << 20) // 1MB distance, 4MB max
72+
// Local reads can afford more requests without copying large gaps between segments.
73+
Self::new(8 * 1024, 4 << 20) // 8KB distance, 4MB max
7374
}
7475

7576
/// Configuration appropriate for object storage (S3, GCS, etc.).
@@ -439,7 +440,7 @@ mod tests {
439440
#[test]
440441
fn test_coalesce_config_file() {
441442
let config = CoalesceConfig::file();
442-
assert_eq!(config.distance, 1 << 20); // 1MB
443+
assert_eq!(config.distance, 8 * 1024); // 8KiB
443444
assert_eq!(config.max_size, 4 << 20); // 4MB
444445
}
445446

0 commit comments

Comments
 (0)