-
Notifications
You must be signed in to change notification settings - Fork 205
[wip] Add scripts for running benchmarks on EC2 #1654
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
Draft
andygrove
wants to merge
18
commits into
apache:main
Choose a base branch
from
andygrove:benchmark-automation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
dfdb226
wip
andygrove aeef5b4
update
andygrove 47878b4
fix
andygrove 7c94941
save for testing
andygrove 4edbab6
save
andygrove 801a7ca
save
andygrove 6896787
save
andygrove 33c7884
save
andygrove 17c3772
save
andygrove 7504796
save
andygrove 5abaeec
save
andygrove 09cfd14
save
andygrove 19ad872
save
andygrove f363227
revert
andygrove c7d31da
fix
andygrove 8873057
fix
andygrove a89a9dc
address feedback
andygrove 297925e
address feedback
andygrove File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
--> | ||
|
||
# Benchmarks | ||
|
||
[WIP] the purpose of this document / folder is to automate running the 100 GB benchmark in AWS so that anyone | ||
can run this as part of the release process and update the charts that we use in the repo. | ||
|
||
This is separate from the general benchmarking advice that we have in the contributor guide but does duplicate much of it. | ||
|
||
The documentation assumes that we are using instance type `m6id.2xlarge` (subject to change). | ||
|
||
For now I am using 1024 GB EBS but this can probably be much smaller, maybe as low as 100 GB. | ||
|
||
Connect to the instance and clone this repo (or the fork/branch to be used for benchmarking). | ||
|
||
```shell | ||
git clone https://github.com/apache/datafusion-comet | ||
``` | ||
|
||
## Install Prerequisites | ||
|
||
This is not fully tested yet. I am copying and pasting from the script for testing. | ||
|
||
```shell | ||
cd dev/benchmarks | ||
./setup.sh | ||
``` | ||
|
||
## Generate data locally | ||
|
||
TODO this is using the new tpchgen-rs project, which is much more convenient that the previous approach, but it | ||
only generates a single Parquet file per table by default. I have not looked into any performance impact that this may | ||
have on the benchmark. | ||
|
||
```shell | ||
cargo install tpchgen-cli | ||
tpchgen-cli -s 100 --format parquet | ||
``` | ||
|
||
## Spark Benchmark | ||
|
||
TODO clear page cache before run | ||
|
||
```shell | ||
./spark-tpch.sh | ||
``` | ||
|
||
## Comet Benchmark | ||
|
||
TODO clear page cache before run | ||
|
||
```shell | ||
./comet-tpch.sh | ||
``` | ||
|
||
## Produce Charts | ||
|
||
TBD |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/bin/bash | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
export COMET_JAR=`pwd`/../../spark/target/comet-spark-spark3.5_2.12-0.8.0-SNAPSHOT.jar | ||
|
||
$SPARK_HOME/bin/spark-submit \ | ||
--master $SPARK_MASTER \ | ||
--conf spark.driver.memory=8G \ | ||
--conf spark.executor.instances=1 \ | ||
--conf spark.executor.cores=8 \ | ||
--conf spark.cores.max=8 \ | ||
--conf spark.executor.memory=8g \ | ||
--conf spark.memory.offHeap.enabled=true \ | ||
--conf spark.memory.offHeap.size=8g \ | ||
--conf spark.local.dir=/home/ec2-user/tmp \ | ||
--conf spark.driver.extraJavaOptions="-Djava.io.tmpdir=/home/ec2-user/tmp" \ | ||
--conf spark.executor.extraJavaOptions="-Djava.io.tmpdir=/home/ec2-user/tmp" \ | ||
--jars $COMET_JAR \ | ||
--driver-class-path $COMET_JAR \ | ||
--conf spark.driver.extraClassPath=$COMET_JAR \ | ||
--conf spark.executor.extraClassPath=$COMET_JAR \ | ||
--conf spark.plugins=org.apache.spark.CometPlugin \ | ||
--conf spark.shuffle.manager=org.apache.spark.sql.comet.execution.shuffle.CometShuffleManager \ | ||
--conf spark.comet.enabled=true \ | ||
--conf spark.comet.exec.shuffle.enableFastEncoding=true \ | ||
--conf spark.comet.exec.shuffle.fallbackToColumnar=true \ | ||
--conf spark.comet.cast.allowIncompatible=true \ | ||
--conf spark.comet.exec.replaceSortMergeJoin=true \ | ||
tpcbench.py \ | ||
--name comet \ | ||
--benchmark tpch \ | ||
--data /home/ec2-user/ \ | ||
--queries /home/ec2-user/datafusion-benchmarks/tpch/queries \ | ||
--output . \ | ||
--iterations 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/bin/bash | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
sudo yum install -y wget | ||
|
||
# Install Rust | ||
sudo yum groupinstall -y "Development Tools" | ||
curl https://sh.rustup.rs -sSf | sh -s -- -y | ||
. "$HOME/.cargo/env" | ||
|
||
# Install Java | ||
sudo yum install -y java-17-amazon-corretto-headless java-17-amazon-corretto-devel | ||
export JAVA_HOME=/usr/lib/jvm/java-17-amazon-corretto | ||
|
||
# Build Comet | ||
make release PROFILES="-Pspark-3.5" | ||
|
||
# Clone datafusion-benchmarks repo, which has the queries | ||
git clone https://github.com/apache/datafusion-benchmarks.git | ||
|
||
# Install Spark | ||
wget https://dlcdn.apache.org/spark/spark-3.5.5/spark-3.5.5-bin-hadoop3.tgz | ||
if [ ! -d "spark-3.5.5-bin-hadoop3" ]; then | ||
wget https://dlcdn.apache.org/spark/spark-3.5.5/spark-3.5.5-bin-hadoop3.tgz | ||
tar xzf spark-3.5.5-bin-hadoop3.tgz | ||
fi | ||
|
||
# Create a temp folder on the primary EBS volume | ||
mkdir /home/ec2-user/tmp | ||
|
||
# Start Spark | ||
export SPARK_HOME=/home/ec2-user/spark-3.5.5-bin-hadoop3 | ||
export SPARK_MASTER=spark://localhost:7077 | ||
$SPARK_HOME/sbin/start-master.sh --host localhost | ||
$SPARK_HOME/sbin/start-worker.sh $SPARK_MASTER |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
SPARK_LOCAL_DIRS=/home/ec2-user/tmp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/bash | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
export SPARK_MASTER=spark://localhost:7077 | ||
|
||
$SPARK_HOME/bin/spark-submit \ | ||
--master $SPARK_MASTER \ | ||
--conf spark.driver.memory=8G \ | ||
--conf spark.executor.instances=1 \ | ||
--conf spark.executor.cores=8 \ | ||
--conf spark.cores.max=8 \ | ||
--conf spark.executor.memory=8g \ | ||
--conf spark.memory.offHeap.enabled=true \ | ||
--conf spark.memory.offHeap.size=8g \ | ||
--conf spark.local.dir=/home/ec2-user/tmp \ | ||
--conf spark.driver.extraJavaOptions="-Djava.io.tmpdir=/home/ec2-user/tmp" \ | ||
--conf spark.executor.extraJavaOptions="-Djava.io.tmpdir=/home/ec2-user/tmp" \ | ||
tpcbench.py \ | ||
--name spark \ | ||
--benchmark tpch \ | ||
--data /home/ec2-user/ \ | ||
--queries /home/ec2-user/datafusion-benchmarks/tpch/queries \ | ||
--output . \ | ||
--iterations 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import argparse | ||
from datetime import datetime | ||
import json | ||
from pyspark.sql import SparkSession | ||
import time | ||
|
||
def main(benchmark: str, data_path: str, query_path: str, iterations: int, output: str, name: str): | ||
|
||
# Initialize a SparkSession | ||
spark = SparkSession.builder \ | ||
.appName(f"{name} benchmark derived from {benchmark}") \ | ||
.getOrCreate() | ||
|
||
# Register the tables | ||
if benchmark == "tpch": | ||
num_queries = 22 | ||
table_names = ["customer", "lineitem", "nation", "orders", "part", "partsupp", "region", "supplier"] | ||
elif benchmark == "tpcds": | ||
num_queries = 99 | ||
table_names = ["call_center", "catalog_page", "catalog_returns", "catalog_sales", "customer", | ||
"customer_address", "customer_demographics", "date_dim", "time_dim", "household_demographics", | ||
"income_band", "inventory", "item", "promotion", "reason", "ship_mode", "store", "store_returns", | ||
"store_sales", "warehouse", "web_page", "web_returns", "web_sales", "web_site"] | ||
else: | ||
raise "invalid benchmark" | ||
|
||
for table in table_names: | ||
path = f"{data_path}/{table}.parquet" | ||
print(f"Registering table {table} using path {path}") | ||
df = spark.read.parquet(path) | ||
df.createOrReplaceTempView(table) | ||
|
||
conf_dict = {k: v for k, v in spark.sparkContext.getConf().getAll()} | ||
|
||
results = { | ||
'engine': 'datafusion-comet', | ||
'benchmark': benchmark, | ||
'data_path': data_path, | ||
'query_path': query_path, | ||
'spark_conf': conf_dict, | ||
} | ||
|
||
for iteration in range(0, iterations): | ||
print(f"Starting iteration {iteration} of {iterations}") | ||
iter_start_time = time.time() | ||
|
||
for query in range(1, num_queries+1): | ||
spark.sparkContext.setJobDescription(f"{benchmark} q{query}") | ||
|
||
# if query != 13: | ||
# continue | ||
|
||
# read text file | ||
path = f"{query_path}/q{query}.sql" | ||
|
||
# if query == 72: | ||
# # use version with sensible join order | ||
# path = f"{query_path}/q{query}_optimized.sql" | ||
|
||
print(f"Reading query {query} using path {path}") | ||
with open(path, "r") as f: | ||
text = f.read() | ||
# each file can contain multiple queries | ||
queries = text.split(";") | ||
|
||
start_time = time.time() | ||
for sql in queries: | ||
sql = sql.strip().replace("create view", "create temp view") | ||
if len(sql) > 0: | ||
print(f"Executing: {sql}") | ||
df = spark.sql(sql) | ||
df.explain() | ||
rows = df.collect() | ||
|
||
print(f"Query {query} returned {len(rows)} rows") | ||
|
||
end_time = time.time() | ||
print(f"Query {query} took {end_time - start_time} seconds") | ||
|
||
# store timings in list and later add option to run > 1 iterations | ||
query_timings = results.setdefault(query, []) | ||
query_timings.append(end_time - start_time) | ||
|
||
iter_end_time = time.time() | ||
print(f"Iteration {iteration} took {round(iter_end_time - iter_start_time,2)} seconds") | ||
|
||
str = json.dumps(results, indent=4) | ||
current_time_millis = int(datetime.now().timestamp() * 1000) | ||
results_path = f"{output}/{name}-{benchmark}-{current_time_millis}.json" | ||
print(f"Writing results to {results_path}") | ||
with open(results_path, "w") as f: | ||
f.write(str) | ||
|
||
# Stop the SparkSession | ||
spark.stop() | ||
|
||
#print(str) | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description="DataFusion benchmark derived from TPC-H / TPC-DS") | ||
parser.add_argument("--benchmark", required=True, help="Benchmark to run (tpch or tpcds)") | ||
parser.add_argument("--data", required=True, help="Path to data files") | ||
parser.add_argument("--queries", required=True, help="Path to query files") | ||
parser.add_argument("--iterations", required=False, default="1", help="How many iterations to run") | ||
parser.add_argument("--output", required=True, help="Path to write output") | ||
parser.add_argument("--name", required=True, help="Prefix for result file e.g. spark/comet/gluten") | ||
args = parser.parse_args() | ||
|
||
main(args.benchmark, args.data, args.queries, int(args.iterations), args.output, args.name) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My RHEL9 EC2 instance did not have
wget
. May be we should addyum install wget --y
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added