datafusion-ballista icon indicating copy to clipboard operation
datafusion-ballista copied to clipboard

Small files problem.

Open xunxunmimi5577 opened this issue 7 months ago • 6 comments

I observed that an excessive number of small files significantly increases physical plan generation time and memory consumption.

Here are my test results:

I tested with a 100GB TPC-DS dataset, where the store_returns table is 4GB and partitioned with over 200,000 files. I loaded the data locally, registered it as a table using the register_parquet API, and executed:

SELECT count(*) FROM store_returns;

The query took 81.39 seconds, with the log showing:

Planned job QiZU0fh in 81.057936897s

After merging the files in the store_returns directory down to 4,032 files, the same query took only 16.84 seconds, with the log showing:

Planned job 7534D1z in 16.758905506s

This clearly demonstrates that the performance difference is primarily caused by the physical plan generation phase.

Additionally, when executing TPC-DS Q1 with too many small files, I observed the scheduler memory continuously increasing, eventually causing the process to crash. After merging the small files, the query executed successfully in just over 70 seconds.

xunxunmimi5577 avatar Apr 29 '26 03:04 xunxunmimi5577

Is there any solution to deal with scenarios with a large number of small files?

xunxunmimi5577 avatar Apr 29 '26 03:04 xunxunmimi5577

unfortunately small files problem is bothering many other frameworks and libraries, there is no generic solution to it

milenkovicm avatar Apr 30 '26 08:04 milenkovicm

I think this is very generic problem, i.e why in Hadoop DFS it is recommended to use block sizes of 128 or 256 MB Small files -> lots of metadata -> memory exhausting

sandugood avatar Apr 30 '26 09:04 sandugood

unfortunately small files problem is bothering many other frameworks and libraries, there is no generic solution to it

Spark has passed my tests, and it reads the parquet footer when tasks read the file.

xunxunmimi5577 avatar Apr 30 '26 10:04 xunxunmimi5577

Perhaps you can find out the slow parts to make performance on high number of small files better?

Some options

  • Planning performance: perhaps there are hot paths in the planning (which your log shows).

  • Scheduler -> executor communication

As far as I remember, Ballista doesn't prune plans yet (e.g. to only add file paths to the used partitions) so it might serialize/send/plans with the full 200K files over and over to all workers.

  • Combine small files in scan: when possible, combine multiple files in one partition to reduce the per-partition planning/scheduling/communication overhead.

Dandandan avatar Apr 30 '26 10:04 Dandandan

As far as I remember, Ballista doesn't prune plans yet (e.g. to only add file paths to the used partitions) so it might serialize/send/plans with the full 200K files over and over to all workers.

I believe you're right @Dandandan, per partition plan "adaptation" may be needed to support some other use cases as well, I don't think it would be too hard to add this functionality

milenkovicm avatar Apr 30 '26 15:04 milenkovicm