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

Add benchmark on Pandas DataFrame for Pandas, Polars, DuckDB, chDB #222

Merged
merged 6 commits into from
Sep 11, 2024

Conversation

auxten
Copy link
Member

@auxten auxten commented Sep 9, 2024

Add benchmark on Pandas DataFrame for Pandas, Polars, DuckDB, chDB

  • Pandas: 2.2.2
  • Polars: 1.6.0
  • DuckDB: 1.0.0
  • chDB : 2.0.3
  1. Assume data is already in memory, time cost on reading parquet and converting it into Pandas DataFrame are not counted as load time. But as Polars needs to convert Pandas DataFrame into Polars DataFrame to make it work, the convertion time is recorded in the "load_time"
  2. Pandas and Polars queries are using their own api to emulate the operation of SQL.
  3. During query Polars crashed the Python process several times, I don't know how to make it work. So Q39, Q42 are marked failed

Polars Q39 crash message:

Crash with:
  thread '<unnamed>' panicked at crates/polars-time/src/windows/duration.rs:215:21:
  expected leading integer in the duration string, found m
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
lambda x: x.filter(
    (pl.col("CounterID") == 62)
    & (pl.col("EventDate") >= pl.datetime(2013, 7, 1))
    & (pl.col("EventDate") <= pl.datetime(2013, 7, 31))
    & (pl.col("IsRefresh") == 0)
)
.group_by(
    [
        "TraficSourceID",
        "SearchEngineID",
        "AdvEngineID",
        # pl.when(pl.col("SearchEngineID").eq(0) & pl.col("AdvEngineID").eq(0))
        # .then(pl.col("Referer"))
        # .otherwise("")
        # .alias("Src"),
        "URL",
    ]
)
.agg(pl.len().alias("PageViews"))
.sort("PageViews", descending=True)
.slice(1000, 10),

Polars Q42 crash message:

Crash with:
  thread '<unnamed>' panicked at crates/polars-time/src/windows/duration.rs:215:21:
  expected leading integer in the duration string, found m
lambda x: x.filter(
    (pl.col("CounterID") == 62)
    & (pl.col("EventDate") >= pl.datetime(2013, 7, 14))
    & (pl.col("EventDate") <= pl.datetime(2013, 7, 15))
    & (pl.col("IsRefresh") == 0)
    & (pl.col("DontCountHits") == 0)
)
.group_by(pl.col("EventTime").dt.truncate("minute"))
.agg(pl.len().alias("PageViews"))
.slice(1000, 10),

@auxten
Copy link
Member Author

auxten commented Sep 9, 2024

@rschu1ze @alexey-milovidov Please have a look

@rschu1ze rschu1ze self-assigned this Sep 9, 2024

sudo apt-get update
sudo apt-get install -y python3-pip
pip install pandas chdb
Copy link
Member

Choose a reason for hiding this comment

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

I had to use pip install --break-system-packages here (as it complained without the flag). Interestingly, the pip install commands in other ClickBench scripts also don't use that flag, so I am okay with not having it (it might be some weirdness with my system).

Copy link
Member Author

Choose a reason for hiding this comment

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

I also encountered the same problem and checked how other Python pkgs worked. I think this should be the Ubuntu 24 introduced new problem.
But after that I decided to leave it identical with other packages. Maybe we could fix all of them with another patch.

Copy link
Member

Choose a reason for hiding this comment

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

duckdb-dataframe/benchmark.sh Outdated Show resolved Hide resolved
Copy link
Member

@rschu1ze rschu1ze left a comment

Choose a reason for hiding this comment

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

Double-checked the measurements on a c6a.metal box, and they reproduced nicely (with a few % deviation here and there but that is expected).

@rschu1ze rschu1ze merged commit d16c5b2 into ClickHouse:main Sep 11, 2024
@qoega
Copy link
Member

qoega commented Sep 12, 2024

Is it meant to be added to the main report? https://github.com/ClickHouse/ClickBench/blob/main/index.html

Or you can have a separate one as we have for hardware and versions.

@auxten
Copy link
Member Author

auxten commented Sep 12, 2024

Is it meant to be added to the main report? https://github.com/ClickHouse/ClickBench/blob/main/index.html

Or you can have a separate one as we have for hardware and versions.

I added a "dataframe" type. You can check it with this link

@qoega
Copy link
Member

qoega commented Sep 12, 2024

Polars Q0 and Q29 - did we check the result? Did we check that it is not using query result caching for 29?

"Q29",
"SELECT SUM(ResolutionWidth), SUM(ResolutionWidth + 1), SUM(ResolutionWidth + 2), SUM(ResolutionWidth + 3), SUM(ResolutionWidth + 4), SUM(ResolutionWidth + 5), SUM(ResolutionWidth + 6), SUM(ResolutionWidth + 7), SUM(ResolutionWidth + 8), SUM(ResolutionWidth + 9), SUM(ResolutionWidth + 10), SUM(ResolutionWidth + 11), SUM(ResolutionWidth + 12), SUM(ResolutionWidth + 13), SUM(ResolutionWidth + 14), SUM(ResolutionWidth + 15), SUM(ResolutionWidth + 16), SUM(ResolutionWidth + 17), SUM(ResolutionWidth + 18), SUM(ResolutionWidth + 19), SUM(ResolutionWidth + 20), SUM(ResolutionWidth + 21), SUM(ResolutionWidth + 22), SUM(ResolutionWidth + 23), SUM(ResolutionWidth + 24), SUM(ResolutionWidth + 25), SUM(ResolutionWidth + 26), SUM(ResolutionWidth + 27), SUM(ResolutionWidth + 28), SUM(ResolutionWidth + 29), SUM(ResolutionWidth + 30), SUM(ResolutionWidth + 31), SUM(ResolutionWidth + 32), SUM(ResolutionWidth + 33), SUM(ResolutionWidth + 34), SUM(ResolutionWidth + 35), SUM(ResolutionWidth + 36), SUM(ResolutionWidth + 37), SUM(ResolutionWidth + 38), SUM(ResolutionWidth + 39), SUM(ResolutionWidth + 40), SUM(ResolutionWidth + 41), SUM(ResolutionWidth + 42), SUM(ResolutionWidth + 43), SUM(ResolutionWidth + 44), SUM(ResolutionWidth + 45), SUM(ResolutionWidth + 46), SUM(ResolutionWidth + 47), SUM(ResolutionWidth + 48), SUM(ResolutionWidth + 49), SUM(ResolutionWidth + 50), SUM(ResolutionWidth + 51), SUM(ResolutionWidth + 52), SUM(ResolutionWidth + 53), SUM(ResolutionWidth + 54), SUM(ResolutionWidth + 55), SUM(ResolutionWidth + 56), SUM(ResolutionWidth + 57), SUM(ResolutionWidth + 58), SUM(ResolutionWidth + 59), SUM(ResolutionWidth + 60), SUM(ResolutionWidth + 61), SUM(ResolutionWidth + 62), SUM(ResolutionWidth + 63), SUM(ResolutionWidth + 64), SUM(ResolutionWidth + 65), SUM(ResolutionWidth + 66), SUM(ResolutionWidth + 67), SUM(ResolutionWidth + 68), SUM(ResolutionWidth + 69), SUM(ResolutionWidth + 70), SUM(ResolutionWidth + 71), SUM(ResolutionWidth + 72), SUM(ResolutionWidth + 73), SUM(ResolutionWidth + 74), SUM(ResolutionWidth + 75), SUM(ResolutionWidth + 76), SUM(ResolutionWidth + 77), SUM(ResolutionWidth + 78), SUM(ResolutionWidth + 79), SUM(ResolutionWidth + 80), SUM(ResolutionWidth + 81), SUM(ResolutionWidth + 82), SUM(ResolutionWidth + 83), SUM(ResolutionWidth + 84), SUM(ResolutionWidth + 85), SUM(ResolutionWidth + 86), SUM(ResolutionWidth + 87), SUM(ResolutionWidth + 88), SUM(ResolutionWidth + 89) FROM hits;",
lambda x: x["ResolutionWidth"].sum()
+ x["ResolutionWidth"].shift(1).sum()
Copy link
Member

Choose a reason for hiding this comment

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

What shift does(link)? we just needed +1. +2 etc and not play with indices

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right, both Pandas and Polars are incorrect. I'll fix them later.

@auxten
Copy link
Member Author

auxten commented Sep 12, 2024

Polars Q0 and Q29 - did we check the result? Did we check that it is not using query result caching for 29?

As I mentioned:

But as Polars needs to convert Pandas DataFrame into Polars DataFrame to make it work, the convertion time is recorded in the "load_time"

For Q0, I think Polars dataframe just keeps some statistic data to make Q0 super fast.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants