Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
サーバーレスJavaパフォーマンス選手権 at AWS Dev Day 2023 Tokyo
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
x-blood
June 26, 2023
Programming
1.5k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
サーバーレスJava パフォーマンス選手権 at AWS Dev Day 2023 Tokyo
x-blood
June 26, 2023
More Decks by x-blood
See All by x-blood
Amazon Q Developerでテストコードを生成してみた
xblood
0
44
re:Inventで現地参加したコンテナ関連セッションを振り返る
xblood
0
550
Amazon EKS Pod Identityで何が変わるのか
xblood
0
1.1k
Lizさんに届け!AWS Jr. ChampionとTop Engineerが書籍コンテナセキュリティを読んで感じたこと
xblood
0
1.6k
サーバーレスJavaの今 ~SnapStartとWeb Adapterを寄せて~
xblood
4
3.7k
Finch OSSコードリーディング
xblood
0
1.4k
ECS Service Connectでマイクロサービスを繋いでみた
xblood
0
2.5k
AWS Glue Git統合のPoCでの活用
xblood
0
230
Spring BootとKubernetesで実現する今どきのDevOps入門
xblood
1
1.2k
Other Decks in Programming
See All in Programming
3Dシーンの圧縮
fadis
1
650
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.1k
The NotImplementedError Problem in Ruby
koic
1
600
AI駆動開発で崩れていくコードベースを立て直す
kyoko_nr_nr
1
440
「エンジニアインターン、どうやって取った?」準備のリアルを語るLT会 Progate BAR
akiomatic
0
120
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
500
Spec-Driven Development with AI-Agents: From High-Level Requirements to Working Software
antonarhipov
2
450
AIとRubyの静的型付け
ukin0k0
0
540
AI 時代のソフトウェア設計の学び方
masuda220
PRO
29
12k
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
550
肥大化するレガシーコードに立ち向かうためのインターフェース分離と依存の逆転 / JJUG CCC 2026 Spring
hirokunimaeta
0
500
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.3k
Featured
See All Featured
The untapped power of vector embeddings
frankvandijk
2
1.7k
Test your architecture with Archunit
thirion
1
2.3k
Balancing Empowerment & Direction
lara
6
1.1k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
220
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
570
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
120k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
3.3k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
320
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Navigating Weather and Climate Data
rabernat
0
210
Transcript
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. サーバーレスJava パフォーマンス選⼿権 佐藤 靖幸 C - 4 - 2 デロイト トーマツ ウェブサービス株式会社
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. 本セッションについて パフォーマンス選⼿権 レギュレーション エントリー選⼿紹介 パフォーマンス選⼿権 開催︕ まとめ アジェンダ
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. ⾃⼰紹介 佐藤 靖幸 得意領域 バックエンド開発 クラウドインフラ (Amazon Web Services) 好きなAWSサービス Amazon VPC・AWS Lambda Amazon ECS・Amazon EKS © 佐藤靖幸 2023
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 本セッションについて
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. 本セッションについて サーバーレスJavaは実装⽅法・起動⽅法に様々な選択肢があります。 本セッションではサーバーレスJavaの実装⽅法と起動⽅法における 代表的な⽅法をご紹介し、それぞれのベンチマークを取得して パフォーマンスを⽐較します 併せて、それぞれの実装⽅法・起動⽅法の 特徴とトレードオフをご紹介します
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. 併せて閲覧をおすすめする資料 AWS Summit Tokyo 2023 Java on Lambda のコールドスタート を乗り越える、 これからの サーバーレスアプリケーション JJUG CCC 2023 サーバーレスJavaの今 ~SnapStartとWeb Adapterを寄せて~
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. パフォーマンス選⼿権 レギュレーション
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. AWS Lambda Runtime : Java 17 (Amazon Corretto 17) Timeout : 10 sec Memory : 2048 MB HTTP EndPoint : API Gateway HTTP API Database : DynamoDB Develop Environment : MacBook Air(M1, 2020)
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. AWS アーキテクチャ構成 三層アプリケーションをAWS Lambdaで実装 データソースはAmazon DynamoDBを利⽤
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. パフォーマンス測定⽅法 K6を利⽤。同時に200リクエストをAPI Gatewayを対象に実⾏ 以下のカテゴリでパフォーマンスを測定 • コールドスタートタイム(平均・ミリ秒) • E2E 90%タイル レイテンシー(平均・秒) • パッケージのビルド時間(秒) • ウォームアップ(合計・数) • パッケージサイズ(MB)
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. エントリー選⼿の紹介
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. パフォーマンス選⼿権 エントリー選⼿⼀覧 1. Pure Java https://github.com/x-blood/awsdevday2023tokyo-sls-framework 2. Pure Java SnapStart https://github.com/x-blood/awsdevday2023tokyo-sls-pure-java-snapstart 3. Framework https://github.com/x-blood/awsdevday2023tokyo-sls-framework 4. Framework SnapStart https://github.com/x-blood/awsdevday2023tokyo-sls-framework-snapstart 5. Framework Native Image https://github.com/x-blood/awsdevday2023tokyo-sls-framework-native-image 6. Framework Web Adapter https://github.com/x-blood/awsdevday2023tokyo-sls-framework-web-adapter 7. Framework Web Adapter + Native Image https://github.com/x-blood/awsdevday2023tokyo-sls-framework-web-adapter-native-image
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. 1. Pure Java シンプルなJavaのLambda Hander ライブラリ管理にはMavenを利⽤ Pros • 必要なライブラリを取捨選択 • 軽量なパッケージサイズ Cons • アーキテクチャ移⾏が容易なクラス設計の推奨
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Pure Javaのコード設計(おさらい) Lambdaを呼び出すイベントの種類ごとに AWS SDK for Javaのイベントハンドラを利⽤ イベントハンドラーを使うことで開発者体験が向上
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. 2. Pure Java SnapStart シンプルなJavaのLambda Handerに加えて、 Lambda SnapStartを⽤いたJVM実⾏環境のスナップショットを利⽤ Pros • リストアスタート時間による起動時間の減少 Cons • JVMスナップショット特有の考慮点が必要
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. SnapStart(おさらい) SnapStartを有効化すると、新しいLambdaバージョン発⾏時に ⾃動的にスナップショットを⽣成 バージョンまたはエイリアス指定でLambdaを起動することで JVM環境の起動を⾼速化
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. SnapStartの考慮点① ⼀意性の確保 ⼀意となる情報( UUIDなど)の⼀意性の確保 ネットワーク確⽴ スナップショット復元後のネットワーク確⽴の担保 外部API データベース接続
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. SnapStartの考慮点② クラスのプリローディング スナップショット作成時に多くのクラスを 事前ローディングしておくことでパフォーマンスが向上 初期化中にクラスを事前ロードできない場合は、 ダミー呼び出しを使⽤してクラスを事前ロード
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. 3. Framework AWS Lambdaでアプリケーションフレームワークを利⽤ 本セッションのエントリー選⼿はQuarkusを利⽤ Pros • アプリケーションフレームワークの⾼度な機能 • Pure Javaと⽐較してコンテナワークロードへの移植性の向上 Cons • パッケージサイズの肥⼤化に伴うコールドスタート時間の増加
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Frameworkのサーバーレス統合 AWS SDK for Javaのイベントハンドラクラスを活⽤しつつも フレームワークと統合 拡張機能が提供されLambdaの機能拡張やビルドの簡潔さに寄与
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. 4. Framework SnapStart AWS Lambdaでアプリケーションフレームワークの機能を活⽤しつつ Lambda SnapStartも適⽤ Pros • 肥⼤化したパッケージのスナップショット取得による コールドスタート時間の短縮 Cons • JVMスナップショット特有の考慮点を フレームワークの範囲まで拡⼤
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Frameworkによるプリローディング機能 パッケージのビルドを⾏う際に フレームワークが提供するAWS Lambda 統合機能を利⽤して プリローディング⽤のメタ情報を⾃動⽣成
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. 5. Framework Native Image Native Imageに最適化可能なアプリケーションフレームワークを活⽤ アプリケーションフレームワークをNative Imageに Pros • アプリケーションフレームワークのNative Image最適化による ⾼速なコールドスタートを実現 Cons • Graal VM特有のメタデータ管理を アプリケーションフレームワークの範囲まで拡⼤
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Native Imageの考慮点 Javaの動的機能(リフレクションなど)を利⽤する場合は 到達可能メタデータ(reflect-config.json)を⽣成 トレース・エージェントツールを使⽤して メタデータを⾃動⽣成 $JAVA_HOME/bin/java - agentlib:native-image-agent=config- output-dir=${OUTPUT_PATH}
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Framework × Native Image フレームワークを利⽤することで Native Imageビルドを簡潔に ビルドオプションやビルド⽤イメージ指定が可能
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. 6. Framework Web Adapter アプリケーションフレームワークをAWS Lambda Web Adapterで ほぼそのまま動作させる Pros • コンテナワークロード(ECS・EKSなど)への移⾏コストがない Cons • HTTPプロトコル前提 EventBridge、SQS、StepFunctionsなどを利⽤する場合は 統合パターンを考慮 • コールドスタートの考慮
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Web Adapter(おさらい) フレームワークを(ほぼそのまま) Lambdaで動かす
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Web Adapterの考慮点 (2023年5⽉30⽇時点) API Gateway, Lambda Functions URL, Application Load Balancer のみをサポート Amazon SQS、Amazon CloudWatch Eventなどによる インテグレーションは従来のイベントハンドラーを 利⽤したハンドリングが実装観点においては より簡潔になる
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Dockerfileの例 DockerfileにAWS Lambda Web Adapterの拡張機能を コピーする⼀⽂を加える(これだけ)
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. 7. Framework Web Adapter × Native Image AWS Lambda Web Adapterで動作させた アプリケーションフレームワークをNative Imageに Pros • JVM実⾏環境が不要になり、JVM環境初期化フェーズが不要に • コンテナイメージの場合はイメージサイズを軽量化することが可能 • アプリケーションフレームワークを(ほぼそのまま)動かせる上に ⾼速なコールドスタートを実現 Cons • Graal VM特有のメタデータ管理が必要
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Native ImageのDockerfile Native Image⽤のベースイメージを利⽤することで コンテナサイズを軽量化
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. 補⾜︓Native Imageのピーク時スループット Native ImageはJIT(Just In Time)のように実⾏しながら 最適化を⾏うことができないため、 パフォーマンス最適化を⾏っていない場合 JITモードよりピーク時スループットが低い サーバーレスJavaはFaaSであるため JVM実⾏環境はリクエストごとに 分散することが強み 0 5 10 15 20 25 30 Startup Speed Peak Throughput Max Latency Package Size Memory Footprint AOT JIT
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. パフォーマンス選⼿権
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. コールドスタートタイム(平均・ミリ秒) 2,223.30 965.13 2,329.84 506.67 413.18 3,940.32 584.34 0.00 500.00 1,000.00 1,500.00 2,000.00 2,500.00 3,000.00 3,500.00 4,000.00 4,500.00 1. Pure Java 2. Pure Java SnapStart 3. Framework 4. Framework SnapStart 5. Framework Native Image 6. Framework Web Adapter 7. Framework Web Adapter × Native Image コールドスタートタイム(平均・ミリ秒) コールドスタートタイム(平均・ミリ秒) Native Imageが最も⾼速なコールドスタートタイムを獲得
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. E2E 90%タイル レイテンシー(秒) 2.58 1.83 2.71 1.28 0.81 4.42 1.01 0.00 0.50 1.00 1.50 2.00 2.50 3.00 3.50 4.00 4.50 5.00 1. Pure Java 2. Pure Java SnapStart 3. Framework 4. Framework SnapStart 5. Framework Native Image 6. Framework Web Adapter 7. Framework Web Adapter × Native Image E2E 90%タイル レイテンシー(秒) E2E 90%タイル レイテンシー(秒) レイテンシーはネイティブイメージが短く、Jarは⻑い
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. パッケージのビルド時間(秒) 4.34 3.65 4.35 3.80 336.00 5.89 327.00 0.00 50.00 100.00 150.00 200.00 250.00 300.00 350.00 400.00 1. Pure Java 2. Pure Java SnapStart 3. Framework 4. Framework SnapStart 5. Framework Native Image 6. Framework Web Adapter 7. Framework Web Adapter × Native Image パッケージのビルド時間(秒) パッケージのビルド時間(秒) Jarは4秒前後。Native Imageは3~5分でビルド時間がネックに
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. 0 0 0 0 0 0 1 0 0.2 0.4 0.6 0.8 1 1.2 1. Pure Java 2. Pure Java SnapStart 3. Framework 4. Framework SnapStart 5. Framework Native Image 6. Framework Web Adapter 7. Framework Web Adapter × Native Image ウォームアップ(合計・数) ウォームアップ(合計・数) ウォームアップ(合計) Native Imageがウォームアップ数を獲得。 Jarはウォームアップ数0
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. パッケージサイズ(MB) 12.20 12.20 14.20 14.20 62.30 24.10 40.00 0.00 10.00 20.00 30.00 40.00 50.00 60.00 70.00 1. Pure Java 2. Pure Java SnapStart 3. Framework 4. Framework SnapStart 5. Framework Native Image 6. Framework Web Adapter 7. Framework Web Adapter × Native Image パッケージサイズ(MB) パッケージサイズ(MB) Pure Javaが最も軽量なパッケージサイズを実現可能
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. まとめ サーバーレスJavaに銀の弾丸はない しかしながら、ネイティブイメージに変換することで 他のランタイムに引けを取らないまでに コールドスタートを⾼速化 開発メンバーの習熟度から技術スタックを選択し AWS Lambda Web Adapter、Native Imageを プロダクションで活⽤︕よりよいサーバーレスJavaライフを︕
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Appendix GitHub 1. Pure Java https://github.com/x-blood/awsdevday2023tokyo-sls-framework 2. Pure Java SnapStart https://github.com/x-blood/awsdevday2023tokyo-sls-pure-java-snapstart 3. Framework https://github.com/x-blood/awsdevday2023tokyo-sls-framework 4. Framework SnapStart https://github.com/x-blood/awsdevday2023tokyo-sls-framework-snapstart 5. Framework Native Image https://github.com/x-blood/awsdevday2023tokyo-sls-framework-native-image 6. Framework Web Adapter https://github.com/x-blood/awsdevday2023tokyo-sls-framework-web-adapter 7. Framework Web Adapter + Native Image https://github.com/x-blood/awsdevday2023tokyo-sls-framework-web-adapter-native-image
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Appendix 1. Pure Java Benchmark Details AWS Lambda Category Result Value Cold Starts Count 200 Total Duration avg (ms) 2,223.30 ms Init Duration avg (ms) 1,605.63 ms Restore Duration avg (ms) - Max Memory Used avg (mb) 156.27 MB Build Times (sec) 4.35 sec Binary Size (mb) 12.20 MB E2E Category Result Value Duration avg (sec) 2.48 sec Duration 90% (sec) 2.58 sec Duration 95% (sec) 2.62 sec https://github.com/x-blood/awsdevday2023tokyo-sls-framework
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Appendix 2. Pure Java SnapStart Benchmark Details AWS Lambda Category Result Value Cold Starts Count 200 Total Duration avg (ms) 965.13 ms Init Duration avg (ms) - Restore Duration avg (ms) 277.04 ms Max Memory Used avg (mb) 128.01 MB Build Times (sec) 3.65 sec Binary Size (mb) 12.20 MB E2E Category Result Value Duration avg (sec) 1.60 sec Duration 90% (sec) 1.83 sec Duration 95% (sec) 1.90 sec https://github.com/x-blood/awsdevday2023tokyo-sls-pure-java-snapstart
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Appendix 3. Framework Benchmark Details AWS Lambda Category Result Value Cold Starts Count 200 Total Duration avg (ms) 2,329.84 ms Init Duration avg (ms) 2,242.34 ms Restore Duration avg (ms) - Max Memory Used avg (mb) 173.69 MB Build Times (sec) 4.35 sec Binary Size (mb) 14.20 MB E2E Category Result Value Duration avg (sec) 2.60 sec Duration 90% (sec) 2.71 sec Duration 95% (sec) 2.73 sec https://github.com/x-blood/awsdevday2023tokyo-sls-framework
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Appendix 4. Framework SnapStart Benchmark Details AWS Lambda Category Result Value Cold Starts Count 200 Total Duration avg (ms) 506.67 ms Init Duration avg (ms) - Restore Duration avg (ms) 262.40 mx Max Memory Used avg (mb) 134.76 MB Build Times (sec) 3.80 sec Binary Size (mb) 14.20 MB E2E Category Result Value Duration avg (sec) 1.17 sec Duration 90% (sec) 1.28 sec Duration 95% (sec) 1.31 sec https://github.com/x-blood/awsdevday2023tokyo-sls-framework-snapstart
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Appendix 5. Framework Native Image Benchmark Details AWS Lambda Category Result Value Cold Starts Count 200 Total Duration avg (ms) 413.18 ms Init Duration avg (ms) 269.52 ms Restore Duration avg (ms) - Max Memory Used avg (mb) 79.01 MB Build Times (sec) 336.00 sec Binary Size (mb) 62.30 MB E2E Category Result Value Duration avg (sec) 0.76 sec Duration 90% (sec) 0.81 sec Duration 95% (sec) 0.82 sec https://github.com/x-blood/awsdevday2023tokyo-sls-framework-native-image
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Appendix 6. Framework Web Adapter Benchmark Details AWS Lambda Category Result Value Cold Starts Count 200 Total Duration avg (ms) 3940.32 ms Init Duration avg (ms) 2217.41 ms Restore Duration avg (ms) - Max Memory Used avg (mb) 206.41 MB Build Times (sec) 5.89 sec Binary Size (mb) 24.10 MB E2E Category Result Value Duration avg (sec) 4.14 sec Duration 90% (sec) 4.42 sec Duration 95% (sec) 4.57 sec https://github.com/x-blood/awsdevday2023tokyo-sls-framework-web-adapter
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Appendix 7. Framework Web Adapter Native Image Benchmark Details AWS Lambda Category Result Value Cold Starts Count 199 Total Duration avg (ms) 584.34 ms Init Duration avg (ms) 471.34 ms Restore Duration avg (ms) - Max Memory Used avg (mb) 76.54 MB Build Times (sec) 327.00 sec Binary Size (mb) 40.00 MB E2E Category Result Value Duration avg (sec) 0.96 sec Duration 90% (sec) 1.01 sec Duration 95% (sec) 1.05 sec https://github.com/x-blood/awsdevday2023tokyo-sls-framework-web-adapter-native-image
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Thank you! © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 佐藤 靖幸 @yasai_ls
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Please complete the session survey © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.