【问题标题】:What data Apache Spark ships to execution nodesApache Spark 向执行节点发送哪些数据
【发布时间】:2015-07-27 19:10:56
【问题描述】:

我使用 Apache Spark 来查找以太网通信中的模式/攻击。我担心 Spark 发送到 YARN/Hadoop 执行节点的数据量。

我在我的地图函数中使用 Scapy(见下面的代码)。如果它没有安装在执行节点上,Spark 会将整个模块发送给它们吗?或者在这种情况下任务不会被执行?还是以失败告终?有没有办法控制这种行为?

如果我的地图函数访问任何全局对象会发生什么?物品是否运送给工人?还是存在某种错误/意外行为?

这是一个示例代码:

#!/usr/bin/python
from pyspark import SparkContext, SparkConf

def ExtractIP(rawEther):
    from scapy.layers.inet import Ether, IP

    eth = Ether(rawEther)
    # May not be IP (for example ARP)
    try:
        return eth[IP].fields['src']
    except:
        return '0.0.0.0'

def main():
    # Init Spark
    conf = SparkConf().setAppName("MyApp").setMaster("local")
    sc = SparkContext(conf=conf)

    # Load data
    cap = sc.sequenceFile("hdfs://master/user/art/Data.seq")

    # Get raw Ethernet message
    raw_msgs = cap.values()

    # Get the source IP address using Scapy
    msg_ip = raw_msgs.map(ExtractIP)

    # Print the number of target IP messages
    print msg_ip.filter(lambda srcIp: srcIp == '10.1.1.100').count()


if __name__ == "__main__":
    main()

【问题讨论】:

    标签: python hadoop apache-spark scapy pyspark


    【解决方案1】:

    闭包中引用的所有变量都会自动传送到工作节点,但您需要处理依赖关系。

    有多种处理方法:

    1. 安装依赖/放置在每个工作节点上的PYTHONPATH
    2. 在现有方法上创建 SparkContextaddPyFile 方法时使用 pyFiles 参数
    3. 使用--py-files 参数spark-submit

    如果依赖关系很大或需要一些外部库,第一种方法可能是最佳的。如果构建您自己的模块,您可能更喜欢pyFiles 解决方案之一。

    【讨论】:

      猜你喜欢
      • 2017-01-05
      • 1970-01-01
      • 2015-04-13
      • 1970-01-01
      • 2016-07-19
      • 2020-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多