EMR Spark クラスタ

EMR Spark アプローチでは、すべての Spark ジョブが Amazon EMR クラスタで実行されます。

要件

  • AWS ファイアウォールのアクセスルールを作成できるように、マシンにはパブリック IPv4 アドレスが必要です。
  • IAM の役割とポリシーを作成するには、ユーザーが AWS アカウントに対する権限を持っている必要があります。 「 DevOps 」の役割を推奨します。

展開手順

SDK conda 環境をアクティブ化します。

conda activate olp-sdk-for-python-1.12-env

グローバルプロパティとキーペアを含む EMR ワークスペースを初期化します。

Linux/MacOS の場合 :

emr-init

Windows の場合 :

emr-init.lnk

emr.env AWS とレポジトリ資格情報を提供する生成されたを編集します。

Linux/MacOS の場合 :

nano ~/.here/emr/emr.env

emr.env ファイルの例 :

#!/usr/bin/env bash

# Credentials variables
export DEFAULT_AWS_ACCESS_KEY="your AWS access key"
export DEFAULT_AWS_ACCESS_KEY_SECRET="your AWS access key secret"
export DEFAULT_HERE_USER="your HERE maven repository user"
export DEFAULT_HERE_PASSWORD="your HERE maven repository password"

# Environment variables
export DEFAULT_EMR_CORES="2"
export DEFAULT_EMR_VERSION="emr-5.24.0"
export DEFAULT_EMR_MASTER_TYPE="m4.large"
export DEFAULT_EMR_WORKER_TYPE="m4.2xlarge"
export DEFAULT_TAG_TEAM="My Team"
export DEFAULT_TAG_PROJECT="My Project"
export DEFAULT_TAG_OWNER="Me"
export DEFAULT_TAG_ENV="PoC"
export DEFAULT_AWS_REGION="us-east-2"

Windows の場合 :

notepad.exe %USERPROFILE%\.here\emr\emr.bat

サンプルの emr.bat ファイル :

REM Credentials variables
set DEFAULT_AWS_ACCESS_KEY=your-AWS-access-key
set DEFAULT_AWS_ACCESS_KEY_SECRET=your-AWS-access-key-secret
set DEFAULT_HERE_USER=your-HERE-maven-repository-user
set DEFAULT_HERE_PASSWORD=your-HERE-maven-repository-password

REM Environment variables
set DEFAULT_EMR_CORES=2
set DEFAULT_EMR_VERSION=emr-5.24.0
set DEFAULT_EMR_MASTER_TYPE=m4.large
set DEFAULT_EMR_WORKER_TYPE=m4.2xlarge
set DEFAULT_TAG_TEAM=My-Team
set DEFAULT_TAG_PROJECT=My-Project
set DEFAULT_TAG_OWNER=Me
set DEFAULT_TAG_ENV=PoC
set DEFAULT_AWS_REGION=us-east-2

EMR クラスタをプロビジョニングします。

Linux/MacOS の場合 :

emr-provision -ns <custom-single-word>

Windows の場合 :

emr-provision.lnk -ns <custom-single-word>

<custom-single-word> は、衝突を避けるために AWS リソース名に追加されたサフィックスです。 英数字とハイフンのみを使用できます。

プロビジョニングが成功すると、次のようなメッセージが表示されます。

Apply complete! Resources: 20 added, 0 changed, 0 destroyed.

Outputs:

emr_master_public_dns = ec2-3-16-25-189.us-east-2.compute.amazonaws.com

Environment up and running, fully operational!

Access your Livy session list here:

>> http://ec2-3-16-25-189.us-east-2.compute.amazonaws.com:8998

Access the YARN Resource Manager here:

>> http://ec2-3-16-25-189.us-east-2.compute.amazonaws.com:8088

You can use this bucket to upload and process data

>> s3://spark-emrlab-bucket-lab

Jupyter 内でノートブックを作成し、 Python3 カーネルのいずれかを選択して次のセルを追加し、 credentials.properties の Property spark.driver.extrJavaOptions および spark.executor.preJavaOptions のプレースホルダーに資格情報を追加します。

セル 1

%load_ext sparkmagic.magics

セル 2

%%spark config
{
  "driverMemory": "2G",
  "executorMemory": "4G",
  "executorCores": 2,
  "conf": {
    "spark.driver.extraJavaOptions": "-Dhere.platform.data-client.request-signer.credentials.here-account.here-token-endpoint-url=<here.account.token.endpoint> -Dhere.platform.data-client.request-signer.credentials.here-account.here-client-id=<here.account.clientid> -Dhere.platform.data-client.request-signer.credentials.here-account.here-access-key-id=<here.access.key.id> -Dhere.platform.data-client.request-signer.credentials.here-account.here-access-key-secret=<here.access.key.secret>",
    "spark.executor.extraJavaOptions" : "-Dhere.platform.data-client.request-signer.credentials.here-account.here-token-endpoint-url=<here.account.token.endpoint> -Dhere.platform.data-client.request-signer.credentials.here-account.here-client-id=<here.account.clientid> -Dhere.platform.data-client.request-signer.credentials.here-account.here-access-key-id=<here.access.key.id> -Dhere.platform.data-client.request-signer.credentials.here-account.here-access-key-secret=<here.access.key.secret>",
    "spark.hadoop.fs.olp.impl": "com.here.platform.data.client.hdfs.DataServiceHadoopFileSystem",
    "spark.scheduler.mode": "FAIR",
    "spark.executor.instances": 2,
    "spark.dynamicAllocation.enabled": "true",
    "spark.shuffle.service.enabled": "true",
    "spark.dynamicAllocation.executorIdleTimeout": "60s",
    "spark.dynamicAllocation.cachedExecutorIdleTimeout": "60s",
    "spark.dynamicAllocation.minExecutors": 2,
    "spark.dynamicAllocation.maxExecutors": 4,
    "spark.dynamicAllocation.initialExecutors": 2,
    "spark.jars.ivySettings": "/var/lib/spark/.here/ivy.settings.xml",
    "spark.driver.userClassPathFirst": "false",
    "spark.executor.userClassPathFirst": "false",
    "spark.jars.packages": "com.here.olp.util:mapquad:4.0.13,com.here.platform.location:location-compilation-core_2.11:0.20.184,com.here.platform.location:location-core_2.11:0.20.184,com.here.platform.location:location-inmemory_2.11:0.20.184,com.here.platform.location:location-integration-here-commons_2.11:0.20.184,com.here.platform.location:location-integration-optimized-map_2.11:0.20.184,com.here.platform.location:location-data-loader-standalone_2.11:0.20.184,com.here.platform.location:location-spark_2.11:0.20.184,com.here.platform.location:location-compilation-here-map-content_2.11:0.20.184,com.here.platform.location:location-examples-utils_2.11:0.4.115,com.here.schema.sdii:sdii_archive_v1_java:2.0.1,com.here.sdii:sdii_message_v3_java:4.0.1,com.here.sdii:sdii_message_list_v3_java:4.0.1,com.here.schema.rib:lane-attributes_v2_scala:2.33.0,com.here.schema.rib:road-traffic-pattern-attributes_v2_scala:2.33.0,com.here.schema.rib:advanced-navigation-attributes_v2_scala:2.33.0,com.here.schema.rib:cartography_v2_scala:2.33.0,com.here.schema.rib:adas-attributes_v2_scala:2.33.0,com.typesafe.akka:akka-actor_2.11:2.5.11,com.beachape:enumeratum_2.11:1.5.13,com.github.ben-manes.caffeine:caffeine:2.6.2,com.github.cb372:scalacache-caffeine_2.11:0.24.3,com.github.cb372:scalacache-core_2.11:0.24.3,com.github.os72:protoc-jar:3.6.0,com.google.protobuf:protobuf-java:3.6.1,com.iheart:ficus_2.11:1.4.3,com.typesafe:config:1.3.3,org.apache.logging.log4j:log4j-api-scala_2.11:11.0,org.typelevel:cats-core_2.11:1.4.0,org.typelevel:cats-kernel_2.11:1.4.0,org.apache.logging.log4j:log4j-api:2.8.2,com.here.platform.data.client:spark-support_2.11:0.5.30,com.here.platform.data.client:data-client_2.11:0.5.30,com.here.platform.data.client:client-core_2.11:0.5.30,com.here.platform.data.client:hrn_2.11:0.1.614,com.here.platform.data.client:data-engine_2.11:0.5.30,com.here.platform.data.client:blobstore-client_2.11:0.5.30,com.here.account:here-oauth-client:0.4.13,com.here.platform.analytics:spark-ds-connector-deps_2.11:0.6.15,com.here.platform.analytics:spark-ds-connector_2.11:0.6.15",
    "spark.jars.excludes": "com.google.protobuf:protobuf-java,com.here.*:*_proto,org.json4s:*,org.apache.spark:spark-core_2.11,org.apache.spark:spark-sql_2.11,org.apache.spark:spark-streaming_2.11,org.apache.spark:spark-launcher_2.11,org.apache.spark:spark-network-shuffle_2.11,org.apache.spark:spark-unsafe_2.11,org.apache.spark:spark-network-common_2.11,org.apache.spark:spark-tags_2.11,org.scala-lang:scala-library,org.scala-lang:scala-compiler,org.scala-lang.modules:scala-parser-combinators_2.11,org.scala-lang.modules:scala-java8-compat_2.11,org.scala-lang:scala-reflect,org.scala-lang:scalap,com.fasterxml.jackson.core:jackson-*"
  }
}

セル 3

# For a Scala Spark session
%spark add -s scala-spark -l scala -u <PUT YOUR LIVY ENDPOINT HERE> -k

# For a Pyspark Session
%spark add -s pyspark -l python -u <PUT YOUR LIVY ENDPOINT HERE> -k

EMR では、ノートブック内のプラットフォームデータを読み取るために、資格情報を明示的に提供する必要があります。 ジョブを送信するには、アプリ ID とキーシークレットが必要です。

資格情報を使用します

Scala

%%spark
val accessKeyId = "<Your Access Key ID>"
val accessKeySecret = "<Your Access Key Secret>"
val layerHRN = "<Some Layern HRN>"

val df = spark.read.option( "partitions", 900)
            .option("parallelism", 4)
            .option("accesskeyid", accessKeyId) 
            .option("accesskeysecret", accessKeySecret)
            .ds(layerHRN)

PySpark

%%spark
accessKeyId = "<Your Access Key ID>"
accessKeySecret = "<Your Access Key Secret>"
layerHRN = "<Some Layern HRN>"

df = spark.read.format("com.here.platform.analytics.ds")
            .option("partitions", 900)
            .option("parallelism", 4)
            .option("accesskeyid", accessKeyId) 
            .option("accesskeysecret", accessKeySecret)
            .option("layerhrn", layerHRN)
            .load()

ジョブのコーディングを開始します。

作業が完了したら、クラスタを破壊して、使用されていないインフラストラクチャの料金が請求されないようにします。

Linux/MacOS の場合 :

emr-deprovision

Windows の場合 :

emr-deprovision.lnk

ディープデバッグ

既定では、インターネットアクセスは、 Livy および YARN リソース管理者のエンドポイントにのみ制限されています。 クラスタログを参照して内部ノードマシンにアクセスする場合は、 SSH トンネルを開いて接続する必要があります。 新しいクラスタを展開すると、 SSH トンネルを開くためのスクリプトコマンドが作成されます。 Linux/MacOS の場合 :

$ cd ~/.here/emr
$ ./emr-tunnel.sh

Windows の場合 :

$ cd %USERPROFILE%\.here\emr
$ emr-tunnel.bat

次に、 Web ブラウザに Foxy プロキシをインストールする必要があります。

次に、ご利用の Web ブラウザに応じて、提供されている Foxy プロキシ設定をロードします。

  • Chrome の場合 : ~/anaconda3/envs/<your_env>/lib/olp-emr/util/foxy-proxy-chrome.xml
  • Firefox の場合 : ~/anaconda3/envs/<your_env>/lib/olp-emr/util/foxy-proxy-firefox.json

次に、すべての URL またはパターンに基づいて、 Foxy プロキシをアクティブ化できます(手順については、 Foxy プロキシを参照してください)。 これで、 Web ブラウザ経由で内部マシンのエンドポイントにアクセスできるようになります。

チュートリアルノートブック

EMR のチュートリアル・ノートブックは 、以下のフォルダーにあります。

Linux/MacOS の場合 :$HOME/olp-sdk-for-python-1.12/tutorial-notebooks/emr

Windows の場合 :%USERPROFILE%\olp-sdk-for-python-1.12\tutorial-notebooks\emr

まず、にある「はじめに」ノートブックから作業を開始できます

Linux/MacOS の場合 : $HOME/olp-sdk-for-python-1.12/tutorial-notebooks/GettingStarted.ipynb

Windows の場合 :%USERPROFILE%\olp-sdk-for-python-1.12\tutorial-notebooks\GettingStarted.ipynb すべてのチュートリアルノートブックの概要を取得します。

AWS EMR Jupyter ノートブックで Java および Scala JAR 用の Data SDK を使用します

EMR ノートブックで Java および Scala jar 用の Data SDK を使用する場合 は、上記の展開手順で作成された既存の EMR クラスタを設定できます。

EMR ノートブックインスタンスを開始し、 EMR ノートブック内でノートブックを作成してから、必要なカーネルのいずれかを選択し、次のセルを追加します。

セル 1

%load_ext sparkmagic.magics

セル 2

%manage_spark

次に、上記のコマンドの出力ウィジェットで [ セッションの作成 ] タブをクリックし、 [ プロパティ ] 入力テキストボックスに以下の JSON を貼り付けます。

credentials.properties の spark.priver.extraJavaOptions プロパティと spark.executor.preJavaOptions プロパティのプレースホルダーに資格情報を追加します。 Spark コンテキストのステータスを確認し、に移動 {EMR_Master_Node_IP}:8998して Livy セッションを確認します。

{
  "driverMemory": "2G",
  "executorMemory": "4G",
  "executorCores": 2,
  "conf": {
    "spark.driver.extraJavaOptions": "-Dhere.platform.data-client.request-signer.credentials.here-account.here-token-endpoint-url=<here.account.token.endpoint> -Dhere.platform.data-client.request-signer.credentials.here-account.here-client-id=<here.account.clientid> -Dhere.platform.data-client.request-signer.credentials.here-account.here-access-key-id=<here.access.key.id> -Dhere.platform.data-client.request-signer.credentials.here-account.here-access-key-secret=<here.access.key.secret>",
    "spark.executor.extraJavaOptions" : "-Dhere.platform.data-client.request-signer.credentials.here-account.here-token-endpoint-url=<here.account.token.endpoint> -Dhere.platform.data-client.request-signer.credentials.here-account.here-client-id=<here.account.clientid> -Dhere.platform.data-client.request-signer.credentials.here-account.here-access-key-id=<here.access.key.id> -Dhere.platform.data-client.request-signer.credentials.here-account.here-access-key-secret=<here.access.key.secret>",
    "spark.hadoop.fs.olp.impl": "com.here.platform.data.client.hdfs.DataServiceHadoopFileSystem",
    "spark.scheduler.mode": "FAIR",
    "spark.executor.instances": 2,
    "spark.dynamicAllocation.enabled": "true",
    "spark.shuffle.service.enabled": "true",
    "spark.dynamicAllocation.executorIdleTimeout": "60s",
    "spark.dynamicAllocation.cachedExecutorIdleTimeout": "60s",
    "spark.dynamicAllocation.minExecutors": 2,
    "spark.dynamicAllocation.maxExecutors": 4,
    "spark.dynamicAllocation.initialExecutors": 2,
    "spark.jars.ivySettings": "/var/lib/spark/.here/ivy.settings.xml",
    "spark.driver.userClassPathFirst": "false",
    "spark.executor.userClassPathFirst": "false",
    "spark.jars.packages": "com.here.olp.util:mapquad:4.0.13,com.here.platform.location:location-compilation-core_2.11:0.20.184,com.here.platform.location:location-core_2.11:0.20.184,com.here.platform.location:location-inmemory_2.11:0.20.184,com.here.platform.location:location-integration-here-commons_2.11:0.20.184,com.here.platform.location:location-integration-optimized-map_2.11:0.20.184,com.here.platform.location:location-data-loader-standalone_2.11:0.20.184,com.here.platform.location:location-spark_2.11:0.20.184,com.here.platform.location:location-compilation-here-map-content_2.11:0.20.184,com.here.platform.location:location-examples-utils_2.11:0.4.115,com.here.schema.sdii:sdii_archive_v1_java:2.0.1,com.here.sdii:sdii_message_v3_java:4.0.1,com.here.sdii:sdii_message_list_v3_java:4.0.1,com.here.schema.rib:lane-attributes_v2_scala:2.33.0,com.here.schema.rib:road-traffic-pattern-attributes_v2_scala:2.33.0,com.here.schema.rib:advanced-navigation-attributes_v2_scala:2.33.0,com.here.schema.rib:cartography_v2_scala:2.33.0,com.here.schema.rib:adas-attributes_v2_scala:2.33.0,com.typesafe.akka:akka-actor_2.11:2.5.11,com.beachape:enumeratum_2.11:1.5.13,com.github.ben-manes.caffeine:caffeine:2.6.2,com.github.cb372:scalacache-caffeine_2.11:0.24.3,com.github.cb372:scalacache-core_2.11:0.24.3,com.github.os72:protoc-jar:3.6.0,com.google.protobuf:protobuf-java:3.6.1,com.iheart:ficus_2.11:1.4.3,com.typesafe:config:1.3.3,org.apache.logging.log4j:log4j-api-scala_2.11:11.0,org.typelevel:cats-core_2.11:1.4.0,org.typelevel:cats-kernel_2.11:1.4.0,org.apache.logging.log4j:log4j-api:2.8.2,com.here.platform.data.client:spark-support_2.11:0.5.30,com.here.platform.data.client:data-client_2.11:0.5.30,com.here.platform.data.client:client-core_2.11:0.5.30,com.here.platform.data.client:hrn_2.11:0.1.614,com.here.platform.data.client:data-engine_2.11:0.5.30,com.here.platform.data.client:blobstore-client_2.11:0.5.30,com.here.account:here-oauth-client:0.4.13,com.here.platform.analytics:spark-ds-connector-deps_2.11:0.6.15,com.here.platform.analytics:spark-ds-connector_2.11:0.6.15",
    "spark.jars.excludes": "com.google.protobuf:protobuf-java,com.here.*:*_proto,org.json4s:*,org.apache.spark:spark-core_2.11,org.apache.spark:spark-sql_2.11,org.apache.spark:spark-streaming_2.11,org.apache.spark:spark-launcher_2.11,org.apache.spark:spark-network-shuffle_2.11,org.apache.spark:spark-unsafe_2.11,org.apache.spark:spark-network-common_2.11,org.apache.spark:spark-tags_2.11,org.scala-lang:scala-library,org.scala-lang:scala-compiler,org.scala-lang.modules:scala-parser-combinators_2.11,org.scala-lang.modules:scala-java8-compat_2.11,org.scala-lang:scala-reflect,org.scala-lang:scalap,com.fasterxml.jackson.core:jackson-*"
  }
}

HERE Data SDK for Python をお選びいただきありがとうございます。 設定後、この 1 分間の簡単な調査に記入して、セットアップ体験の改善に役立ててください。


」に一致する結果は 件です

    」に一致する結果はありません