AWS Graviton への移行支援する Porting Advisor for Gravitonを試してみた

ソースコードを分析して、AWS Graviton への移行時に変更が必要となる古いランタイムやライブラリをチェックしてくれます。
2023.02.08

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

クラウドコストを最適化する手段の一つとして、コストパフォーマンスが高い AWS Graviton への移行・採用があります。 また近年では、サスティナビリティの観点からもパフォーマンスが良い AWS Graviton の利用が推奨されることを見聞きする機会があります。

良い面が聞かれる一方で、注意すべき点もあります。
例としては下記があります。

  • 全ての OS やインスタンスタイプで利用出来るわけではありません
  • プロセッサ設計と実行されるアプリケーション仕様により、期待されるパフォーマンスが得られない可能性があります

特に二つの注意点については、インフラストラクチャーではなく実行されるアプリケーション要件による部分が大きく移行前に検証が推奨されます。

そのため、移行に関するガイドが GitHub 上で公開されています。

上記ガイド内で、ワークロード内のソフトウェアスタックの分析・変更判断を支援するツールとして Porting Advisor for Graviton が紹介されています。

The Porting Advisor for Graviton is an open-source command line tool that analyzes source code and generates a report highlighting missing and outdated libraries and code constructs that may require modification along with recommendations for alternatives. It accelerates your transition to AWS Graviton-based instances by reducing the iterative process of identifying and resolving source code and library dependencies

↓↓↓ 機械翻訳 ↓↓↓

GravitonのPorting Advisorは、ソース コードを分析し、欠落しているライブラリや古いライブラリ、および変更が必要な可能性のあるコード構造を強調表示するレポートを生成するオープン ソースのコマンド ライン ツールです。ソースコードとライブラリの依存関係を特定して解決する反復プロセスを減らすことで、AWS Graviton ベースのインスタンスへの移行を加速します。

引用元: aws/aws-graviton-getting-started/transition-guide.md

今回、その Porting Advisor for Graviton が GA されていたため、試してみます。

やってみた

こちらのツールも GitHub で公開されています。

現時点(2023/02/08)での分析対象となる言語とチェック対象は下記のようです。

Python 3+
- Python version
- PIP version
- Dependency versions in requirements.txt file

Java 8+
- Java version
- Dependency versions in pom.xml file
- JAR scanning for native method calls (requires JAVA to be installed)

Go 1.11+
- Go version
- Dependency versions on go.mod file

C, C++, Fortran
- Inline assembly with no corresponding aarch64 inline assembly.
- Assembly source files with no corresponding aarch64 assembly source files.
- Missing aarch64 architecture detection in autoconf config.guess scripts.
- Linking against libraries that are not available on the aarch64 architecture.
- Use of architecture specific intrinsic.
- Preprocessor errors that trigger when compiling on aarch64.
- Use of old Visual C++ runtime (Windows specific).
- The following types of issues are detected, but not reported by default:
- Compiler specific code guarded by compiler specific pre-defined macros.
- The following types of cross-compile specific issues are detected, but not reported by default.
- Architecture detection that depends on the host rather than the target.
- Use of build artifacts in the build process.

前提条件

- Python 3.10 or above (with PIP3 and venv module installed).
- (Optionally) Open JDK 17 (or above) and Maven 3.5 (or above) if you want to scan JAR files for native methods.

↓↓↓ 機械翻訳 ↓↓↓

- Python 3.10 以上 (PIP3 と venv モジュールがインストールされていること)。
- (オプション) JARファイルをネイティブメソッド用にスキャンしたい場合は、JDK 17 (またはそれ以上) と Maven 3.5 (またはそれ以上) を開いてください。

% python3 --version
Python 3.11.1

準備

早速、README を参考にやっていきます。まずはソースをローカルへクローンします。

% git clone https://github.com/aws/porting-advisor-for-graviton.git
Cloning into 'porting-advisor-for-graviton'...
remote: Enumerating objects: 333, done.
remote: Counting objects: 100% (333/333), done.
remote: Compressing objects: 100% (206/206), done.
remote: Total 333 (delta 102), reused 301 (delta 87), pack-reused 0
Receiving objects: 100% (333/333), 144.62 KiB | 4.99 MiB/s, done.
Resolving deltas: 100% (102/102), done.

% ls
porting-advisor-for-graviton

環境を準備します。

% python3 -m venv .venv
% source .venv/bin/activate

インストールを実行します。

% cd porting-advisor-for-graviton
% pip3 install -r requirements.txt
Collecting altgraph==0.17.2
  Using cached altgraph-0.17.2-py2.py3-none-any.whl (21 kB)
Collecting Jinja2==3.1.2
  Using cached Jinja2-3.1.2-py3-none-any.whl (133 kB)
Collecting MarkupSafe==2.1.1
  Using cached MarkupSafe-2.1.1.tar.gz (18 kB)
  Preparing metadata (setup.py) ... done
Collecting packaging==21.3
  Using cached packaging-21.3-py3-none-any.whl (40 kB)
Collecting progressbar33==2.4
  Using cached progressbar33-2.4.tar.gz (10 kB)
  Preparing metadata (setup.py) ... done
Collecting pyparsing==3.0.9
  Using cached pyparsing-3.0.9-py3-none-any.whl (98 kB)
Collecting XlsxWriter==3.0.3
  Using cached XlsxWriter-3.0.3-py3-none-any.whl (149 kB)
Installing collected packages: progressbar33, altgraph, XlsxWriter, pyparsing, MarkupSafe, packaging, Jinja2
  DEPRECATION: progressbar33 is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
  Running setup.py install for progressbar33 ... done
  DEPRECATION: MarkupSafe is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
  Running setup.py install for MarkupSafe ... done
Successfully installed Jinja2-3.1.2 MarkupSafe-2.1.1 XlsxWriter-3.0.3 altgraph-0.17.2 packaging-21.3 progressbar33-2.4 pyparsing-3.0.9

[notice] A new release of pip available: 22.3.1 -> 23.0
[notice] To update, run: pip install --upgrade pip

これで準備完了です。

実行

今回は都合の良い(古いライブラリなどを含む)ソースコードを持っていないため、ツール内にある Python サンプルソースに対して実行します。

% ls sample-projects 
dotnet-samples	go-samples	java-samples	node-samples	python-samples	ruby-samples
% python3 src/porting-advisor.py sample-projects/python-samples 
| Elapsed Time: 0:00:02                                                                                                                                                                                                                                                         

Porting Advisor for Graviton v1.0.0
Report date: 2023-02-08 16:10:46

4 files scanned.
detected python code. if you need pip, version 19.3 or above is recommended. we detected that you have version 22.3.1.
detected python code. min version 3.7.5 is required. we detected that you have version 3.11.1. see https://github.com/aws/aws-graviton-getting-started/blob/main/python.md for more details.
sample-projects/python-samples/incompatible/requirements.txt:3: using dependency library openblas version 0.3.16. upgrade to at least version 0.3.17
sample-projects/python-samples/incompatible/requirements.txt:5: dependency library numpy is present. min version 1.19.0 is required.

Report generated successfully. Hint: you can use --output FILENAME.html to generate an HTML report.

サンプルソースでは、下記の二つがチェックに引っかかりました。

  • openblas
  • numpy

requirements.txt を見てみます。
確かに openblas は最低バージョンが 0.3.16 、NumPy は特に定義がされていないため、検出されたようです。

% cat sample-projects/python-samples/incompatible/requirements.txt 
# Porting Advisor for Graviton test file

OpenBLAS>=0.3.16
SciPy>=1.7.1
NumPy
FakeDependency>=1.2.3%

ちょっと強引ですが、直接ファイルを書き換えて、再度チェックを実行します。

% cat sample-projects/python-samples/incompatible/requirements.txt
# Porting Advisor for Graviton test file

OpenBLAS>=0.3.17
SciPy>=1.7.1
NumPy>=1.19.0
FakeDependency>=1.2.3

% python3 src/porting-advisor.py sample-projects/python-samples   
| Elapsed Time: 0:00:02                                                                                                                                                                                                                                                         

Porting Advisor for Graviton v1.0.0
Report date: 2023-02-08 16:16:48

4 files scanned.
No issues found.
detected python code. if you need pip, version 19.3 or above is recommended. we detected that you have version 22.3.1.
detected python code. min version 3.7.5 is required. we detected that you have version 3.11.1. see https://github.com/aws/aws-graviton-getting-started/blob/main/python.md for more details.

Report generated successfully. Hint: you can use --output FILENAME.html to generate an HTML report.

今度は該当箇所はないと結果が出ました。 requirements.txt を対象に分析していることが改めて確認出来ました。

結果出力

コンソール上での結果表示以外に、ファイルでも出力が出来るようです。
現時点(2023/02/08)ファイル形式は、TEXT, JSON, HTML, CSV の4種類のようです。
それぞれ実施してみます。

% python3 src/porting-advisor.py sample-projects/python-samples --output report.html
| Elapsed Time: 0:00:02                                                                                                                                                                                                                                                         

Porting Advisor for Graviton v1.0.0
Report date: 2023-02-08 16:20:59

Report saved at: report.html

% python3 src/porting-advisor.py sample-projects/python-samples --output report.json
% python3 src/porting-advisor.py sample-projects/python-samples --output report.csv
% python3 src/porting-advisor.py sample-projects/python-samples --output report.txt

% ls report.*   
report.csv	report.html	report.json	report.txt
  • report.html

非常に見やすいです!

  • report.json

別の管理ツールに取り込むなどのユースケースで有用そうです。

{
  "errors": [],
  "issue_types": "-CompilerSpecific,-CrossCompile,-NoEquivalent",
  "issues": [
    "DependencyVersionIssue: sample-projects/python-samples/incompatible/requirements.txt:3: using dependency library openblas version 0.3.16. upgrade to at least version 0.3.17"
  ],
  "open_text_mode": "w",
  "ported_inline_asm": 0,
  "remarks": [
    "LanguageVersionRemark: detected python code. min version 3.7.5 is required. we detected that you have version 3.11.1. see https://github.com/aws/aws-graviton-getting-started/blob/main/python.md for more details.",
    "ToolVersionRemark: detected python code. if you need pip, version 19.3 or above is recommended. we detected that you have version 22.3.1.",
    "DependencyVersionRemark: sample-projects/python-samples/incompatible/requirements.txt:5: dependency library numpy is present. min version 1.19.0 is required."
  ],
  "root_directory": "sample-projects/python-samples",
  "self_process": false,
  "send_filename": false,
  "source_dirs": [
    "sample-projects/python-samples/incompatible",
    "sample-projects/python-samples/compatible",
    "sample-projects/python-samples"
  ],
  "source_files": [
    "sample-projects/python-samples/submain.py",
    "sample-projects/python-samples/main.py",
    "sample-projects/python-samples/compatible/requirements.txt",
    "sample-projects/python-samples/incompatible/requirements.txt"
  ],
  "target_os": "linux"
}
  • report.csv

こちらも複数対象に実施した際のサマリーとして利用出来そうです。

  • report.txt

コンソールに出力された結果が出力されるようです。実行履歴として良さそうです。

% cat report.txt
4 files scanned.
detected python code. if you need pip, version 19.3 or above is recommended. we detected that you have version 22.3.1.
detected python code. min version 3.7.5 is required. we detected that you have version 3.11.1. see https://github.com/aws/aws-graviton-getting-started/blob/main/python.md for more details.
sample-projects/python-samples/incompatible/requirements.txt:3: using dependency library openblas version 0.3.16. upgrade to at least version 0.3.17
sample-projects/python-samples/incompatible/requirements.txt:5: dependency library numpy is present. min version 1.19.0 is required.

まとめ

AWS Graviton への移行を支援する Porting Advisor for Graviton を利用してみました。
冒頭で紹介した GitHub 上のガイドに記載がある通り、移行に際しては確認が必要な観点は複数あるため、今回のようなツールを利用して、その手間を軽減出来るのは良いですね。
今回紹介したツール以外に、CloudShell を利用して AWS Lambda に AWS Graviton2 と互換性のないランタイムを持つ関数の調査するツールも公開されています。

AWS Graviton への移行は得られる効果も大きいため、今後も Porting Advisor for Graviton や他の支援ツールも登場すると嬉しいですね。期待!!

参考情報

(2023.2.22 追記) AWS Blog でも利用方法を紹介した記事が掲載されています。