Top Banner
HeapStats: Troubleshooting with Serviceability and the New Runtime Monitoring Tool 2015/07/03 TechLunch #21 NTT OSSセンタ 久保田祐史 Copyright©2015 NTT corp. All Rights Reserved.
48

HeapStats: Introduction and Technical Preview

Aug 06, 2015

Download

Technology

Yuji Kubota
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: HeapStats: Introduction and Technical Preview

HeapStats: Troubleshooting with Serviceability and the New

Runtime Monitoring Tool

2015/07/03 TechLunch #21 NTT OSSセンタ 久保田祐史

Copyright©2015 NTT corp. All Rights Reserved.

Page 2: HeapStats: Introduction and Technical Preview

NTT OSSセンタ所属

IcedTea Committer OpenJDK Contributor icedtea / openjdk 寄り

Copyright©2015 NTT corp. All Rights Reserved. 2

Page 3: HeapStats: Introduction and Technical Preview

JVM 芸人 Speaker:

JavaOne 2014 JJUG CCC 2014

etc…

Copyright©2015 NTT corp. All Rights Reserved. 3

Page 4: HeapStats: Introduction and Technical Preview

NTT OSSセンタ •  OSS活用によるNTTグループの社内システムのTCO削減とSI競争力強化を目的に2006年設立事業現場でのOSS導入阻害要因の解消をめざす *)OSSVERT®:OSs Suites VERified Technically(技術検証済みOSS組合せ)

事業会社

 SI会社  問合せ対応、 導入支援、

プロダクト保守等

技術検証、検証済OSSの導入推進

プロダクト/ ツール類の開発

技術者育成、人材交流

各種 OSS コミュニティ

設計, 開発, 運用

グループ各社

サポートベンダ、 NTT

研究所等 お客様

サポート 連携

開発 連携

①OSSトータル  サポート

NTT OSSセンタ

②OSS適用推進   (OSSVERT®*検証)

③技術開発   (DBMS,高可用ミドル等)

④ソフトウェア  基盤技術力向上

Copyright©2015 NTT corp. All Rights Reserved. 4

Page 5: HeapStats: Introduction and Technical Preview

NTT OSSセンタ ポータルサイト •  http://www.oss.ecl.ntt.co.jp/ossc/

Copyright©2015 NTT corp. All Rights Reserved. 5

Page 6: HeapStats: Introduction and Technical Preview

•  Troubles with JVM •  HeapStats Overview

– HeapStats Agent – HeapStats Analyzer – Demonstration

•  Community •  Technical Preview

Copyright©2015 NTT corp. All Rights Reserved. 6

Agenda

Page 7: HeapStats: Introduction and Technical Preview

Troubles with JVM Caused by: java.sql.SQLException: プロトコル違反です。

at xxx.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112) at xxx.jdbc.driver.Statement.executeForDescribe(Statement.java:804) at xxx.jdbc.driver. Statement.doExecuteWithTimeout(Statement.java:1154) at xxx.jdbc.driver.Statement.executeQuery(Statement.java:1313) at com.xxx.query.QueryDataSet.<init>(QueryDataSet.java:80) at org.xxx.database.util.BaseSQL.executeQuery(BaseSQL.java:930) ... 26 more

Exception in thread "TP-Processor9" java.lang.OutOfMemoryError: Java heap space java.lang.OutOfMemoryError: Java heap space

at java.util.Arrays.copyOfRange(Arrays.java:3221) at java.lang.String.<init>(String.java:233) at javax.servlet.http.HttpServlet.service(HttpServlet.java:723) at javax.servlet.http.HttpServlet.service(HttpServlet.java:723) at javax.servlet.http.HttpServlet.service(HttpServlet.java:643) at javax.servlet.http.HttpServlet.service(HttpServlet.java:723) at java.lang.Thread.run(Thread.java:619)

Copyright©2015 NTT corp. All Rights Reserved. 7

Page 8: HeapStats: Introduction and Technical Preview

時間の流れ

時間の流れ

障害解析の理想と現実 対策完了

定常 運用

各種ログ・ツールを 用いた効率的な解析

問題の対処

障害 解決 …

障害発生

障害再現

原因の特定

障害発生

理想

• 商用環境では解析に必要なログを収集してなかった

障害の再現待ち& 各種ログ情報の取得

サービス再開

現実 定常 運用

サービス再開

Copyright©2015 NTT corp. All Rights Reserved. 8

Page 9: HeapStats: Introduction and Technical Preview

時間の流れ

時間の流れ

障害解析の理想と現実 対策完了

定常 運用

各種ログ・ツールを 用いた効率的な解析

問題の対処

障害発生 原因の特定

障害発生 原因の特定 対策完了

現実

理想

定常 運用

各種ログ・ツールを 複数用いた手作業での解析

問題の対処

障害 解決 …

サービス再開

• 分析の前準備が非常に煩雑 • 商用環境で手作業でのログ収集は高リスク(手順ミス、高負荷)

障害の再現待ち& 各種ログ情報の取得

障害再現

障害 解決 …

サービス再開

Copyright©2015 NTT corp. All Rights Reserved. 9

Page 10: HeapStats: Introduction and Technical Preview

時間の流れ

時間の流れ

障害解析の課題 対策完了

定常 運用

各種ログ・ツールを 用いた効率的な解析

問題の対処

障害発生 原因の特定

障害発生 原因の特定 対策完了

現実

理想

定常 運用

各種ログ・ツールを 複数用いた手作業での解析

問題の対処

障害 解決 …

サービス再開

• 素早く障害解決するために… • ログを常に収集する • 導入等が簡単、低負荷である

障害の再現待ち& 各種ログ情報の取得

障害再現

障害 解決 …

サービス再開

Copyright©2015 NTT corp. All Rights Reserved. 10

Page 11: HeapStats: Introduction and Technical Preview

HeapStats Overview

アプリケーションサーバ

• メモリリークの予兆検知! • デッドロック検知! • 障害発生!

情報収集 解析

自動で障害発生時に 詳細情報を収集

HeapStats アナライザ

※1 SPECjvm2008のComposite resultによる測定 ※2 運用監視ソフトや製品と組み合わせることで通知が行えます

迅速な状況通知(※2)

SNMPトラップ

5%(※1)以下の低オーバヘッドで常時情報収集

HeapStats JVM監視エージェント

迅速な 原因分析

Copyright©2015 NTT corp. All Rights Reserved. 11

Page 12: HeapStats: Introduction and Technical Preview

HeapStats Overview

アプリケーションサーバ

• メモリリークの予兆検知! • デッドロック検知! • 障害発生!

情報収集 解析

自動で障害発生時に 詳細情報を収集

HeapStats アナライザ

※1 SPECjvm2008のComposite resultによる測定 ※2 運用監視ソフトや製品と組み合わせることで通知が行えます

迅速な状況通知(※2)

SNMPトラップ

5%(※1)以下の低オーバヘッドで常時情報収集

HeapStats JVM監視エージェント

迅速な 原因分析

Copyright©2015 NTT corp. All Rights Reserved. 12

Page 13: HeapStats: Introduction and Technical Preview

HeapStats Agent •  RPM コマンドから楽々インストール

–  rpm -ivh heapstats-<version>.rpm •  Java 起動オプションを一つ追加でOK!

–  java -agentlib:heapstats YourApp •  実行中の Java プロセスにも設定可能!

– 再起動の必要なし •  継続的に各種詳細情報をファイル出力

Copyright©2015 NTT corp. All Rights Reserved. 13

Page 14: HeapStats: Introduction and Technical Preview

282.68 269.92

0 50

100 150 200 250 300

Without HeapStats With HeapStats

4.51 %

(ops/m)

SPECjvm2008 Composite Result

• ベンチマークツール: SPECjvm2008 1.01 • マシン: DELL PowerEdge R810(Xeon X7542、メモリ32GB) •  OS: Red Hat Enterprise Linux Server release 6.3 x86_64 •  Java:      java-1.7.0-openjdk-1.7.0.25-2.3.10.4.el6_4.x86_64 •  java起動オプション: -Xms4500m -Xmx4500m -XX:+UseG1GC -agentpath:<エージェントライブラリ>

オーバヘッド

Copyright©2015 NTT corp. All Rights Reserved. 14

※ 測定環境

Page 15: HeapStats: Introduction and Technical Preview

HeapStats Overview

アプリケーションサーバ

• メモリリークの予兆検知! • デッドロック検知! • 障害発生!

情報収集 解析

自動で障害発生時に 詳細情報を収集

HeapStats アナライザ

※1 SPECjvm2008のComposite resultによる測定 ※2 運用監視ソフトと組み合わせることでメール通知なども行えます

迅速な状況通知(※2)

SNMPトラップ

5%(※1)以下の低オーバヘッドで常時情報収集

HeapStats JVM監視エージェント

迅速な 原因分析

Copyright©2015 NTT corp. All Rights Reserved. 15

Page 16: HeapStats: Introduction and Technical Preview

HeapStats Analyzer •  Java 製 GUI Viewer

– Java 解析なので Java がある前提 – java -jar heapstats.jar (※JDK6以上)

• 一覧性の高い時系列画面等を提供 – 状況を一目で確認しやすい – CSV にコンバートする機能もある

Copyright©2015 NTT corp. All Rights Reserved. 16

Page 17: HeapStats: Introduction and Technical Preview

Demonstration

アナライザ

①サンプル起動

④スナップショット解析

Webブラウザ

APサーバ

エージェント

②メモリ使用量増加

スナップショット

③OutOf MemoryError

標準出力

• メモリリーク発生事例

Copyright©2015 NTT corp. All Rights Reserved. 17

Page 18: HeapStats: Introduction and Technical Preview

プロセスリソース(OS/JVM)

Copyright©2015 NTT corp. All Rights Reserved. 18

Page 19: HeapStats: Introduction and Technical Preview

GC時間, ヒープ, メタスペース

Copyright©2015 NTT corp. All Rights Reserved. 19

Page 20: HeapStats: Introduction and Technical Preview

クラスヒストグラム(特定時刻)

Copyright©2015 NTT corp. All Rights Reserved. 20

Page 21: HeapStats: Introduction and Technical Preview

クラスヒストグラム(時系列)

Copyright©2015 NTT corp. All Rights Reserved. 21

Page 22: HeapStats: Introduction and Technical Preview

オブジェクト参照関係

Copyright©2015 NTT corp. All Rights Reserved. 22

Page 23: HeapStats: Introduction and Technical Preview

障害発生時の詳細情報

Copyright©2015 NTT corp. All Rights Reserved. 23

Page 24: HeapStats: Introduction and Technical Preview

HeapStats のメリット n  再現待ち・手作業からの解放

n  Javaアプリ利用のシステムにおける障害解析のスピードアップ・効率化を狙い、運用中の商用システムにおいても即座に解析が可能な支援ツールを開発

n  HeapStats を入れるだけで様々な情報が自動的に収集される

n  素早い初動解析 n  ヒープ情報を詳細に収集、分析が可能 n  この他、OSレベル/Javaレベルで詳細な情報を収集

n  OS:CPU使用率、ネイティブメモリ使用量、ソケットエンドポイント、等 n  Java:ライブスレッド数、ロック競合回数、完全停止(Stop-The-World)時間等

n  リアルタイムな検知・通知 n  特定インスタンスのメモリ使用量、あるいはヒープメモリの総使用量が閾値を超えた場合、SNMPトラップで外部へ通知

n  Javaスレッド間のデッドロックをリアルタイムに検知し、SNMP等で外部へ通知することが可能 Copyright©2015 NTT corp. All Rights Reserved. 24

Page 25: HeapStats: Introduction and Technical Preview

HeapStats のメリット n  再現待ち・手作業からの解放

n  Javaアプリ利用のシステムにおける障害解析のスピードアップ・効率化を狙い、運用中の商用システムにおいても即座に解析が可能な支援ツールを開発

n  HeapStats を入れるだけで様々な情報が自動的に収集される。

n  素早い初動解析 n  ヒープ情報を詳細に収集、分析が可能。 n  この他、OSレベル/Javaレベルで詳細な情報を収集

n  OS:CPU使用率、ネイティブメモリ使用量、ソケットエンドポイント、等 n  Java:ライブスレッド数、ロック競合回数、完全停止(Stop-The-World)時間等

n  リアルタイムな検知・通知 n  特定インスタンスのメモリ使用量、あるいはヒープメモリの総使用量が閾値を超えた場合、SNMPトラップで外部へ通知

n  Javaスレッド間のデッドロックをリアルタイムに検知し、SNMP等で外部へ通知することが可能

Pros •  確実な初期行動がとれる •  メモリ絡みの問題はほぼ撃墜できる •  オーバーヘッドはかなり低い Cons •  スレッド周りの時系列情報が取れない

•  瞬間情報はスレッドダンプで確認可能 •  プロファイリング情報は取れない

Copyright©2015 NTT corp. All Rights Reserved. 25

Page 26: HeapStats: Introduction and Technical Preview

HeapStats 次期バージョン •  スレッド監視

– スレッドの状態を監視・収集し、時系列に表示する

•  Analyzer の JavaFX 版、CLI 版を提供 – 操作性が向上し、より直感的な UI へ – ターミナル上で完結する仕組みを提供

•  オールインワンパッケージ – 今は命令セットごとにパッケージを用意

•  2015年9月末リリース予定 Copyright©2015 NTT corp. All Rights Reserved. 26

Page 27: HeapStats: Introduction and Technical Preview

HeapStats Community

Copyright©2015 NTT corp. All Rights Reserved. 27

•  Committers – Yasumasa Suenaga (末永恭正) – KUBOTA Yuji (久保田祐史) – TAKAO Shinji (髙雄慎二)

•  Web Site –  http://icedtea.classpath.org/wiki/HeapStats –  http://icedtea.classpath.org/pipermail/heapstats/

Page 28: HeapStats: Introduction and Technical Preview

28 Copyright©2015 NTT corp. All Rights Reserved.

Java Day Tokyo 2015 にて

国内の OpenJDK コミュニティ貢献者が開発している

Page 29: HeapStats: Introduction and Technical Preview

•  知らないなんてもったいない! 障害発生の原因を洗い出すOSSのJavaVM解析支援ツール「HeapStats」を使ってみよう

•  http://codezine.jp/article/detail/8332

CodeZine 記事も

Copyright©2015 NTT corp. All Rights Reserved. 29

Page 30: HeapStats: Introduction and Technical Preview

HeapStats Technical Preview

Copyright©2015 NTT corp. All Rights Reserved. 30

Page 31: HeapStats: Introduction and Technical Preview

Copyright©2015 NTT corp. All Rights Reserved. 31

• 基本方針 – JVM から良い感じに情報収集 – 情報 = ヒープ上のクラス情報

• 他にもスレッド情報等があるが、 今回は割愛

HeapStats Agent の実装

Page 32: HeapStats: Introduction and Technical Preview

•  Java Agent – コードを動的に操作可能な、プロファイリング/デバッグの基本テクニック

– HeapStats は JVM TI を利用している • http://www.oracle.com/technetwork/

articles/java/jvmti-136367.html Copyright©2015 NTT corp. All Rights Reserved. 32

JVM から情報を引っ張る

Page 33: HeapStats: Introduction and Technical Preview

JVM TI (Tool Interface) •  JVM レベルで操作・把握が可能 • コールバックを任意に設定可能

– GC前後, 特定フィールド変更時, 等 • プラットフォーム依存がある

– HeapStats は Linux 限定 Copyright©2015 NTT corp. All Rights Reserved. 33

Page 34: HeapStats: Introduction and Technical Preview

JVM TI (Tool Interface) •  JVM レベルで操作・把握が可能 • コールバックを任意に設定可能

– GC前後, 特定フィールド変更時, 等 • プラットフォーム依存がある

– HeapStats は Linux 限定

JVMの保護が得られない = SEGV との戦い

Copyright©2015 NTT corp. All Rights Reserved. 34

嫌でも OpenJDK に 詳しくなれる

Page 35: HeapStats: Introduction and Technical Preview

low-overhead を目指す

Copyright©2015 NTT corp. All Rights Reserved. 35

•  Major GCと同期して情報収集 – Java オブジェクトの C++ 表現(=oop,

Ordinary Object Pointer)を収集する – 収集の際に STW が懸かるのを避ける

• ロードしているクラス情報の一括取得 • Java ヒープのスキャン

Page 36: HeapStats: Introduction and Technical Preview

Thread stack

Object monitor

JNI Reference

GC Root ✔ ✔ ✔

✔ ✔

✔ ✔ ✔ ✔

Sweep

Live object

Mark

GC process of HotSpot VM

Copyright©2015 NTT corp. All Rights Reserved. 36

この情報が欲しい

実際はスタック/キューで管理され、子要素 (対象oop) が0になると終了

この情報は不要

Page 37: HeapStats: Introduction and Technical Preview

✔ Object

virtual calculateSize() :

JVM internal (C++)

Java Object

virtual marking() Class Object

virtual marking() Primitive Object

virtual marking()

vtable

marking virtual marking()

Override to collect

override_marking(AMD64): push [register for argument] mov [argument] [register] call [collect information method] pop [register for argument] jmp XXObject::marking

Marking

Save the stack and register for resume

the GC process.

How to hook the marking

Copyright©2015 NTT corp. All Rights Reserved. 37

Page 38: HeapStats: Introduction and Technical Preview

Java ヒープ占有オブジェクト (oop) •  instanceKlass

– インスタンスクラスのC++表現 •  objArrayKlass

–  Javaオブジェクト配列クラスのC++表現 •  typeArrayKlass

– プリミティブ配列クラスのC++表現 •  instanceRefKlass

– Weak参照やSoft参照など、参照形態の異なる(いわゆる弱参照系)インスタンスクラスのC++表現

38 Copyright©2015 NTT corp. All Rights Reserved.

これらを計算対象とすればヒープ上の情報は網羅的に収集できる

Page 39: HeapStats: Introduction and Technical Preview

•  -XX:ParallelGC – *Klass::oop_follow_contents(oopDesc*)

•  -XX:ParallelOldGC – *Klass::oop_follow_contents(ParCompaction

Manager*, oopDesc*)

•  この関数を経由して marking が行われる – oopDesc* (= typedef oop) を取得すれば各種

oop の情報が marking と同期して得られる 39 Copyright©2015 NTT corp. All Rights Reserved.

jdk8u45 Parallel GC の場合

Page 40: HeapStats: Introduction and Technical Preview

40 Copyright©2015 NTT corp. All Rights Reserved.

CMS GC の場合 jdk8u45

• 実は marking では情報が取れない – concurrent に実行される都合上、多数の OopClosure を介する

– OopClosure の non virtual 関数が marking を行うためフックできない

Page 41: HeapStats: Introduction and Technical Preview

41 Copyright©2015 NTT corp. All Rights Reserved.

CMS GC の場合 jdk8u45

• New 世代対策 – Remark フェーズで New 世代をフルスキャンするのでそこをフック • Remark: Javaスレッドを止めて全ヒープ漏れなくマークするフェーズ

Page 42: HeapStats: Introduction and Technical Preview

42 Copyright©2015 NTT corp. All Rights Reserved.

CMS GC の場合 jdk8u45

•  Old 世代対策 – Sweep フェーズで Old 世代をフルスキャンするのでフック • Sweep: ゴミ掃除フェーズ • マーク済かはCMSBitMap が保持しているので利用してマーク済 oop だけ収集 ※:マーク済 oop = Live object

Page 43: HeapStats: Introduction and Technical Preview

CMS GC の場合 •  New 世代

–  typeArrayKlass::oop_oop_iterate(oopDesc*, OopClosure*)

– *Klass::oop_oop_iterate_nv(oopDesc*, Par_MarkRefsIntoAndScanClosure*)

•  Old 世代 – SweepClosure::do_blk_careful(HeapWord*)

43 Copyright©2015 NTT corp. All Rights Reserved.

jdk8u45

typeArrayKlass は全ての OopClosure に関する Klass::oop_oop_iterate_nv() から呼ばれる共通処理があるのでここをフック

Page 44: HeapStats: Introduction and Technical Preview

44 Copyright©2015 NTT corp. All Rights Reserved.

jdk8u45

•  Marking と Evacuation (マークと退避) サイクルが完全に分離されている

•  Evacuation が、インクリメンタルで動作する場合があり、1 GC でヒープ全体の情報を収集できない可能性がある

•  マーク済情報を保持してないので、自前で BitMap を作る必要が有る

G1GC の場合

Page 45: HeapStats: Introduction and Technical Preview

45 Copyright©2015 NTT corp. All Rights Reserved.

jdk8u45

•  頑張って Marking サイクルでフック –  typeArrayKlass::oop_oop_iterate (oopDesc*,

OopClosure *) – *Klass::oop_oop_iterate_nv(oopDesc*,

G1CMOopClosure*) – *Klass::oop_oop_iterate_nv(oopDesc*,

G1RootRegionScanClosure*) •  この他、独自BitMap作成に必要な情報収集

G1GC の場合

Page 46: HeapStats: Introduction and Technical Preview

46 Copyright©2015 NTT corp. All Rights Reserved.

• Permanent / Metaspace 領域の情報収集方法

•  oop からの各種情報取得方法 • スレッド情報の収集方法 •  etc…

言ってない事

Page 47: HeapStats: Introduction and Technical Preview

47 Copyright©2015 NTT corp. All Rights Reserved.

・3・b •  http://icedtea.classpath.org/wiki/HeapStats •  [email protected] •  hg clone

http://icedtea.classpath.org/hg/heapstats

We want you!

Page 48: HeapStats: Introduction and Technical Preview

Thank You !

Copyright©2015 NTT corp. All Rights Reserved. 48