【问题标题】:Can I run a pyspark jupyter notebook in cluster deploy mode?我可以在集群部署模式下运行 pyspark jupyter notebook 吗?
【发布时间】:2018-02-10 08:04:33
【问题描述】:

背景: 集群配置如下:

  • 一切都在使用 docker 文件运行。
  • node1:火花大师
  • node2:jupyter hub(我也在这里运行我的笔记本)
  • node3-7:火花工作节点
  • 我可以使用 spark 的默认端口从我的工作节点 telnet 和 ping 到 node2,反之亦然

问题: 我正在尝试在以集群部署模式运行的 pyspark jupyter notebook 中创建一个 spark 会话。我试图让驱动程序在不是运行 jupyter notebook 的节点的节点上运行。现在我可以在集群上运行作业,但只能在 node2 上运行驱动程序。

经过大量挖掘,我发现了这个stackoverflow post,它声称如果您使用 spark 运行交互式 shell,您只能在本地部署模式下执行此操作(驱动程序位于您正在使用的机器上)。那篇文章接着说,像 jupyter hub 这样的东西也不能在集群部署模式下工作,但我找不到任何可以证实这一点的文档。有人可以确认 jupyter hub 是否可以在集群模式下运行吗?

我尝试在集群部署模式下运行 spark 会话:

from pyspark.sql import SparkSession

spark = SparkSession.builder\
.enableHiveSupport()\
.config("spark.local.ip",<node 3 ip>)\
.config("spark.driver.host",<node 3 ip>)\
.config('spark.submit.deployMode','cluster')\
.getOrCreate()

错误:

/usr/spark/python/pyspark/sql/session.py in getOrCreate(self)
    167                     for key, value in self._options.items():
    168                         sparkConf.set(key, value)
--> 169                     sc = SparkContext.getOrCreate(sparkConf)
    170                     # This SparkContext may be an existing one.
    171                     for key, value in self._options.items():

/usr/spark/python/pyspark/context.py in getOrCreate(cls, conf)
    308         with SparkContext._lock:
    309             if SparkContext._active_spark_context is None:
--> 310                 SparkContext(conf=conf or SparkConf())
    311             return SparkContext._active_spark_context
    312 

/usr/spark/python/pyspark/context.py in __init__(self, master, appName, sparkHome, pyFiles, environment, batchSize, serializer, conf, gateway, jsc, profiler_cls)
    113         """
    114         self._callsite = first_spark_call() or CallSite(None, None, None)
--> 115         SparkContext._ensure_initialized(self, gateway=gateway, conf=conf)
    116         try:
    117             self._do_init(master, appName, sparkHome, pyFiles, environment, batchSize, serializer,

/usr/spark/python/pyspark/context.py in _ensure_initialized(cls, instance, gateway, conf)
    257         with SparkContext._lock:
    258             if not SparkContext._gateway:
--> 259                 SparkContext._gateway = gateway or launch_gateway(conf)
    260                 SparkContext._jvm = SparkContext._gateway.jvm
    261 

/usr/spark/python/pyspark/java_gateway.py in launch_gateway(conf)
     93                 callback_socket.close()
     94         if gateway_port is None:
---> 95             raise Exception("Java gateway process exited before     sending the driver its port number")
     96 
     97         # In Windows, ensure the Java child processes do not linger after Python has exited.

Exception: Java gateway process exited before sending the driver its port number

【问题讨论】:

    标签: apache-spark pyspark jupyter-notebook


    【解决方案1】:

    You cannot use cluster mode with PySpark at all:

    目前,独立模式不支持 Python 应用程序的集群模式。

    即使你可以cluster mode is not applicable in interactive environment:

    case (_, CLUSTER) if isShell(args.primaryResource) =>
      error("Cluster deploy mode is not applicable to Spark shells.")
    case (_, CLUSTER) if isSqlShell(args.mainClass) =>
      error("Cluster deploy mode is not applicable to Spark SQL shell.")
    

    【讨论】:

    • 只是想指出这对于独立模式是正确的(就像在原始问题中一样)。如果您使用其他集群管理器(例如 Yarn),您可以使用 PySpark 以集群模式提交作业。
    • 主题问题是关于集群部署的。声明“您根本不能将集群模式与 PySpark 一起使用”是不正确的 - 我们确实在生产中一直使用带有 yarn-cluster 模式的 pyspark。 @J Schmidt 指出的错误与以独立模式运行的 pyspark 无关。实际上他的示例显示 .config('spark.submit.deployMode','cluster') 这不是独立模式。谢谢。
    【解决方案2】:
    1. Jupyter 中间接使用 yarn-cluster 模式的一种“支持”方式 是通过 Apache Livy

    基本上,LivySpark 集群的 REST API 服务。

    Jupyter 有一个扩展名“spark-magic”,允许将LivyJupyter 集成在一起

    JupyterSpark-magic 绑定的示例(驱动程序在纱线集群中运行,在这种情况下不在本地运行,如上所述):

    1. 在 Jupyter 中使用 YARN-cluster 模式的另一种方法是使用 Jupyter Enterprise Gateway https://jupyter-enterprise-gateway.readthedocs.io/en/latest/kernel-yarn-cluster-mode.html#configuring-kernels-for-yarn-cluster-mode

    2. 还有一些商业选项通常使用我上面列出的方法之一。例如,我们的一些用户在 IBM DSX(又名 IBM Watson Studio Local)上使用 Apache Livy - 上面的第一个选项。

    【讨论】:

      【解决方案3】:

      我不是 PySpark 方面的专家,但是您是否尝试过更改 pyspark jupyter 内核的 kernel.json 文件?

      也许您可以在其中添加选项部署模式集群

      "env": {
        "SPARK_HOME": "/your_dir/spark",
        "PYTHONPATH": "/your_dir/spark/python:/your_dir/spark/python/lib/py4j-0.9-src.zip",
        "PYTHONSTARTUP": "/your_dir/spark/python/pyspark/shell.py",
        "PYSPARK_SUBMIT_ARGS": "--master local[*] pyspark-shell"
       }
      

      你改变这一行:

      "PYSPARK_SUBMIT_ARGS": "--master local[*] pyspark-shell"
      

      使用您的集群主 IP 和 --deploy-mode 集群

      不确定这会改变什么,但也许可行,我也很想知道!

      祝你好运

      编辑:我发现这也许可以帮助你,即使它是从 2015 年开始的

      link jupyter pyspark cluster

      【讨论】:

        猜你喜欢
        • 2018-09-15
        • 2021-11-23
        • 2020-11-03
        • 2020-10-31
        • 1970-01-01
        • 2018-09-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多