Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Improve parallelism in writing hive parquet #17512

Merged
merged 1 commit into from
Jul 11, 2024

Conversation

nameexhaustion
Copy link
Collaborator

No description provided.

@github-actions github-actions bot added performance Performance issues or improvements python Related to Python Polars rust Related to Rust Polars labels Jul 9, 2024
Copy link

codecov bot commented Jul 9, 2024

Codecov Report

Attention: Patch coverage is 99.13043% with 1 line in your changes missing coverage. Please review.

Project coverage is 80.51%. Comparing base (daf2e49) to head (2c70546).
Report is 2 commits behind head on main.

Files Patch % Lines
crates/polars-io/src/partition.rs 99.13% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17512      +/-   ##
==========================================
+ Coverage   80.48%   80.51%   +0.03%     
==========================================
  Files        1483     1483              
  Lines      195118   195234     +116     
  Branches     2778     2778              
==========================================
+ Hits       157039   157193     +154     
+ Misses      37568    37530      -38     
  Partials      511      511              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nameexhaustion nameexhaustion marked this pull request as ready for review July 9, 2024 02:00
@ritchie46
Copy link
Member

I think we should maybe add a semaphore to ensure we don't open to many files at once.

@nameexhaustion nameexhaustion marked this pull request as draft July 10, 2024 00:54
POOL.install(|| match groups {
GroupsProxy::Idx(idx) => idx
.all()
.chunks(MAX_OPEN_FILES)
Copy link
Collaborator Author

@nameexhaustion nameexhaustion Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't do any simple semaphore logic because of Rayon's work-stealing, so I've just applied the limit by batching the groups instead.

I tried other ways, but it was very rough 🥲. It's basically impossible to apply backpressure with Rayon - you can't really tell it not to steal/execute certain tasks 🤕.

@@ -722,7 +722,8 @@ impl BatchedParquetReader {
use_statistics,
hive_partition_columns.as_deref(),
);
tx.send((dfs, rows_read, limit)).unwrap();
// Don't unwrap, async task could be cancelled.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drive-by - not related to this PR, but I got a CI failure from this


let cols = df.get_columns();
let get_n_files_and_rows_per_file = |part_df: &DataFrame| {
let n_files = (part_df.estimated_size() / chunk_size).clamp(1, 0xffff_ffff);
Copy link
Collaborator Author

@nameexhaustion nameexhaustion Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reduced the max number of files per-directory from 4_503_599_627_370_495 to 4_294_967_295, don't think we needed that many 😅. We now use 8 characters instead of 13 for the file name, which should help with sorting.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, I doubt we'll hit that in our lifetime. :')

@nameexhaustion nameexhaustion marked this pull request as ready for review July 10, 2024 07:38
@@ -9,5 +9,7 @@ pub use crate::json::*;
pub use crate::ndjson::core::*;
#[cfg(feature = "parquet")]
pub use crate::parquet::{metadata::*, read::*, write::*};
#[cfg(feature = "parquet")]
pub use crate::partition::write_partitioned_dataset;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drive-by - forgot to re-export this for rust users

@ritchie46 ritchie46 merged commit 310036b into pola-rs:main Jul 11, 2024
26 checks passed
@c-peters c-peters added the accepted Ready for implementation label Jul 15, 2024
@deanm0000
Copy link
Collaborator

is hive writing exposed on python side somewhere or still only rust?

@ritchie46
Copy link
Member

It is in the python writers. See partition_by arguments.

@nameexhaustion nameexhaustion deleted the par-hive-write branch July 19, 2024 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation performance Performance issues or improvements python Related to Python Polars rust Related to Rust Polars
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants