データアナリティクス事業本部の笠原です。
現在DevelopersIO 2023の一環として、YouTubeでのビデオセッションが公開されています。
今回「Glue for Rayを使ってみよう」というタイトルでビデオセッションを公開しました。
概要
re:Invent 2022で公開された「Glue for Ray」が、先日GAしました。
このビデオセッションでは、Glue for Rayをまだ使ったことない方向けに、Glue for Rayの簡単な使い方をレクチャーします。
動画
スライド
参考サイト
AWS Glue for Ray の一般提供が開始されました | DevelopersIO
AWS Glue on Ray ではじめるデータ分析 とそのパフォーマンス
Working with Ray jobs in AWS Glue - AWS Glue
Benchmarking Python Distributed AI Backends with Wordbatch
補足
セッション中にPandas DataframeとRay Datasetの実行時間比較を行っていますので、そのコードを掲載します。
import ray
import pandas as pd
from ray import data
import time
ray.init('auto')
## Ray Dataset
time_start = time.perf_counter()
ds = ray.data.read_parquet("s3://amazon-reviews-pds/parquet/product_category=Wireless/")
# Add the given new column to the dataset and show the sample record after adding a new column
ds = ds.add_column( "helpful_votes_ratio", lambda df: df["helpful_votes"] / df["total_votes"])
# Dropping few columns from the underlying Dataset
ds = ds.drop_columns(["review_body", "vine", "product_parent", "verified_purchase", "review_headline"])
ds.write_parquet("s3://glue-ray-sample-kasahara/ray/tutorial/output/")
time_end = time.perf_counter()
print(f"{time_end - time_start} [s]")
## Pandas DataFrame
time_start = time.perf_counter()
df = pd.read_parquet("s3://amazon-reviews-pds/parquet/product_category=Wireless/")
df["helpful_votes_ratio"] = df["helpful_votes"] / df["total_votes"]
df = df.drop(columns=["review_body", "vine", "product_parent", "verified_purchase", "review_headline"], axis=1)
df.to_parquet("s3://glue-ray-sample-kasahara/ray/tutorial/output_pandas/output_pandas.snappy.parquet")
time_end = time.perf_counter()
print(f"{time_end - time_start} [s]")
単一のRayジョブ内で実行して比較しています。
内容はAmazon Customer Review DatasetsのWirelessカテゴリのParquetデータファイルを取り込み、カラム追加とカラム削除をして、あらかじめ作成済みのS3バケットにParquetデータファイルとして出力をしています。
コード自体はRay DatasetとPandas Dataframeでほとんど同じような処理をしています。
Rayジョブの設定はデフォルトのままです。
なお、 pd.read_parquet()
でAmazon Customer Review DatasetsのS3バケットから直接読み込む際に必要なライブラリ s3fs
を --pip-install
で追加インストールしています。
実行結果は以下のとおりでした。
実行時間[s] | |
---|---|
Ray Dataset | 64.621119405 |
Pandas Dataframe | 125.452704231 |
Ray Datasetsが分散処理されているためPandas Dataframeより高速に処理されていることがわかると思います。
最後に
Glue for RayがGAしました。 比較的容易に分散処理が記述できるようになっています。 ETL処理に関しては、Pandas等と比較してほとんど変わらない記述で処理が可能になっています。 まだ成長段階のサービスです。今後より使いやすくなっていくことを期待しながら、みなさんで積極的に使っていきましょう。