我有一个PySpark的示例作业,它是PageRank算法的一个版本。
代码如下:
from __future__ import print_function
from operator import add
import timeit
from pyspark.sql import SparkSession
# Normalize a list of pairs(url, rank) to 1
def normalize(ranks):
norm = sum([rank for u, rank in ranks])
ranks = [(u, rank / norm) for (u, rank) in ranks ]
return sorted(ranks, key=lambda x: x[1], reverse=True)
def pagerank_2(edgeList, n, niter):
# Loads all URLs from input file and initialize their neighbors.
m = edgeList.groupByKey().cache()
s = 0.85
# Loads all URLs with other URL(s) link to from input file
# and initialize ranks of them to one.
q = spark.sparkContext.range(n).map(lambda x: (x, 1.0)).cache()
r = spark.sparkContext.range(n).map(lambda x: (x, 0.0)).cache()
# Calculates and updates URL ranks continuously
# using PageRank algorithm.
for iteration in range(niter):
# Calculates URL contributions to the rank of other URLs.
# Add URL ranks based on neighbor contributions.
# Do not forget to add missing values in q and set to 0.0
q = q.fullOuterJoin(m)\
.flatMap(lambda x: (x[1][1] and [(u, x[1][0]/len(x[1][1])) for u in x[1][1]]) or [])\
.reduceByKey(add)\
.rightOuterJoin(r)\
.mapValues(lambda x: (x[0] or 0)*s + (1-s))
print("iteration = ", iteration)
# Collects all URL ranks and dump them to console after normalization
ranks = normalize(q.collect())
print(ranks[0:10])
if __name__ == "__main__":
spark = SparkSession\
.builder\
.master('local[*]')\
.appName("SparkPageRank")\
.config('spark.driver.allowMultipleContexts', 'true')\
.config('spark.sql.warehouse.dir', 'file:///C:/Home/Org/BigData/python/BE4/') \
.config('spark.sql.shuffle.partitions', '10')\
.getOrCreate()
spark.sparkContext.setLogLevel('WARN')
g = [(0, 1), (0, 5), (1, 2), (1, 3), (2, 3),
(2, 4), (2, 5), (3, 0), (5, 0), (5, 2)]
n = 6
edgeList = spark.sparkContext.parallelize(g)
print(timeit.timeit('pagerank_2(edgeList, 6, 10)', number=1, globals=globals()))
节点从0到n-1编号。 edgeList参数是一个RDD,其中包含节点对(也称为边)对的列表。
我在Windows 10(Anaconda,Spark 2.1.0,winutils)上以本地模式运行它。
这项工作是作为2896个任务分发的,这些任务都很轻。
我的问题是运行时间。
使用上面的示例:
- Windows 10:> 40百万!
- 适用于Linux的Windows子系统(Ubuntu 14.04):30s
- 该计算机是笔记本电脑核心i7-4702HQ,16 Gb ram,512 Gb SSD。
Windows的启动过程比Linux慢,但是慢50倍?当然有什么办法可以减少这种差距?
我已禁用所有受威胁文件的Windows Defender:java目录,python目录等。
关于看什么还有其他想法吗?
感谢您提供任何线索。
最佳答案
也许 key 是 local [*] ,这意味着
Run Spark locally with as many worker threads as logical cores on your machine.
尝试使用诸如本地[10]
-
screen基本用法-最牛程序员
-
python中glob文件路径查找-最牛程序员
-
PHP Glob()函数以示例匹配路径,目录,文件名-最牛程序员
-
Linux Basic - GLOB模式匹配-最牛程序员
-
树莓派建一个气象监测站-最牛程序员
-
Linux系统管理(四)——Shell编程资料分享以及示例演示-最牛程序员
-
树莓派日期时间校准-最牛程序员
-
c++ - Segmentation Fault(Core Dump)-代码在VS中有效,但在Linux Terminal中不可用-最牛程序员
-
linux - 获取计算机用户名-最牛程序员
-
Centos7 安装谷歌浏览器-最牛程序员
-
物联网温湿度显示控制项目(网页、Android双端显示&搭载linux平台网关&MQTT通信)-最牛程序员
-
c - 延时(Linux)(Windows)-最牛程序员
-
c# - Windows上的Mono(和常见问题)-最牛程序员
-
windows - Windows Perl->移植后Unix无法正常工作,可能是编码问题-最牛程序员
-
linux - 如何在包含文件的Linux上找到8.3命名文件-最牛程序员
-
linux - 使用批处理解决Linux通配符-最牛程序员
-
linux - PySpark速度Ubuntu vs Windows-最牛程序员
-
linux - Linux中是否有等效的CreateEvent,WaitForSingleObject和SetEvent?-最牛程序员
-
Kali与编程:Winserver2019上搭建wds网络部署服务器-最牛程序员
-
linux内核同步机制中的概念介绍和方法-最牛程序员