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's OOM and k8s' OOM 遭遇した2つのOOMと対策 ~ Launcha...
Search
Konboi
June 09, 2025
1
130
Java's OOM and k8s' OOM 遭遇した2つのOOMと対策 ~ Launchableでの事例 ~ / JJUG 2025 Spring
Konboi
June 09, 2025
Tweet
Share
More Decks by Konboi
See All by Konboi
非同期開発体制を支えるドキュメント文化 / YAPC::Hiroshima 2024
konboi
28
11k
様々な環境へコマンドラインツールを提供する上での苦労とその対策 / YAPC::Kyoto 2023
konboi
0
2.9k
煩雑な運用を Goを使って楽にする / Go Conference 2019 Spring
konboi
4
4.5k
あなたってどんな方(型)?/ kamakura.go#4
konboi
1
600
中規模チームを支える自動化とノウハウ共有の仕組み/CEDEC2017
konboi
8
9.7k
golang tokyo #6 / ゲーム開発には欠かせない?! あれをシュッと見る
konboi
1
7.6k
git-schemlexとddl-makerを使ったDB migrationの紹介 / git-schemalex and ddl-maker migration #golangtokyo
konboi
1
10k
Redisの調査についてとrmlp
konboi
5
4.5k
カヤックの新卒研修 #師弟登壇2015
konboi
0
3.8k
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
Producing Creativity
orderedlist
PRO
346
40k
Testing 201, or: Great Expectations
jmmastey
42
7.6k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3.1k
A Tale of Four Properties
chriscoyier
160
23k
The Cult of Friendly URLs
andyhume
79
6.5k
Designing for humans not robots
tammielis
253
25k
The Straight Up "How To Draw Better" Workshop
denniskardys
234
140k
Embracing the Ebb and Flow
colly
86
4.7k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
181
53k
The Invisible Side of Design
smashingmag
300
51k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Transcript
Java's OOM and k8s' OOM 遭遇した2つのOOMと対策 ~ Launchableでの事例 ~ 2025.06.07
Presented by Ryosuke Yabuki a.k.a Konboi
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. 自己紹介 • 矢吹遼介
a.k.a Konboi • CloudBees, Inc. ◦ ex.Launchable - 昨年7月に買収されました • Sr. Software Engineer • JJUG初参加 & 初登壇 • SNS ◦ blog: https://blog.konboi.com ◦ GitHub/X(twitter)/Bluesky: Konboi
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. アジェンダ • 運用しているサービスの紹介
• Java's OOM Part ◦ 発生した事象について ◦ どのように対応したか • k8s' OOM Part ◦ 発生した事象について ◦ k8s の Resource - RequestsとLimitについて ◦ HeapとOff Heap ◦ どのように対応したか • まとめ
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. 運用しているサービスの紹介 • テストの結果を集め
AIを使ってテストにまつわる困り事を助けるサービス • Case: テスト結果の収集 ◦ 数百 ~ 数百万のテスト結果を受け取り保存 ◦ CPU Heavy な処理が多い
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. 運用しているサービスの紹介 • Case:
Predictive Test Selection - 効率的なテストの実施をサポート ◦ テストのリストを受け取り失敗しやすいテストリストを返す ◦ 数MB ~ 数百MBの機械学習モデルを使用した処理 ◦ Memory Heavy な処理 ▪ リストのサイズによっても CPUもHeavy • 特性の異なる処理を 1つのアプリケーションで処理
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. あらまし Java /
k8s の OOMが起きるまで...
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. あらまし • テスト結果収集簡略化のため
Jenkins Plugin の新規開発 ◦ 通常はCLIをセットアップし利用してもらう • Plugin をインストールするだけでテスト結果を送信できるように
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. あらまし • リリース前に社内でドッグフーディング
• 社内のJenkins CI サーバー のプロジェクトにテスト導入 ◦ 直列実行だと約50時間 ◦ テストケース数は 3万件以上 • 結果... ◦ Java の OOM ◦ k8s の OOM
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. Java Part
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. 発生した事象 - Java
part • 社内CIサーバーにプラグインをインストール後 • 複数の 5xx エラーを観測 • Sentryで原因が OOM なのを確認
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. 原因 - Java
part • 送られてきたテスト結果を一時的に全てメモリーにロード • 想定よりも件数/サイズが多くメモリに乗り切らず OOM が発生
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. 原因 - Java
part • 送られてきたテスト結果を一時的に全てメモリーにロード • 想定よりもサイズが多くメモリに乗り切らず OOM が発生
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. どのように対応したか - Java
part • 該当箇所をストリームで処理するように修正 • OOM 時に heap dump を取るように変更 ◦ XXHeapDumpPath=/foo/bar/
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. まとめ - Java
part • 一気にメモリに載せるような処理は避けましょう ◦ 意図せずそうなってしまう場合も ◦ 想定よりもデータのサイズが大きいことも ありますよね... • heap dump をとるようにしましょう ◦ 今回は原因がすぐに判明したが ... ◦ ⚠ dump file はサイズが大きくなりがち。 disk space に注意
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. Kubernetes Part
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. 発生した事象 - k8s
part • Java側の修正を反映後 頻繁にPodが再起動するように ...
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. 発生した事象 - k8s
part • 調査してみると OOM Kill されていた • ただ heap dump file は作成されず ◦ なぜ...? 🤔 • 何が原因か手がかりが得られず
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. k8s の Resource
および Requests / Limits
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. k8s の Resource
および Requests/Limits
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. k8s の Resource
および Requests/Limits
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. k8s の Resource
および Requests/Limits
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. k8s の Resource
および Requests/Limits
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. k8s の Resource
および Requests/Limits • Requests: ◦ Podを動かすための必要なリソース ◦ Nodeのリソースとrequests を見比べてPodの配置を決める • Limits: ◦ Podが使っていいリソースの上限 ◦ 超過すると... ▪ CPUは制限される ▪ メモリは OOM で Kill される
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. k8s の Resource
および Requests/Limits • Requests: ◦ Podを動かすための必要なリソース ◦ Nodeのリソースとrequests を見比べてPodの配置を決める • Limits: ◦ Podが使っていいリソースの上限 ◦ 超過すると... ▪ CPUは制限される ▪ メモリは OOM で Kill される
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. k8s の Resource
および Requests/Limits • Requests: ◦ Podを動かすための必要なリソース ◦ Nodeのリソースとrequests を見比べてPodの配置を決める • Limits: ◦ Podが使っていいリソースの上限 ◦ 超過すると... ▪ CPUは制限される ▪ メモリは OOM で Kill される
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. Java側と思っていたが...
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. k8s の Resource
および Requests/Limits
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. k8s の Resource
および Requests/Limits OOM
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. k8s の Resource
および Requests/Limits Restart
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. k8s側で発生していた
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. k8s の Resource
および Requests/Limits
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. k8s の Resource
および Requests/Limits
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. k8s の Resource
および Requests/Limits
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. k8s の Resource
および Requests/Limits
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. k8s の Resource
および Requests/Limits
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. k8s の Resource
および Requests/Limits
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. k8s の Resource
および Requests/Limits
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. k8s の Resource
および Requests/Limits OOM Kill
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. k8s の Resource
および Requests/Limits
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. k8s の Resource
および Requests/Limits
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. k8s の Resource
および Requests/Limits
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. 発生した事象 - k8s
part • よくよくMessageを見てみると... • Pod は OOM で Kill され 再起動していた • “OOMˮ だから Java 側だと勘違いしていた ◦ Java側の対応をしたばかりというのもあり ...) • k8s 側の OOM だから heap dump file が無いのは当たり前
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. 発生した事象 - k8s
part • でも、何故 limits を指定してるのに こんなにメモリが使われているんだ ...? 🤔 • 8178740Ki → 約8GB • JVM の オプションで Xmx 5G と最大ヒープサイズを指定している
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. Java JVM の
Heap と Off Heap
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. Java JVM の
Heap と Off Heap • Heap ◦ JVMに割り当てられるメモリ ◦ Java Object は Heap領域 に生成される ◦ GC の対象 • Off Heap ◦ ヒープ外に割り当てられるメモリ ◦ GC の対象外 ◦ 大規模なデータ処理に使われる
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. Java JVM の
Heap と Off Heap • Off Heap の利用サイズを指定できるオプションもある • が、デフォルトでは Heap Size を基準に決まるものも • e.g.) XXMaxDirectMemorySize ◦ ~ Java 8: heap size の 87.5% ◦ Java 11 heap size と 同サイズ ▪ OpenJ9 の場合 • JVM の Option によってまちまち
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. 発生した事象 - k8s
Part • 処理するデータサイズが増 • Off Heap が今まで以上に使われるようになった • Heap サイズ + Off Heap サイズ > k8sʼ Limits ◦ 10 (= 5 5 > 6 • k8s の OOMKilled が頻発
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. どのように対応したか - k8s
Part • Resource / Limit の サイズを見直し • メモリ使用量の監視強化 • スケーリング戦略の調整 • JVMの監視もしたいけど後回しに ...)
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. まとめ • Java
と k8s 2 つの OOM について Launchable で起きた事例紹介 • k8s の Resource および Requests / Limits • Heap と Off Heap • k8s 環境における Java アプリケーション の メモリ管理の難しさ
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. Weʼre Hiring •
AI & ML Engineer を募集しています • 日本から世界と戦いませんか? • 気になったら気軽に DMください!!
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. おまけ • 問題は解決したが調査したところ
Jenkins Plugin にバグがあった • 既に送った結果も重複して送っていた Workflow 1-1 Workflow 1-2 Workflow 1-3 Workflow 2-1 Workflow 2-2 Workeflow 2-3
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. おまけ • 問題は解決したが調査したところ
Jenkins Plugin にバグがあった • 既に送った結果も重複して送っていた Workflow 1-1 Workflow 1-2 Workflow 1-3 Workflow 2-1 Workflow 2-2 Workeflow 2-3 Send
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. おまけ • 問題は解決したが調査したところ
Jenkins Plugin にバグがあった • 既に送った結果も重複して送っていた Workflow 1-1 Workflow 1-2 Workflow 1-3 Workflow 2-1 Workflow 2-2 Workeflow 2-3 Send Send
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. おまけ • 問題は解決したが調査したところ
Jenkins Plugin にバグがあった • 既に送った結果も重複して送っていた Workflow 1-1 Workflow 1-2 Workflow 1-3 Workflow 2-1 Workflow 2-2 Workeflow 2-3 Send Send Send
Confidential. ©2025 CloudBees, Inc. All Rights Reserved. おまけ • リリース前のテスト大事
• バグで色々大変だったけどこうやって JVM x k8s についての知見が増えた