You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "geoffreyclaude (via GitHub)" <gi...@apache.org> on 2025/02/27 13:50:25 UTC

[PR] Fix sequential metadata fetching in ListingTable causing high latency [datafusion]

geoffreyclaude opened a new pull request, #14918:
URL: https://github.com/apache/datafusion/pull/14918

   ## Which issue does this PR close?
   
   - Closes #14916.
   
   ## Rationale for this change
   
   When scanning an exact list of remote Parquet files, the ListingTable was fetching file metadata (via head calls) sequentially. This was due to using `stream::iter(file_list).flatten()`, which processes each one-item stream in order. For remote blob stores, where each head call can take tens to hundreds of milliseconds, this sequential behavior significantly increased the time to create the physical plan.
   
   ## What changes are included in this PR?
   
   This commit replaces the sequential flattening with concurrent merging using `futures::stream::select_all(file_list)`. With this change, the `head` requests are executed in parallel (up to the configured `meta_fetch_concurrency` limit), reducing latency when creating the physical plan.
   
   ## Are these changes tested?
   
   Tests have been updated to ensure that metadata fetching occurs concurrently.
   
   ## Are there any user-facing changes?
   
   No user-facing changes besides reducing the latency in this particular situation.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix sequential metadata fetching in ListingTable causing high latency [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #14918:
URL: https://github.com/apache/datafusion/pull/14918#issuecomment-2690454212

   I pushed a commit to fix the formatting


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix sequential metadata fetching in ListingTable causing high latency [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #14918:
URL: https://github.com/apache/datafusion/pull/14918#discussion_r1975867484


##########
datafusion/core/src/test/object_store.rs:
##########
@@ -61,3 +71,121 @@ pub fn local_unpartitioned_file(path: impl AsRef<std::path::Path>) -> ObjectMeta
         version: None,
     }
 }
+
+/// Blocks the object_store `head` call until `concurrency` number of calls are pending.
+pub fn ensure_head_concurrency(
+    object_store: Arc<dyn ObjectStore>,
+    concurrency: usize,
+) -> Arc<dyn ObjectStore> {
+    Arc::new(BlockingObjectStore::new(object_store, concurrency))
+}
+
+/// An object store that “blocks” in its `head` call until an expected number of concurrent calls are reached.
+#[derive(Debug)]
+struct BlockingObjectStore {
+    inner: Arc<dyn ObjectStore>,
+    barrier: Arc<Barrier>,
+}
+
+impl BlockingObjectStore {
+    const NAME: &'static str = "BlockingObjectStore";
+    fn new(inner: Arc<dyn ObjectStore>, expected_concurrency: usize) -> Self {
+        Self {
+            inner,
+            barrier: Arc::new(Barrier::new(expected_concurrency)),
+        }
+    }
+}
+
+impl Display for BlockingObjectStore {
+    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+        Display::fmt(&self.inner, f)
+    }
+}
+
+/// All trait methods are forwarded to the inner object store, except for
+/// the `head` method which waits until the expected number of concurrent calls is reached.
+#[async_trait::async_trait]
+impl ObjectStore for BlockingObjectStore {
+    async fn put_opts(
+        &self,
+        location: &Path,
+        payload: PutPayload,
+        opts: PutOptions,
+    ) -> object_store::Result<PutResult> {
+        self.inner.put_opts(location, payload, opts).await
+    }
+    async fn put_multipart_opts(
+        &self,
+        location: &Path,
+        opts: PutMultipartOpts,
+    ) -> object_store::Result<Box<dyn MultipartUpload>> {
+        self.inner.put_multipart_opts(location, opts).await
+    }
+
+    async fn get_opts(
+        &self,
+        location: &Path,
+        options: GetOptions,
+    ) -> object_store::Result<GetResult> {
+        self.inner.get_opts(location, options).await
+    }
+
+    async fn head(&self, location: &Path) -> object_store::Result<ObjectMeta> {
+        println!(
+            "{} received head call for {location}",
+            BlockingObjectStore::NAME
+        );
+        // Wait until the expected number of concurrent calls is reached, but timeout after 1 second to avoid hanging failing tests.

Review Comment:
   👍 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix sequential metadata fetching in ListingTable causing high latency [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #14918:
URL: https://github.com/apache/datafusion/pull/14918#issuecomment-2694607224

   I tried to verify these changes but I couldn't figure out how to create an external table with explicitly listing the names via SQL.
   
   For posterity here is what I tried:
   
   
   This PR:
   ```
   > create external table hits stored as parquet OPTIONS('aws.region' 'eu-central-1') location 's3://clickhouse-public-datasets/hits_compatible/athena_partitioned/';
   0 row(s) fetched.
   Elapsed 2.690 seconds.
   ```
   
   Main
   ```
   > create external table hits stored as parquet OPTIONS('aws.region' 'eu-central-1') location 's3://clickhouse-public-datasets/hits_compatible/athena_partitioned/';
   0 row(s) fetched.
   Elapsed 2.284 seconds.
   ```
   
   I am going to try and whip up a smaller reproducer


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix sequential metadata fetching in ListingTable causing high latency [datafusion]

Posted by "geoffreyclaude (via GitHub)" <gi...@apache.org>.
geoffreyclaude commented on code in PR #14918:
URL: https://github.com/apache/datafusion/pull/14918#discussion_r1973621866


##########
datafusion/core/src/datasource/listing/table.rs:
##########
@@ -1098,7 +1098,7 @@ impl ListingTable {
             )
         }))
         .await?;
-        let file_list = stream::iter(file_list).flatten();
+        let file_list = futures::stream::select_all(file_list);

Review Comment:
   This is the actual fix, the rest of the changes are unit tests.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix sequential metadata fetching in ListingTable causing high latency [datafusion]

Posted by "geoffreyclaude (via GitHub)" <gi...@apache.org>.
geoffreyclaude commented on PR #14918:
URL: https://github.com/apache/datafusion/pull/14918#issuecomment-2694756767

   > I tried to verify these changes but I couldn't figure out how to create an external table with explicitly listing the names via SQL.
   > 
   > For posterity here is what I tried:
   > 
   > This PR:
   > 
   > ```
   > > create external table hits stored as parquet OPTIONS('aws.region' 'eu-central-1') location 's3://clickhouse-public-datasets/hits_compatible/athena_partitioned/';
   > 0 row(s) fetched.
   > Elapsed 2.690 seconds.
   > ```
   > 
   > Main
   > 
   > ```
   > > create external table hits stored as parquet OPTIONS('aws.region' 'eu-central-1') location 's3://clickhouse-public-datasets/hits_compatible/athena_partitioned/';
   > 0 row(s) fetched.
   > Elapsed 2.284 seconds.
   > ```
   > 
   > I am going to try and whip up a smaller reproducer
   
   We got there through Substrait, by converting a custom input into a `ParquetExec`... So not the most straightforward one-line reproducer unfortunately!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix sequential metadata fetching in ListingTable causing high latency [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #14918:
URL: https://github.com/apache/datafusion/pull/14918


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix sequential metadata fetching in ListingTable causing high latency [datafusion]

Posted by "geoffreyclaude (via GitHub)" <gi...@apache.org>.
geoffreyclaude commented on code in PR #14918:
URL: https://github.com/apache/datafusion/pull/14918#discussion_r1974270286


##########
datafusion/core/src/datasource/listing/table.rs:
##########
@@ -1098,7 +1098,9 @@ impl ListingTable {
             )
         }))
         .await?;
-        let file_list = stream::iter(file_list).flatten();
+        let meta_fetch_concurrency =
+            ctx.config_options().execution.meta_fetch_concurrency;
+        let file_list = stream::iter(file_list).flatten_unordered(meta_fetch_concurrency);

Review Comment:
   This is the actual fix, the rest of the changes are unit tests.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix sequential metadata fetching in ListingTable causing high latency [datafusion]

Posted by "geoffreyclaude (via GitHub)" <gi...@apache.org>.
geoffreyclaude commented on code in PR #14918:
URL: https://github.com/apache/datafusion/pull/14918#discussion_r1974271100


##########
datafusion/core/src/datasource/listing/table.rs:
##########
@@ -1115,7 +1117,7 @@ impl ListingTable {
                 }
             })
             .boxed()
-            .buffered(ctx.config_options().execution.meta_fetch_concurrency);
+            .buffered_unordered(ctx.config_options().execution.meta_fetch_concurrency);

Review Comment:
   Ordering does not matter, so might as well use `buffered_unordered` to avoid stalling on an outlier.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix sequential metadata fetching in ListingTable causing high latency [datafusion]

Posted by "geoffreyclaude (via GitHub)" <gi...@apache.org>.
geoffreyclaude commented on code in PR #14918:
URL: https://github.com/apache/datafusion/pull/14918#discussion_r1974061938


##########
datafusion/core/src/datasource/listing/table.rs:
##########
@@ -1098,7 +1098,7 @@ impl ListingTable {
             )
         }))
         .await?;
-        let file_list = stream::iter(file_list).flatten();
+        let file_list = futures::stream::select_all(file_list);

Review Comment:
   Is the following a better alternative? And do we care about ordering here?
   ```rust
   let meta_fetch_concurrency = ctx.config_options().execution.meta_fetch_concurrency;
   let file_list = futures::stream::iter(file_list).flatten_unordered(meta_fetch_concurrency);
   ```



##########
datafusion/core/src/datasource/listing/table.rs:
##########
@@ -1098,7 +1098,7 @@ impl ListingTable {
             )
         }))
         .await?;
-        let file_list = stream::iter(file_list).flatten();
+        let file_list = futures::stream::select_all(file_list);

Review Comment:
   This is the actual fix, the rest of the changes are unit tests.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix sequential metadata fetching in ListingTable causing high latency [datafusion]

Posted by "geoffreyclaude (via GitHub)" <gi...@apache.org>.
geoffreyclaude commented on PR #14918:
URL: https://github.com/apache/datafusion/pull/14918#issuecomment-2690608959

   > I pushed a commit to fix the formatting and try to get a clean CI run
   
   Thanks! I had environment issues which prevented me from running the CI locally. Figured adding an extra basic unit test was simple enough to skip it 🤦


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix sequential metadata fetching in ListingTable causing high latency [datafusion]

Posted by "geoffreyclaude (via GitHub)" <gi...@apache.org>.
geoffreyclaude commented on PR #14918:
URL: https://github.com/apache/datafusion/pull/14918#issuecomment-2694925444

   > I still could not reproduce any improvement with this PR, FWIW. I still think it is a good change so i merged it in, but it might be cool to find some benchmark results that showed the improvement
   
   @alamb: I've updated your reproducer to do a `COUNT(*)` instead of a `LIMIT(10)`. The `COUNT(*)` only needs to read the metadata from the object store, as the number of rows is stored in the Parquet metadata, and effectively "runs" the query during the physical plan creation.
   
   Without the fix, the physical plan creation takes ~2.5 seconds.
   With the fix, it drops to ~700ms. 
   
   The logical planning and query execution take the same time in both.
   
   <details>
   
   ```rust
   use arrow::util::pretty::pretty_format_batches;
   use datafusion::config::{ParquetOptions, TableParquetOptions};
   use datafusion::datasource::file_format::parquet::ParquetFormat;
   use datafusion::datasource::listing::{
       ListingOptions, ListingTable, ListingTableConfig, ListingTableUrl,
   };
   use datafusion::execution::object_store::ObjectStoreUrl;
   use datafusion::functions_aggregate::expr_fn::count;
   use datafusion::logical_expr::utils::COUNT_STAR_EXPANSION;
   use datafusion::physical_plan::displayable;
   use datafusion::prelude::{Expr, SessionContext};
   use futures::StreamExt;
   use std::sync::Arc;
   use std::time::Instant;
   
   #[tokio::main]
   async fn main() -> datafusion::error::Result<()> {
       let ctx = SessionContext::new();
       let object_store_url =
           ObjectStoreUrl::parse("https://datasets.clickhouse.com").unwrap();
       let object_store = object_store::http::HttpBuilder::new()
           .with_url(object_store_url.as_str())
           .build()
           .unwrap();
   
       ctx.register_object_store(object_store_url.as_ref(), Arc::new(object_store));
   
       // urls are like
       // https://datasets.clickhouse.com/hits_compatible/athena_partitioned/hits_1.parquet'
       //let base_url = ObjectStoreUrl::parse("https://datasets.clickhouse.com").unwrap();
       let paths: Vec<ListingTableUrl> = (1..100).map(|i| format!("https://datasets.clickhouse.com/hits_compatible/athena_partitioned/hits_{i}.parquet"))
           .map(|url| ListingTableUrl::parse(&url).unwrap())
           .collect();
   
       let listing_options =
           ListingOptions::new(Arc::new(ParquetFormat::new())).with_collect_stat(true);
   
       println!("Creating table / reading statistics....");
       let config = ListingTableConfig::new_with_multi_paths(paths)
           .with_listing_options(listing_options)
           .infer_schema(&ctx.state())
           .await?;
       let start = Instant::now();
       let listing_table = ListingTable::try_new(config).unwrap();
       let df = ctx
           .read_table(Arc::new(listing_table))?
           .aggregate(vec![], vec![count(Expr::Literal(COUNT_STAR_EXPANSION))])?;
       println!("Done in {:?}", Instant::now() - start);
   
       let logical_plan_str = df.logical_plan().display_indent().to_string();
       println!("Logical plan:\n{logical_plan_str}");
   
       println!("Creating physical plan...");
   
       let start = Instant::now();
       let physical_plan = df.create_physical_plan().await?;
       println!("Done in {:?}", Instant::now() - start);
   
       let physical_plan_str = displayable(physical_plan.as_ref()).indent(true).to_string();
       println!("Physical plan:\n{physical_plan_str}");
   
       println!("Running query...");
       let start = Instant::now();
       let mut result_stream = physical_plan.execute(0, ctx.task_ctx())?;
       let mut batches = vec![];
   
       while let Some(record) = result_stream.next().await {
           batches.push(record?);
       }
       println!(
           "Got {} batches in  {:?}",
           batches.len(),
           Instant::now() - start
       );
   
       let response_str = pretty_format_batches(&batches)?.to_string();
       println!("Query result:\n{response_str}");
   
       Ok(())
   }
   ````
   </details>
   
   ### main
   ```text
   Creating table / reading statistics....
   Done in 2.267666ms
   Logical plan:
   Aggregate: groupBy=[[]], aggr=[[count(Int64(1))]]
     TableScan: ?table?
   Creating physical plan...
   Done in 2.510654875s
   Physical plan:
   ProjectionExec: expr=[98997497 as count(Int64(1))]
     PlaceholderRowExec
   
   Running query...
   Got 1 batches in  215.333µs
   Query result:
   +-----------------+
   | count(Int64(1)) |
   +-----------------+
   | 98997497        |
   +-----------------+
   
   ```
   
   ### fix/concurrent_heads
   ```text
   Creating table / reading statistics....
   Done in 2.187417ms
   Logical plan:
   Aggregate: groupBy=[[]], aggr=[[count(Int64(1))]]
     TableScan: ?table?
   Creating physical plan...
   Done in 686.674166ms
   Physical plan:
   ProjectionExec: expr=[98997497 as count(Int64(1))]
     PlaceholderRowExec
   
   Running query...
   Got 1 batches in  191.458µs
   Query result:
   +-----------------+
   | count(Int64(1)) |
   +-----------------+
   | 98997497        |
   +-----------------+
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix sequential metadata fetching in ListingTable causing high latency [datafusion]

Posted by "geoffreyclaude (via GitHub)" <gi...@apache.org>.
geoffreyclaude commented on code in PR #14918:
URL: https://github.com/apache/datafusion/pull/14918#discussion_r1974272139


##########
datafusion/core/src/datasource/listing/table.rs:
##########
@@ -1115,7 +1117,7 @@ impl ListingTable {
                 }
             })
             .boxed()
-            .buffered(ctx.config_options().execution.meta_fetch_concurrency);
+            .buffer_unordered(ctx.config_options().execution.meta_fetch_concurrency);

Review Comment:
   Ordering does not matter here, so might as well use `buffer_unordered` to avoid stalling on an outlier.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix sequential metadata fetching in ListingTable causing high latency [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #14918:
URL: https://github.com/apache/datafusion/pull/14918#issuecomment-2694766133

   I still could not reproduce any improvement with this PR, FWIW. I still think it is a good change so i merged it in, but it might be cool to find some benchmark results that showed the improvement
   
   
   <details><summary>Details</summary>
   <p>
   
   ```rust
   
   use std::sync::Arc;
   use std::time::Instant;
   use datafusion::datasource::file_format::parquet::ParquetFormat;
   use datafusion::datasource::listing::{ListingOptions, ListingTable, ListingTableConfig, ListingTableUrl};
   use datafusion::execution::object_store::ObjectStoreUrl;
   use datafusion::prelude::SessionContext;
   
   #[tokio::main]
   async fn main() -> datafusion::error::Result<()> {
       let ctx = SessionContext::new();
       let object_store_url = ObjectStoreUrl::parse("https://datasets.clickhouse.com").unwrap();
       let object_store = object_store::http::HttpBuilder::new()
           .with_url(object_store_url.as_str())
           .build()
           .unwrap();
   
       ctx.register_object_store(object_store_url.as_ref(),
           Arc::new(object_store));
   
   
       // urls are like
       // https://datasets.clickhouse.com/hits_compatible/athena_partitioned/hits_1.parquet'
       //let base_url = ObjectStoreUrl::parse("https://datasets.clickhouse.com").unwrap();
       let paths: Vec<ListingTableUrl> = (1..100).map(|i| format!("https://datasets.clickhouse.com/hits_compatible/athena_partitioned/hits_{i}.parquet"))
           .map(|url| ListingTableUrl::parse(&url).unwrap())
           .collect();
   
       let listing_options = ListingOptions::new(Arc::new(ParquetFormat::new()))
           .with_collect_stat(true);
   
       let start = Instant::now();
       println!("Creating table / reading statistics....");
       let config = ListingTableConfig::new_with_multi_paths(paths)
           .with_listing_options(listing_options)
           .infer_schema(&ctx.state()).await?;
       let listing_table = ListingTable::try_new(config).unwrap();
       let df = ctx.read_table(Arc::new(listing_table))?;
       println!("Done in {:?}", Instant::now() - start);
   
       println!("running query");
       let start = Instant::now();
       let batches = df.limit(0, Some(10))?.collect().await.unwrap();
       println!("Got {} batches in  {:?}", batches.len(), Instant::now() - start);
   
       Ok(())
   }
   
   
   ```
   
   </p>
   </details> 
   
   Some testing numbers (the results vary wildly)
   
   
   On this branch
   ```
   Creating table / reading statistics....
   Done in 250.333042ms
   running query
   Got 1 batches in  1.943637416s
   hello world!
   (venv) andrewlamb@Andrews-MacBook-Pro-2:~/Software/rust_playground$ cargo run --release
       Finished `release` profile [optimized] target(s) in 0.21s
        Running `target/release/rust_playground`
   Creating table / reading statistics....
   Done in 174.578ms
   running query
   Got 1 batches in  1.62131175s
   hello world!
   (venv) andrewlamb@Andrews-MacBook-Pro-2:~/Software/rust_playground$ cargo run --release
       Finished `release` profile [optimized] target(s) in 0.12s
        Running `target/release/rust_playground`
   Creating table / reading statistics....
   Done in 191.24325ms
   running query
   Got 1 batches in  1.257049458s
   hello world!
   ```
   
   On main
   
   ```
   Creating table / reading statistics....
   Done in 165.25ms
   running query
   Got 1 batches in  819.607625ms
   hello world!
   (venv) andrewlamb@Andrews-MacBook-Pro-2:~/Software/rust_playground$ cargo run --release
       Finished `release` profile [optimized] target(s) in 0.20s
        Running `target/release/rust_playground`
   Creating table / reading statistics....
   Done in 165.120666ms
   running query
   Got 1 batches in  1.036410625s
   hello world!
   (venv) andrewlamb@Andrews-MacBook-Pro-2:~/Software/rust_playground$ cargo run --release
       Finished `release` profile [optimized] target(s) in 0.10s
        Running `target/release/rust_playground`
   Creating table / reading statistics....
   Done in 198.459166ms
   running query
   Got 1 batches in  831.307041ms
   hello world!
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix sequential metadata fetching in ListingTable causing high latency [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #14918:
URL: https://github.com/apache/datafusion/pull/14918#issuecomment-2694766662

   Thanks again @geoffreyclaude 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix sequential metadata fetching in ListingTable causing high latency [datafusion]

Posted by "geoffreyclaude (via GitHub)" <gi...@apache.org>.
geoffreyclaude commented on code in PR #14918:
URL: https://github.com/apache/datafusion/pull/14918#discussion_r1974061938


##########
datafusion/core/src/datasource/listing/table.rs:
##########
@@ -1098,7 +1098,7 @@ impl ListingTable {
             )
         }))
         .await?;
-        let file_list = stream::iter(file_list).flatten();
+        let file_list = futures::stream::select_all(file_list);

Review Comment:
   Is the following a better alternative? And do we care about ordering here?
   ```
   let meta_fetch_concurrency = ctx.config_options().execution.meta_fetch_concurrency;
   let file_list = futures::stream::iter(file_list).flatten_unordered(meta_fetch_concurrency);
   ```



##########
datafusion/core/src/datasource/listing/table.rs:
##########
@@ -1098,7 +1098,7 @@ impl ListingTable {
             )
         }))
         .await?;
-        let file_list = stream::iter(file_list).flatten();
+        let file_list = futures::stream::select_all(file_list);

Review Comment:
   Is the following a better alternative? And do we care about ordering here?
   ```rust
   let meta_fetch_concurrency = ctx.config_options().execution.meta_fetch_concurrency;
   let file_list = futures::stream::iter(file_list).flatten_unordered(meta_fetch_concurrency);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix sequential metadata fetching in ListingTable causing high latency [datafusion]

Posted by "geoffreyclaude (via GitHub)" <gi...@apache.org>.
geoffreyclaude commented on code in PR #14918:
URL: https://github.com/apache/datafusion/pull/14918#discussion_r1974271100


##########
datafusion/core/src/datasource/listing/table.rs:
##########
@@ -1115,7 +1117,7 @@ impl ListingTable {
                 }
             })
             .boxed()
-            .buffered(ctx.config_options().execution.meta_fetch_concurrency);
+            .buffered_unordered(ctx.config_options().execution.meta_fetch_concurrency);

Review Comment:
   Ordering does not matter, so might as well use `buffered_unordered` to avoid stalling on an outlier.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix sequential metadata fetching in ListingTable causing high latency [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #14918:
URL: https://github.com/apache/datafusion/pull/14918#issuecomment-2689526294

   Thanks @geoffreyclaude -- I kicked off the CI for this


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix sequential metadata fetching in ListingTable causing high latency [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #14918:
URL: https://github.com/apache/datafusion/pull/14918#issuecomment-2769716046

   This was referenced by @sergiimk  in https://discord.com/channels/885562378132000778/1290751484807352412/1356393367566553240 (they hit the same problem and was pleased to find it fixed!)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix sequential metadata fetching in ListingTable causing high latency [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #14918:
URL: https://github.com/apache/datafusion/pull/14918#discussion_r1975866768


##########
datafusion/core/src/datasource/listing/table.rs:
##########
@@ -1670,6 +1749,56 @@ mod tests {
         Ok(())
     }
 
+    /// Check that the files listed by the table match the specified `output_partitioning`
+    /// when the object store contains `files`, and validate that file metadata is fetched
+    /// concurrently
+    async fn assert_list_files_for_exact_paths(
+        files: &[&str],
+        target_partitions: usize,
+        output_partitioning: usize,
+        file_ext: Option<&str>,
+    ) -> Result<()> {
+        let ctx = SessionContext::new();
+        let (store, _) = make_test_store_and_state(
+            &files.iter().map(|f| (*f, 10)).collect::<Vec<_>>(),
+        );
+
+        let meta_fetch_concurrency = ctx
+            .state()
+            .config_options()
+            .execution
+            .meta_fetch_concurrency;
+        let expected_concurrency = files.len().min(meta_fetch_concurrency);
+        let head_blocking_store = ensure_head_concurrency(store, expected_concurrency);

Review Comment:
   this is very cool



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org