最近,我的任务是在Databricks Delta-lake上摄取JSON响应。我必须使用不同的参数访问REST端点URL 6500次,并提取响应。
我尝试了多处理库中的两个模块,ThreadPool和Pool,以使每个模块的执行速度更快一些。
ThreadPool:
现在,我已经设置了n_pool = multiprocessing.cpu_count(),如果集群自动缩放,会有什么不同吗?
池
Py4JError: SparkConf does not exist in the JVM
**OR**
py4j.protocol.Py4JError: org.apache.spark.api.python.PythonUtils.getEncryptionEnabled does not exist in the JVM发布于 2022-03-01 12:19:19
如果使用线程池,它们将只在驱动程序节点上运行,执行器将处于空闲状态。相反,您需要使用Spark本身来并行化请求。这通常是通过创建一个带有URL列表(如果基本URL是相同的URL参数)的数据same来完成的,然后使用Spark来执行实际的请求。就像这样:
import urllib
df = spark.createDataFrame([("url1", "params1"), ("url2", "params2")],
("url", "params"))
@udf("body string, status int")
def do_request(url: str, params: str):
full_url = url + "?" + params # adjust this as required
with urllib.request.urlopen(full_url) as f:
status = f.status
body = f.read().decode("utf-8")
return {'status': status, 'body': body}
res = df.withColumn("result", do_requests(col("url"), col("params")))这将使用一个名为result的新列返回dataframe,该列将有两个字段-- status和body (JSON答案作为字符串)。
发布于 2022-02-28 08:56:45
您可以尝试以下方法来解决
Py4JError: SparkConf does not exist in the JVM
**OR**
py4j.protocol.Py4JError: org.apache.spark.api.python.PythonUtils.getEncryptionEnabled does not exist in the JVM错误
Install findspark
$pip install findspark
Code:
import findsparkfindspark.init()参考文献:Py4JError: JVM中不存在SparkConf和org.apache.spark.api.python.PythonUtils.getEncryptionEnabled : JVM中不存在org.apache.spark.api.python.PythonUtils.getEncryptionEnabled
https://stackoverflow.com/questions/71094840
复制相似问题