HEY を使用した Vertex AI オンライン予測ベースライン テスト

1. はじめに

このチュートリアルでは、HEY ウェブ パフォーマンス ツールを使用して、us-central1 と us-west1 で、us-central1 にデプロイされた予測エンドポイントに対してベースライン テストを実施する際に、Cloud Monitoring のオンライン予測指標を作成して評価する方法について説明します。

作成するアプリの概要

まず、aiml-vpc という VPC ネットワークを設定します。この VPC ネットワークは、us-west1 と us-central1 のサブネットとインスタンスで構成されます。これらのネットワークは、us-central1 にデプロイされたオンライン予測とモデルをターゲットに、HEY を使用してトラフィックを生成するために使用されます。

オンプレミス環境とマルチクラウド環境で PSC を利用して googleapis にアクセスする方法を示すため、Private Service Connect とプライベート DNS もチュートリアルに組み込まれています。

このチュートリアルでは、HEY からオンライン予測へのトラフィックを検証するために、Cloud Monitoring と Network Intelligence を使用します。チュートリアルで説明するステップは VPC にデプロイされていますが、これらのステップを活用して、オンプレミス環境またはマルチクラウド環境から Vertex API のベースラインをデプロイして取得することもできます。ネットワーク アーキテクチャは、以下のコンポーネントで構成されています。

dd5c102ce1ab0150.png

ユースケースの詳細は次のとおりです。

  1. HEY を使用して us-west1 の GCE インスタンスから us-central1 のオンライン予測にアクセスする
  2. Vertex API へのアクセスに PSC が使用されていることを確認する
  3. HEY を使用して curl を 5 分間実行する
  4. Cloud Monitoring を使用してレイテンシを検証する
  5. ネットワーク インテリジェンスを使用してリージョン間のレイテンシを検証する
  6. HEY を使用して us-central1 の GCE インスタンスから us-central1 のオンライン予測にアクセスする
  7. Vertex API へのアクセスに PSC が使用されていることを確認する
  8. HEY を使用して curl を 5 分間実行する
  9. Cloud Monitoring を使用してレイテンシを検証する
  10. Network Intelligence を使用してリージョン内のレイテンシを検証する

学習内容

  • Private Service Connect エンドポイントを確立する方法
  • HEY を使用してオンライン予測への負荷を生成する方法
  • Cloud Monitoring を使用して Vertex AI 指標を作成する方法
  • Network Intelligence を使用して内部およびリージョン間レイテンシ

必要なもの

  • Google Cloud プロジェクト

IAM 権限

Compute ネットワーク管理者

Compute ネットワーク管理者

Service Directory 編集者

DNS 管理者

ネットワーク管理閲覧者

2. 始める前に

プロジェクトを更新してチュートリアルをサポートする

このチュートリアルでは、Cloud Shell で gcloud 構成を実装するために $variables を使用します。

Cloud Shell で、次のコマンドを実行します。

gcloud config list project
gcloud config set project [YOUR-PROJECT-NAME]
projectid=YOUR-PROJECT-NAME
echo $projectid

3. aiml-vpc の設定

aiml-vpc を作成する

gcloud サービスで networkmanagement.googleapis.com を有効にする

Cloud Shell で、次のコマンドを実行します。

gcloud compute networks create aiml-vpc --project=$projectid --subnet-mode=custom

Cloud Shell で、ネットワーク インテリジェンスのネットワーク管理 API を有効にする

gcloud services enable networkmanagement.googleapis.com

ユーザー管理のノートブック サブネットを作成する

Cloud Shell 内で、workbench-subnet を作成します。

gcloud compute networks subnets create workbench-subnet --project=$projectid --range=172.16.10.0/28 --network=aiml-vpc --region=us-central1 --enable-private-ip-google-access

Cloud Shell 内で、us-west1-subnet を作成します。

gcloud compute networks subnets create us-west1-subnet --project=$projectid --range=192.168.10.0/28 --network=aiml-vpc --region=us-west1

Cloud Shell 内で、us-central1-subnet を作成します。

gcloud compute networks subnets create us-central1-subnet --project=$projectid --range=192.168.20.0/28 --network=aiml-vpc --region=us-central1

Cloud Router と NAT の構成

GCE インスタンスには外部 IP アドレスがないため、チュートリアルでは Cloud NAT を使用してソフトウェア パッケージをダウンロードします。Cloud NAT は下り(外向き)NAT 機能を提供します。つまり、インターネット ホストがユーザー管理ノートブックとの通信を開始できないため、ノートブックの安全性が向上します。

Cloud Shell 内で、リージョン クラウド ルーター us-west1 を作成します。

gcloud compute routers create cloud-router-us-west1-aiml-nat --network aiml-vpc --region us-west1

Cloud Shell 内で、リージョン Cloud NAT ゲートウェイ us-west1 を作成します。

gcloud compute routers nats create cloud-nat-us-west1 --router=cloud-router-us-west1-aiml-nat --auto-allocate-nat-external-ips --nat-all-subnet-ip-ranges --region us-west1

Cloud Shell 内で、リージョン クラウド ルーター us-central1 を作成します。

gcloud compute routers create cloud-router-us-central1-aiml-nat --network aiml-vpc --region us-central1

Cloud Shell 内で、リージョン Cloud NAT ゲートウェイ us-central1 を作成します。

gcloud compute routers nats create cloud-nat-us-central1 --router=cloud-router-us-central1-aiml-nat --auto-allocate-nat-external-ips --nat-all-subnet-ip-ranges --region us-central1

4. Private Service Connect エンドポイントを作成する

次のセクションでは、 aiml-vpc から Vertex API へのアクセスに使用する Private Service Connect(PSC)エンドポイントを作成します。

Cloud Shell から

gcloud compute addresses create psc-ip \
    --global \
    --purpose=PRIVATE_SERVICE_CONNECT \
    --addresses=100.100.10.10 \
    --network=aiml-vpc

「pscendpointip」を保存使用しないでください。

pscendpointip=$(gcloud compute addresses list --filter=name:psc-ip --format="value(address)")

echo $pscendpointip

PSC エンドポイントを作成する

Cloud Shell から

gcloud compute forwarding-rules create pscvertex \
    --global \
    --network=aiml-vpc \
    --address=psc-ip \
    --target-google-apis-bundle=all-apis

構成済みの Private Service Connect エンドポイントを一覧表示する

Cloud Shell から

gcloud compute forwarding-rules list  \
--filter target="(all-apis OR vpc-sc)" --global

構成した Private Service Connect エンドポイントの説明を取得する

Cloud Shell から

gcloud compute forwarding-rules describe \
    pscvertex --global

5. GCE インスタンス用のサービス アカウントを作成する

Vertex API をきめ細かく制御するには、ユーザーが管理するサービス アカウントを west と central のインスタンスに適用する必要があります。生成されたサービス アカウントの権限は、ビジネス要件に基づいて変更できます。このチュートリアルでは、ユーザー マネージド サービス アカウント vertex-sa に次のロールを適用します。

続行する前に、Service Account API をにする必要があります。

Cloud Shell 内で、サービス アカウントを作成します。

gcloud iam service-accounts create vertex-gce-sa \
    --description="service account for vertex" \
    --display-name="vertex-sa"

Cloud Shell で、サービス アカウントを更新して Compute インスタンス管理者ロールを割り当てる

gcloud projects add-iam-policy-binding $projectid --member="serviceAccount:vertex-gce-sa@$projectid.iam.gserviceaccount.com" --role="roles/compute.instanceAdmin.v1"

Cloud Shell で、Vertex AI ユーザーロールを使用してサービス アカウントを更新します。

gcloud projects add-iam-policy-binding $projectid --member="serviceAccount:vertex-gce-sa@$projectid.iam.gserviceaccount.com" --role="roles/aiplatform.user"

6. ユーザー管理のサービス アカウントを作成する(ノートブック)

次のセクションでは、チュートリアルで使用する Vertex Workbench(ノートブック)に関連付けるユーザー マネージド サービス アカウントを作成します。

このチュートリアルでは、サービス アカウントに次のルールが適用されます。

Cloud Shell 内で、サービス アカウントを作成します。

gcloud iam service-accounts create user-managed-notebook-sa \
    --display-name="user-managed-notebook-sa"

Cloud Shell で、ストレージ管理者のロールでサービス アカウントを更新します。

gcloud projects add-iam-policy-binding $projectid --member="serviceAccount:user-managed-notebook-sa@$projectid.iam.gserviceaccount.com" --role="roles/storage.admin"

Cloud Shell 内で、Vertex AI ユーザーロールを使用してサービス アカウントを更新します。

gcloud projects add-iam-policy-binding $projectid --member="serviceAccount:user-managed-notebook-sa@$projectid.iam.gserviceaccount.com" --role="roles/aiplatform.user"

Cloud Shell 内で、Artifact Registry 管理者ロールを持つサービス アカウントを更新します。

gcloud projects add-iam-policy-binding $projectid --member="serviceAccount:user-managed-notebook-sa@$projectid.iam.gserviceaccount.com" --role="roles/artifactregistry.admin"

Cloud Shell でサービス アカウントを一覧表示し、ユーザー管理ノートブックの作成時に使用するメールアドレスをメモします。

gcloud iam service-accounts list

7. テスト インスタンスを作成する

次のセクションでは、us-west1 と us-central1 からベースライン テストを実施するためのテスト インスタンスを作成します。

Cloud Shell 内で west-client を作成します。

gcloud compute instances create west-client \
    --zone=us-west1-a \
    --image-family=debian-11 \
    --image-project=debian-cloud \
    --subnet=us-west1-subnet \
    --scopes=https://www.googleapis.com/auth/cloud-platform \
    --no-address \
    --shielded-secure-boot --service-account=vertex-gce-sa@$projectid.iam.gserviceaccount.com \
    --metadata startup-script="#! /bin/bash
      sudo apt-get update
      sudo apt-get install tcpdump dnsutils -y"

Cloud Shell 内で central-client を作成します。

gcloud compute instances create central-client \
    --zone=us-central1-a \
    --image-family=debian-11 \
    --image-project=debian-cloud \
    --subnet=us-central1-subnet \
    --scopes=https://www.googleapis.com/auth/cloud-platform \
    --no-address \
    --shielded-secure-boot --service-account=vertex-gce-sa@$projectid.iam.gserviceaccount.com \
    --metadata startup-script="#! /bin/bash
      sudo apt-get update
      sudo apt-get install tcpdump dnsutils -y"

IAP に VM インスタンスへの接続を許可するには、次のファイアウォール ルールを作成します。

  • IAP を使用してアクセスできるようにするすべての VM インスタンスに適用します。
  • IP 範囲 35.235.240.0/20 からの上り(内向き)トラフィックを許可する。この範囲には、IAP が TCP 転送に使用するすべての IP アドレスが含まれています。

Cloud Shell 内で、IAP ファイアウォール ルールを作成します。

gcloud compute firewall-rules create ssh-iap-vpc \
    --network aiml-vpc \
    --allow tcp:22 \
    --source-ranges=35.235.240.0/20

8. ユーザー管理のノートブックを作成する

Notebooks API を

次のセクションでは、以前に作成したサービス アカウント user-managed-notebook-sa を組み込んだユーザー管理ノートブックを作成します。

Cloud Shell 内で private-client インスタンスを作成します。

gcloud notebooks instances create workbench-tutorial \
      --vm-image-project=deeplearning-platform-release \
      --vm-image-family=common-cpu-notebooks \
      --machine-type=n1-standard-4 \
      --location=us-central1-a \
      --subnet-region=us-central1 \
      --shielded-secure-boot \
      --subnet=workbench-subnet \
      --no-public-ip    --service-account=user-managed-notebook-sa@$projectid.iam.gserviceaccount.com

[Vertex AI] → [ワークベンチ] に移動して、デプロイされたノートブックを表示します。

b02fcb9b07dca06a.png

9. モデルとオンライン予測をデプロイする

次のセクションでは、提供された Codelab「Vertex AI:カスタム予測ルーチンと Sklearn でカスタム予測ルーチンを使用し、予測用のデータの前処理と後処理を行う」を使用します。これは、前のステップでノートブックをすでに作成しているため、セクション 7 から始まります。モデルがデプロイされたら、チュートリアルに戻って次のセクションに進みます。

ee68b7ba0cfd2746.png

10. オンライン予測用のカスタム モニタリング ダッシュボードを作成する

オンライン予測では、デフォルトのモニタリング ダッシュボードが [VERTEX AI] → [オンライン予測] → [エンドポイント名](diamonds-cpr_endpoint)に作成されます。ただし、テストでは開始時刻と終了時刻を定義する必要があるため、カスタム ダッシュボードが必要です。

次のセクションでは、Cloud Monitoring の指標を作成して、オンライン予測エンドポイントへのリージョン アクセスに基づいてレイテンシの測定値を取得します。これにより、us-west1 と us-central にデプロイされた GCE インスタンスから us-central1 のエンドポイントにアクセスする際のレイテンシの違いを検証します。

このチュートリアルでは Prediction_latencies の指標を使用します。追加の指標は aiplatform で入手できます。

指標

説明

prediction/online/prediction_latencies

デプロイされたモデルのオンライン予測のレイテンシ。

prediction_latencies 指標のグラフを作成する

Cloud コンソールで [モニタリング] → [Metrics Explorer] に移動します。

536668ab0b29d77.png

指標 prediction/online/prediction_latencies を挿入し、次のオプションを選択して [適用] を選択します。

c1edd34208cb5ee2.png

次のオプションに基づいて [Group by] で [Save Chart] を選択します。

e180a5d8a044b6e1.png

d2ecd6677a3b34e0.png

[Save] を選択すると、ダッシュボードを選択するよう求められます。[新しいダッシュボードと名前を指定します。

e29a39dc941c8599.png

Vertex カスタム ダッシュボード

次のセクションでは、Vertex カスタム ダッシュボードに正しい時刻が表示されていることを確認します。

[モニタリング] → [ダッシュボード] に移動し、[Vertex カスタム ダッシュボード] を選択して時間を選択します。タイムゾーンが正しいことを確認します。

f43ebed798ce1147.png

凡例を展開して表形式にしてください。

61ffeef22e067ca9.png

展開ビューの例:

9027e8785c023129.png

11. PSC エンドポイントに限定公開 DNS を作成する

aiml-vpc に限定公開 DNS ゾーンを作成して、すべての googleapis を PSC エンドポイントの IP アドレス 100.100.10.10 に解決する。

Cloud Shell で、限定公開 DNS ゾーンを作成します。

gcloud dns --project=$projectid managed-zones create psc-googleapis --description="Private Zone to resolve googleapis to a PSC endpoint" --dns-name="googleapis.com." --visibility="private" --networks="https://www.googleapis.com/compute/v1/projects/$projectid/global/networks/aiml-vpc"

Cloud Shell で、* を関連付ける A レコードを作成します。googleapis.com を PSC IP にマッピング。

gcloud dns --project=$projectid record-sets create *.googleapis.com. --zone="psc-googleapis" --type="A" --ttl="300" --rrdatas="100.100.10.10"

12. テスト変数

Hey はエンドユーザーがネットワークとアプリケーションの要件に基づいてテストをカスタマイズする機能を提供します。このチュートリアルでは、サンプルの実行文字列を含む以下のオプションを使用します。

c == 1 ワーカー

z == 期間

m == HTTP メソッド POST

D == ファイル instances.json からの HTTP リクエスト本文

n == 実行するリクエストの数。デフォルトは 200 です。

HEY を含む curl 文字列の例(実行は不要)

user@us-central$ ./hey_linux_amd64 -c 1 -z 1m -m POST -D instances.json  -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" https://us-central1-aiplatform.googleapis.com/v1/projects/${projectid$}/locations/us-central1/endpoints/${ENDPOINT_ID}:predict

13. 予測 ID を取得する

Cloud コンソールからオンライン予測エンドポイント ID を取得します。この ID は以降のステップで使用します。

Vertex AI → [オンライン予測] に移動します。

ce4d4a88a3fa2345.png

14. HEY(us-west1)をダウンロードして実行する

次のセクションでは、west-client にログインして、us-central1 にあるオンライン予測に対して HEY をダウンロードし、実行します。

Cloud Shell から west-client にログインし、HEY をダウンロードします。

gcloud compute ssh west-client --project=$projectid --zone=us-west1-a --tunnel-through-iap

OS から HEY をダウンロードして権限を更新します。

wget https://hey-release.s3.us-east-2.amazonaws.com/hey_linux_amd64
chmod +x hey_linux_amd64

OS から、次の変数を作成します。

gcloud config list project
gcloud config set project [YOUR-PROJECT-NAME]
projectid=YOUR-PROJECT-NAME
echo $projectid
ENDPOINT_ID="insert-your-endpoint-id-here"

例:

ENDPOINT_ID="2706243362607857664"

次のセクションでは、vi エディタまたは nano を使用して instances.json ファイルを作成し、デプロイしたモデルから予測を取得するために使用するデータ文字列を挿入します。

west-client OS から、以下のデータ文字列を使用して instances.json ファイルを作成します。

{"instances": [
  [0.23, 'Ideal', 'E', 'VS2', 61.5, 55.0, 3.95, 3.98, 2.43],
  [0.29, 'Premium', 'J', 'Internally Flawless', 52.5, 49.0, 4.00, 2.13, 3.11]]}

例:

user@west-client:$ more instances.json 
{"instances": [
  [0.23, 'Ideal', 'E', 'VS2', 61.5, 55.0, 3.95, 3.98, 2.43],
  [0.29, 'Premium', 'J', 'Internally Flawless', 52.5, 49.0, 4.00, 2.13, 3.11]]}

user@west-client:$

事前テスト

OS から curl を実行して、モデルと予測エンドポイントが正常に機能していることを確認します。詳細ログの PSC エンドポイント IP と、成功を示す HTTP/2 200 をメモします。

curl -v -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" https://us-central1-aiplatform.googleapis.com/v1/projects/${projectid}/locations/us-central1/endpoints/${ENDPOINT_ID}:predict -d @instances.json

例: 予測へのアクセスに使用される PSC の IP アドレスをメモし、示されます

user@west-client:$ curl -v -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" https://us-central1-aiplatform.googleapis.com/v1/projects/${projectid}/locations/us-central1/endpoints/${ENDPOINT_ID}:predict -d @instances.json
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 100.100.10.10:443...
* Connected to us-central1-aiplatform.googleapis.com (100.100.10.10) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*  CAfile: /etc/ssl/certs/ca-certificates.crt
*  CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=upload.video.google.com
*  start date: Jul 31 08:22:19 2023 GMT
*  expire date: Oct 23 08:22:18 2023 GMT
*  subjectAltName: host "us-central1-aiplatform.googleapis.com" matched cert's "*.googleapis.com"
*  issuer: C=US; O=Google Trust Services LLC; CN=GTS CA 1C3
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x55a9f38b42c0)
> POST /v1/projects/new-test-project-396322/locations/us-central1/endpoints/2706243362607857664:predict HTTP/2
> Host: us-central1-aiplatform.googleapis.com
> user-agent: curl/7.74.0
> accept: */*
> authorization: Bearer ya29.c.b0Aaekm1LqrcaOlWFFwuEOWX_tZVXXvJgN_K-u5_hFyEAYXAi3AnBEBwwtHS8dweW_P2QGfdyFfa31nMT_6BaKBI0mC9IsfzfIiUwXc8u2yJt01gTUSJpCmGAFKZKidRMgkPYivVYCnuymzdYbRAWacIe__StkRzI9UeQOGN3jNIeESr80AdH12goaxCFXWaNWxoYRfGVhekEgUcsKs7t1OhOM-937gy4YGkXcXa8sGuHWRqF5bnulYlTqlxqQ2aAxMTrQg2lwUWRGCmGhPrym7rXJq7oim0DkAJSbAarl1qFuz0PPfNXeHGbs13zY2r1giV7u8_w4Umj_Q5M7H9fTkq7EiqnLzqRkOHXismYL368P1jOUBYM__krFQt4M3X9RJa0g01tOw3FnOh27BmUqlFQ1J2h14JZpx215Q3xzRvgfJ5iW5YYSkv67uZRQk4V04naOUXyc0plzWuVOjj4nor3fYvkS_oW0IyxJoBjeXR16Vnvln8c04svWX9dt7eobczFvBOm9nVdh4lVp8qxbp__2WtMvc1QVg6y-2i6lRpbvmyp1oadxVRjxV1e0wiQFSe-qqsinJu3bnnaMbxdU2cu5j26o8o8Xpgo0SF1UM0b1WX84iatbWpdFSphZm1llwmRagMzcFBW0aBk-i35_bXSbzwURgMfY6Qbyb9Rv9y0F-Maf34I0WxiMldv2uc57nej7dVl9OSm_Ohnro-i9zcpq9fxo9soYVB8WjaZOUjauk4znstc2_6y4atcVVsQBkeU674biR567Ri3M74Jfv4MrrF02ObfrJRdB7UJ4MU_9kWW-kYeeJzoci15UqYV0f_yJgReBwQa66Supmebee2Sn2nku6xZkRMu5Mz55mXuva0XWrpIbor7WckSsXwUFbf7rj5ipa4mOOyf2hJe1Rq0x6yeBaariRzXrhfm5bBpFBU73-zd-IekvOji0ZJQSkk0o6gpX_794Jny7j14aQJ8VxezcFpZUztimYhMnRhlO2lqms1h0h48
> content-type: application/json
> content-length: 158
> 
* Connection state changed (MAX_CONCURRENT_STREAMS == 100)!
* We are completely uploaded and fine
< HTTP/2 200 
< x-vertex-ai-internal-prediction-backend: harpoon
< content-type: application/json; charset=UTF-8
< date: Sun, 20 Aug 2023 03:51:54 GMT
< vary: X-Origin
< vary: Referer
< vary: Origin,Accept-Encoding
< server: scaffolding on HTTPServer2
< cache-control: private
< x-xss-protection: 0
< x-frame-options: SAMEORIGIN
< x-content-type-options: nosniff
< accept-ranges: none
< 
{
  "predictions": [
    "$479.0",
    "$586.0"
  ],
  "deployedModelId": "3587550310781943808",
  "model": "projects/884291964428/locations/us-central1/models/6829574694488768512",
  "modelDisplayName": "diamonds-cpr",
  "modelVersionId": "1"
}
* Connection #0 to host us-central1-aiplatform.googleapis.com left intact

HEY を実行する

OS から、HEY を実行して 10 分間のベースライン テストを有効にします。

./hey_linux_amd64 -c 1 -z 10m -m POST -D instances.json  -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" https://us-central1-aiplatform.googleapis.com/v1/projects/$projectid/locations/us-central1/endpoints/${ENDPOINT_ID}:predict

15. Hey Validation(us-west1)

us-west1 のコンピューティング インスタンスから Hey を実行したので、以下の結果を評価します。

  • HEY の結果
  • Vertex カスタム ダッシュボード
  • ネットワーク インテリジェンス

HEY の結果

OS から、10 分間の実行に基づいて HEY の結果を検証しましょう。

17.5826 リクエスト/秒

99%(0.0686 秒)|68 ミリ秒

10,550 件のレスポンス(ステータス コード 200)

user@west-client:$ ./hey_linux_amd64 -c 1 -z 10m -m POST -D instances.json  -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" https://us-central1-aiplatform.googleapis.com/v1/projects/$projectid/locations/us-central1/endpoints/${ENDPOINT_ID}:predict

Summary:
  Total:        600.0243 secs
  Slowest:      0.3039 secs
  Fastest:      0.0527 secs
  Average:      0.0569 secs
  Requests/sec: 17.5826
  

Response time histogram:
  0.053 [1]     |
  0.078 [10514] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  0.103 [16]    |
  0.128 [4]     |
  0.153 [3]     |
  0.178 [1]     |
  0.203 [0]     |
  0.229 [2]     |
  0.254 [1]     |
  0.279 [5]     |
  0.304 [3]     |


Latency distribution:
  10% in 0.0546 secs
  25% in 0.0551 secs
  50% in 0.0559 secs
  75% in 0.0571 secs
  90% in 0.0596 secs
  95% in 0.0613 secs
  99% in 0.0686 secs

Details (average, fastest, slowest):
  DNS+dialup:   0.0000 secs, 0.0527 secs, 0.3039 secs
  DNS-lookup:   0.0000 secs, 0.0000 secs, 0.0116 secs
  req write:    0.0000 secs, 0.0000 secs, 0.0002 secs
  resp wait:    0.0567 secs, 0.0526 secs, 0.3038 secs
  resp read:    0.0001 secs, 0.0001 secs, 0.0696 secs

Status code distribution:
  [200] 10550 responses

Vertex カスタム ダッシュボード

[モニタリング] → [ダッシュボード] に移動して、[Vertex カスタム ダッシュボード] を選択します。「10 分」と入力するか、開始時刻と終了時刻を指定します。タイムゾーンが正しいことを確認します。

4102b1d0438c78e3.png

予測レイテンシの定義を見ると、サーバーサイドの指標は、モデルからレスポンスを取得してからクライアント リクエストに応答するまでの合計時間を測定する指標になっています。

  • 合計レイテンシ時間: リクエストがサービスに費やした合計時間。モデルのレイテンシにオーバーヘッドのレイテンシを加えたものです。

一方、HEY は以下のパラメータを考慮するクライアント側の指標です。

クライアント リクエスト + 合計レイテンシ(モデル レイテンシを含む)+ クライアント レスポンス

ネットワーク インテリジェンス

次に、Network Intelligence によって報告されるリージョン間のネットワーク レイテンシを見て、Google Cloud Platform によって報告される us-west1 から us-central1 へのレイテンシについて見ていきます。

Cloud コンソールの [ネットワーク インテリジェンス] → [パフォーマンス ダッシュボード] に移動し、以下のスクリーンショットに示すオプションを選択します。レイテンシは 32 ~ 39 ミリ秒です。

aade5f757115721.png

us-west1 ベースライン サマリー

テストツールによる合計レイテンシ レポートを比較すると、HEY が報告するレイテンシとほぼ同じになります。リージョン間のレイテンシは、レイテンシの大部分を占めています。次の一連のテストで、central-client のパフォーマンスを見てみましょう。

レイテンシ ツール

所要時間

ネットワーク インテリジェンス: us-west1 から us-central1 へのレイテンシ

~ 32 ~ 39 ミリ秒

Cloud Monitoring: 合計予測レイテンシ [99th%]

34.58 ミリ秒(99p)

Google から報告された合計レイテンシ

~ 66.58 ~ 73.58 ms

HEY クライアント側のレイテンシの分布

68 ミリ秒(99p)

16. HEY(us-central1)をダウンロードして実行する

次のセクションでは、central-client にログインして、us-central1 にあるオンライン予測に対して HEY をダウンロードし、実行します。

Cloud Shell から central-client にログインして HEY をダウンロードする

gcloud compute ssh central-client --project=$projectid --zone=us-central1-a --tunnel-through-iap

OS から HEY をダウンロードして権限を更新します。

wget https://hey-release.s3.us-east-2.amazonaws.com/hey_linux_amd64
chmod +x hey_linux_amd64

OS から、次の変数を作成します。

gcloud config list project
gcloud config set project [YOUR-PROJECT-NAME]
projectid=YOUR-PROJECT-NAME
echo $projectid
ENDPOINT_ID="insert-your-endpoint-id-here"

例:

ENDPOINT_ID="2706243362607857664"

次のセクションでは、vi エディタまたは nano を使用して instances.json ファイルを作成し、デプロイしたモデルから予測を取得するために使用するデータ文字列を挿入します。

west-client OS から、以下のデータ文字列を使用して instances.json ファイルを作成します。

{"instances": [
  [0.23, 'Ideal', 'E', 'VS2', 61.5, 55.0, 3.95, 3.98, 2.43],
  [0.29, 'Premium', 'J', 'Internally Flawless', 52.5, 49.0, 4.00, 2.13, 3.11]]}

例:

user@west-client:$ more instances.json 
{"instances": [
  [0.23, 'Ideal', 'E', 'VS2', 61.5, 55.0, 3.95, 3.98, 2.43],
  [0.29, 'Premium', 'J', 'Internally Flawless', 52.5, 49.0, 4.00, 2.13, 3.11]]}

user@west-client:$

事前テスト

OS から curl を実行して、モデルと予測エンドポイントが正常に機能していることを確認します。詳細ログの PSC エンドポイント IP と、成功を示す HTTP/2 200 をメモします。

curl -v -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" https://us-central1-aiplatform.googleapis.com/v1/projects/${projectid}/locations/us-central1/endpoints/${ENDPOINT_ID}:predict -d @instances.json

例: 予測へのアクセスに使用される PSC の IP アドレスをメモし、示されます

user@central-client:~$ curl -v -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" https://us-central1-aiplatform.googleapis.com/v1/projects/${projectid}/locations/us-central1/endpoints/${ENDPOINT_ID}:predict -d @instances.json
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 100.100.10.10:443...
* Connected to us-central1-aiplatform.googleapis.com (100.100.10.10) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*  CAfile: /etc/ssl/certs/ca-certificates.crt
*  CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=upload.video.google.com
*  start date: Jul 31 08:22:19 2023 GMT
*  expire date: Oct 23 08:22:18 2023 GMT
*  subjectAltName: host "us-central1-aiplatform.googleapis.com" matched cert's "*.googleapis.com"
*  issuer: C=US; O=Google Trust Services LLC; CN=GTS CA 1C3
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x559b57adc2c0)
> POST /v1/projects/new-test-project-396322/locations/us-central1/endpoints/2706243362607857664:predict HTTP/2
> Host: us-central1-aiplatform.googleapis.com
> user-agent: curl/7.74.0
> accept: */*
> authorization: Bearer ya29.c.b0Aaekm1KWqq-CIXuL6f1cx9d9jHHquQq9tlSV1oVZ1y3TACi82JFFZRwsagVY7MMovycsU4PLkt9MDMkNngxZE5RzXcS-AoaUaQf1tPT9-_JMTlFI6wCcR7Yr9MeRF5AZblr_k52ZZgEZKeYGcrXoGiqGQcAAwFtHiEVAkUhLuyukteXbMoep1JM9E0zFblJj7Z0yOCMJYBH-6XHcIDYnOKpStMVBR2wcTDbnFrCE08HXbvRnQVcENatTBoI9FzSVL1ORwqUiCcdfnTSjpIXcyD-W82d6ZHjGX_RUhfnH7RPfOJqkuU8pOovwoCjq_jvM_wJUfPuQnBKHp5rxbYxPE349DMBql62po2SWFguuFo-a2eoUnb8-FQeBZqan65zgV0lexR73gZlm071y9grlXv3fmJUo7vlj5W-7_-FJXaWWg8iWc6rmjYeO1Wz2h_8qnmojkX9xSUciI6JfmwdgMWwtvwJb63ppSmdwf8oagrYiQlpMzgRI6rekbRzg-1WOBeOf5nRg5vtxUMSc9iRaoarO5XwFX8vt7rxOUBvbXYVWmo3bsdhzsS9VopMwgMlxgcIJg7bq7_F3iapB-nRjfjfhZWpR83cWIkI2Wb9f89inpsxtYjZbbzdWkZvRB8FYSsY8F8tcpiVoWWyQWZiph9z7O59fF9irWY2gtUnbFcJJ_ZcYztjlMQaR45y42ZflkM3Qn668bzge3Y3hmVI1s6ZSmxxq6m27hoMwVn21R07Y613jwljmaFJ5V8MwkR6yvFhYngrh_JrhRUQtSSMh02Rz25wMfv7g8Fiqymr-12viM4btIFjXZBM3XFqzvso_rw1omI1yYWofmbaBYggpegpJBzSeqVUZe791agjVtiMUkyjXFy__9gI0Qk9ZUarI4p25SvS4I1hX4YyBk6ol32Z5zIsVr1Seff__aklm6M2Mlkumd7nurm46hjOIoOhFpfFxrQ6yivnhYapBOJMYirgbZvigvI3dom1fnmt0-ktmRxp69w7Uzzy
> content-type: application/json
> content-length: 158
> 
* Connection state changed (MAX_CONCURRENT_STREAMS == 100)!
* We are completely uploaded and fine
< HTTP/2 200 
< x-vertex-ai-internal-prediction-backend: harpoon
< date: Sun, 20 Aug 2023 22:25:31 GMT
< content-type: application/json; charset=UTF-8
< vary: X-Origin
< vary: Referer
< vary: Origin,Accept-Encoding
< server: scaffolding on HTTPServer2
< cache-control: private
< x-xss-protection: 0
< x-frame-options: SAMEORIGIN
< x-content-type-options: nosniff
< accept-ranges: none
< 
{
  "predictions": [
    "$479.0",
    "$586.0"
  ],
  "deployedModelId": "3587550310781943808",
  "model": "projects/884291964428/locations/us-central1/models/6829574694488768512",
  "modelDisplayName": "diamonds-cpr",
  "modelVersionId": "1"
}
* Connection #0 to host us-central1-aiplatform.googleapis.com left intact

HEY を実行する

OS から、HEY を実行して 10 分間のベースライン テストを有効にします。

./hey_linux_amd64 -c 1 -z 10m -m POST -D instances.json  -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" https://us-central1-aiplatform.googleapis.com/v1/projects/$projectid/locations/us-central1/endpoints/${ENDPOINT_ID}:predict

17. Hey Validation(us-central1)

us-central1 のコンピューティング インスタンスから Hey を実行したので、以下の結果を評価します。

  • HEY の結果
  • Vertex カスタム ダッシュボード
  • ネットワーク インテリジェンス

HEY の結果

OS から、10 分間の実行に基づいて HEY の結果を検証しましょう。

44.9408 リクエスト/秒

99%(0.0353 秒)|35 ミリ秒

26965 レスポンス(ステータス コード 200)

devops_user_1_deepakmichael_alto@central-client:~$ ./hey_linux_amd64 -c 1 -z 10m -m POST -D instances.json  -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" https://us-central1-aiplatform.googleapis.com/v1/projects/$projectid/locations/us-central1/endpoints/${ENDPOINT_ID}:predict

Summary:
  Total:        600.0113 secs
  Slowest:      0.3673 secs
  Fastest:      0.0184 secs
  Average:      0.0222 secs
  Requests/sec: 44.9408
  

Response time histogram:
  0.018 [1]     |
  0.053 [26923] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  0.088 [25]    |
  0.123 [4]     |
  0.158 [0]     |
  0.193 [1]     |
  0.228 [9]     |
  0.263 [1]     |
  0.298 [0]     |
  0.332 [0]     |
  0.367 [1]     |


Latency distribution:
  10% in 0.0199 secs
  25% in 0.0205 secs
  50% in 0.0213 secs
  75% in 0.0226 secs
  90% in 0.0253 secs
  95% in 0.0273 secs
  99% in 0.0353 secs

Details (average, fastest, slowest):
  DNS+dialup:   0.0000 secs, 0.0184 secs, 0.3673 secs
  DNS-lookup:   0.0000 secs, 0.0000 secs, 0.0079 secs
  req write:    0.0000 secs, 0.0000 secs, 0.0007 secs
  resp wait:    0.0220 secs, 0.0182 secs, 0.3672 secs
  resp read:    0.0002 secs, 0.0001 secs, 0.0046 secs

Status code distribution:
  [200] 26965 responses

Vertex カスタム ダッシュボード

[モニタリング] → [ダッシュボード] に移動して [Vertex カスタム ダッシュボード] を選択し、「10m」と入力します。開始時刻と終了時刻を入力することもできます。タイムゾーンが正しいことを確認します。

最後の 10 m の予測レイテンシは 30.533 ms になります。

予測レイテンシの定義を見ると、サーバーサイドの指標は、モデルからレスポンスを取得してからクライアント リクエストに応答するまでの合計時間を測定する指標になっています。

  • 合計レイテンシ時間: リクエストがサービスに費やした合計時間。モデルのレイテンシにオーバーヘッドのレイテンシを加えたものです。

一方、HEY は以下のパラメータを考慮するクライアント側の指標です。

クライアント リクエスト + 合計レイテンシ(モデル レイテンシを含む)+ クライアント レスポンス

ネットワーク インテリジェンス

次に、Network Intelligence によって報告されるリージョン内のネットワーク レイテンシを見て、Google Cloud Platform によって報告される us-central1 レイテンシを理解しましょう。

Cloud コンソールの [ネットワーク インテリジェンス] → [パフォーマンス ダッシュボード] に移動し、以下のスクリーンショットに示すオプションを選択します。レイテンシは 0.2 ~ 0.8 ミリ秒です。

eaa84848c3185fde.png

us-central1 ベースライン サマリー

テストツールによって報告された合計レイテンシを比較すると、コンピューティング(central-client)と Vertex エンドポイント(モデルとオンライン予測)が同じリージョンにあるため、West-client よりもレイテンシが低くなります。

レイテンシ ツール

所要時間

Network Intelligence: us-central1 のリージョン内レイテンシ

~ 0.2 ~ 0 .8 ミリ秒

Cloud Monitoring: 合計予測レイテンシ [99th%]

30.533 ミリ秒(99p)

Google から報告された合計レイテンシ

~ 30.733 ~ 31.333 ms

HEY クライアント側のレイテンシ

35 ミリ秒(99p)

18. 完了

これで、HEY のデプロイと検証が正常に完了し、Cloud Monitoring とネットワーク インテリジェンスを組み合わせてクライアントサイドの予測ベースライン レイテンシを取得することができました。テストの結果、us-central の予測エンドポイントはリージョン間でサービスを提供できることがわかりましたが、レイテンシが確認されました。

コスモパップはチュートリアルを素晴らしいと思っています!!

e6d3675ca7c6911f.jpeg

19. クリーンアップ

Cloud Shell からチュートリアル コンポーネントを削除します。

gcloud compute instances delete central-client --zone=us-central1-a -q

gcloud compute instances delete west-client --zone=us-west1-a -q

gcloud compute instances delete workbench-tutorial --zone=us-central1-a -q

gcloud compute forwarding-rules delete pscvertex --global --quiet 

gcloud compute addresses delete psc-ip --global --quiet

gcloud compute networks subnets delete workbench-subnet --region=us-central1 --quiet 

gcloud compute networks subnets delete us-west1-subnet --region=us-west1 --quiet

gcloud compute networks subnets delete us-central1-subnet --region=us-central1 --quiet

gcloud compute routers delete cloud-router-us-west1-aiml-nat --region=us-west1 --quiet

gcloud compute routers delete cloud-router-us-central1-aiml-nat --region=us-central1 --quiet

gcloud compute firewall-rules delete  ssh-iap-vpc --quiet

gcloud dns record-sets delete *.googleapis.com. --zone=psc-googleapis --type=A --quiet

gcloud dns managed-zones delete psc-googleapis --quiet

gcloud compute networks delete aiml-vpc --quiet

gcloud storage rm -r gs://$projectid-cpr-bucket

Cloud コンソールから以下を削除しました。

Artifact Registry フォルダ

99c17044e2f80919.png

Vertex AI Model Registry からモデルのデプロイを解除します。

f5b315f089ae6283.png

Vertex AI Online Prediction からエンドポイントを削除する

9b58688a5037de84.png

次のステップ

チュートリアルをご覧ください...

参考資料と動画

リファレンス ドキュメント