【发布时间】: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