web-dev-qa-db-ja.com

Spark: "プールからの接続を待機するタイムアウト"

Sparkジョブを小さな3サーバーのAmazon EMR 5(Spark 2.0)クラスターで実行しています。ジョブが1時間ほど実行されると、次のエラーで失敗します。手動で再起動して、それは機能し、より多くのデータを処理し、最終的に再び失敗します。

My Sparkコードはかなりシンプルで、AmazonまたはS3 APIを直接使用していません。MySparkコードは、S = 3テキスト文字列パスをSparkおよびSparkは内部でS3を使用します。

私のSparkプログラムは、ループ内で次のことを行うだけです。S3からデータをロード->プロセス-> S3の別の場所にデータを書き込みます。

私の最初の疑いは、いくつかの内部AmazonまたはSpark=コードが接続を適切に処理しておらず、接続プールが使い果たされていることです。

com.Amazon.ws.emr.hadoop.fs.shaded.com.amazonaws.AmazonClientException: Unable to execute HTTP request: Timeout waiting for connection from pool
            at com.Amazon.ws.emr.hadoop.fs.shaded.com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.Java:618)
            at com.Amazon.ws.emr.hadoop.fs.shaded.com.amazonaws.http.AmazonHttpClient.doExecute(AmazonHttpClient.Java:376)
            at com.Amazon.ws.emr.hadoop.fs.shaded.com.amazonaws.http.AmazonHttpClient.executeWithTimer(AmazonHttpClient.Java:338)
            at com.Amazon.ws.emr.hadoop.fs.shaded.com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.Java:287)
            at com.Amazon.ws.emr.hadoop.fs.shaded.com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.Java:3826)
            at com.Amazon.ws.emr.hadoop.fs.shaded.com.amazonaws.services.s3.AmazonS3Client.getObjectMetadata(AmazonS3Client.Java:1015)
            at com.Amazon.ws.emr.hadoop.fs.shaded.com.amazonaws.services.s3.AmazonS3Client.getObjectMetadata(AmazonS3Client.Java:991)
            at com.Amazon.ws.emr.hadoop.fs.s3n.Jets3tNativeFileSystemStore.retrieveMetadata(Jets3tNativeFileSystemStore.Java:212)
            at Sun.reflect.GeneratedMethodAccessor45.invoke(Unknown Source)
            at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
            at Java.lang.reflect.Method.invoke(Method.Java:498)
            at org.Apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.Java:191)
            at org.Apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.Java:102)
            at com.Sun.proxy.$Proxy44.retrieveMetadata(Unknown Source)
            at com.Amazon.ws.emr.hadoop.fs.s3n.S3NativeFileSystem.getFileStatus(S3NativeFileSystem.Java:780)
            at org.Apache.hadoop.fs.FileSystem.exists(FileSystem.Java:1428)
            at com.Amazon.ws.emr.hadoop.fs.EmrFileSystem.exists(EmrFileSystem.Java:313)
            at org.Apache.spark.sql.execution.datasources.InsertIntoHadoopFsRelationCommand.run(InsertIntoHadoopFsRelationCommand.scala:85)
            at org.Apache.spark.sql.execution.command.ExecutedCommandExec.sideEffectResult$lzycompute(commands.scala:60)
            at org.Apache.spark.sql.execution.command.ExecutedCommandExec.sideEffectResult(commands.scala:58)
            at org.Apache.spark.sql.execution.command.ExecutedCommandExec.doExecute(commands.scala:74)
            at org.Apache.spark.sql.execution.SparkPlan$$anonfun$execute$1.apply(SparkPlan.scala:115)
            at org.Apache.spark.sql.execution.SparkPlan$$anonfun$execute$1.apply(SparkPlan.scala:115)
            at org.Apache.spark.sql.execution.SparkPlan$$anonfun$executeQuery$1.apply(SparkPlan.scala:136)
            at org.Apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:151)
            at org.Apache.spark.sql.execution.SparkPlan.executeQuery(SparkPlan.scala:133)
            at org.Apache.spark.sql.execution.SparkPlan.execute(SparkPlan.scala:114)
            at org.Apache.spark.sql.execution.QueryExecution.toRdd$lzycompute(QueryExecution.scala:86)
            at org.Apache.spark.sql.execution.QueryExecution.toRdd(QueryExecution.scala:86)
            at org.Apache.spark.sql.execution.datasources.DataSource.write(DataSource.scala:487)
            at org.Apache.spark.sql.DataFrameWriter.save(DataFrameWriter.scala:211)
            at org.Apache.spark.sql.DataFrameWriter.save(DataFrameWriter.scala:194)
            at Sun.reflect.GeneratedMethodAccessor85.invoke(Unknown Source)
            at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
            at Java.lang.reflect.Method.invoke(Method.Java:498)
            at py4j.reflection.MethodInvoker.invoke(MethodInvoker.Java:237)
            at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.Java:357)
            at py4j.Gateway.invoke(Gateway.Java:280)
            at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.Java:128)
            at py4j.commands.CallCommand.execute(CallCommand.Java:79)
            at py4j.GatewayConnection.run(GatewayConnection.Java:211)
            at Java.lang.Thread.run(Thread.Java:745)
    Caused by: com.Amazon.ws.emr.hadoop.fs.shaded.org.Apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection from pool
            at com.Amazon.ws.emr.hadoop.fs.shaded.org.Apache.http.impl.conn.PoolingClientConnectionManager.leaseConnection(PoolingClientConnectionManager.Java:226)
            at com.Amazon.ws.emr.hadoop.fs.shaded.org.Apache.http.impl.conn.PoolingClientConnectionManager$1.getConnection(PoolingClientConnectionManager.Java:195)
            at Sun.reflect.GeneratedMethodAccessor43.invoke(Unknown Source)
            at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
            at Java.lang.reflect.Method.invoke(Method.Java:498)
            at com.Amazon.ws.emr.hadoop.fs.shaded.com.amazonaws.http.conn.ClientConnectionRequestFactory$Handler.invoke(ClientConnectionRequestFactory.Java:70)
            at com.Amazon.ws.emr.hadoop.fs.shaded.com.amazonaws.http.conn.$Proxy45.getConnection(Unknown Source)
            at com.Amazon.ws.emr.hadoop.fs.shaded.org.Apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.Java:423)
            at com.Amazon.ws.emr.hadoop.fs.shaded.org.Apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.Java:863)
            at com.Amazon.ws.emr.hadoop.fs.shaded.org.Apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.Java:82)
            at com.Amazon.ws.emr.hadoop.fs.shaded.org.Apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.Java:57)
            at com.Amazon.ws.emr.hadoop.fs.shaded.com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.Java:837)
            at com.Amazon.ws.emr.hadoop.fs.shaded.com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.Java:607)
            ... 41 more
15
clay

この問題は、EMRの非常に簡単なプログラム(S3からのデータの読み取り、フィルター、S3への書き込み)で発生しました。

S3Aファイルシステムの実装を使用し、fs.s3a.connection.maximum100に設定して、より大きな接続プールを持つことで、問題を解決できました。 (デフォルトは15です。詳細については Hadoop-AWSモジュール:アマゾンウェブサービスとの統合 を参照してください)

これは私が設定を設定する方法です:

// in Scala
val hc = sc.hadoopConfiguration

// in Python (not tested)
hc = sc._jsc.hadoopConfiguration()

// setting the config is the same for both languages
hc.set("fs.s3a.impl", "org.Apache.hadoop.fs.s3a.S3AFileSystem")
hc.setInt("fs.s3a.connection.maximum", 100)

これを機能させるには、Sparkに渡されるS3 URIがs3a://...で始まる必要があります

9
hiddenbit

この問題は、emrfs-site configでfs.s3.maxConnectionsをデフォルトの500よりも大きい値に設定することで、EMRFSにとどまっているときにも解決される場合があります。

https://aws.Amazon.com/premiumsupport/knowledge-center/emr-timeout-connection-wait/

1