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
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
52
re:Inventで現地参加したコンテナ関連セッションを振り返る
xblood
0
570
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.5k
ECS Service Connectでマイクロサービスを繋いでみた
xblood
0
2.5k
AWS Glue Git統合のPoCでの活用
xblood
0
240
Spring BootとKubernetesで実現する今どきのDevOps入門
xblood
1
1.3k
Other Decks in Programming
See All in Programming
RSSとCodexを使ってX投稿自動化してみた
ochtum
0
100
レビュー履歴をAIに食わせて、 Compose移行を加速するs
shihochan
0
260
『寄り添うラジオ』をAIで作る 体験価値から逆算した、会話しないUXと品質設計
theoriatec2024
2
110
PyO3 で既存 Python 評価器を Rust core 化する ー wasm-bindgen でブラウザにも配るための設計
kdash
1
420
AI に Inclusive UI を書かせよう — Design Rules Skill で Compose UI を作り直す
theoriatec2024
1
450
MySQLとPostgreSQLって何が違うの?
akagami
PRO
0
170
20260828_品質と開発生産性を両立させる、AI時代のE2Eテストの考え方
magicpod
0
160
信頼性の目標を誰も求めてない
shubox
0
490
typoなんかねぇよ
raspython3
0
660
型解析で実現する Go の言語内 DSL / Conference に Go! タイムテーブルの歩き方 for Gophers
mazrean
0
130
in-process GraphQL のすすめ #ginzajs
izumin5210
4
1.5k
AWS Step Functions 大規模並列の壁を越える / jaws-sonic-2026-niigata-step-functions
kasacchiful
PRO
0
370
Featured
See All Featured
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
920
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
560
Designing for Timeless Needs
cassininazir
1
470
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.9k
AI: The stuff that nobody shows you
jnunemaker
PRO
9
970
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Practical Orchestrator
shlominoach
191
12k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
470
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
250
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
400
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.