执行时间随着核心数量的增加而增加(Pyspark)

时间:2019-06-06 15:04:26

标签: apache-spark pyspark jupyter

我是火花新手,正在尝试Jupyter笔记本上的基本命令。我正在使用8核(8 GB RAM)笔记本电脑。我想在同一命令上使用更多线程时看到执行速度加快,但是当我运行它时,随着线程数量的增加,速度似乎正在降低。关于我可能做错了什么,我可以提供一些意见吗?

下面提供了代码和相关显示。任何方向都会很棒!

from time import time
for j in range(1,10):
    sc = SparkContext(master="local[%d]"%(j))
    t0 = time()
    sc.parallelize([1,2]*100000).reduce(lambda x,y:x+y)
    print("{} thread/s, time {}s".format(j,time()-t0))
    sc.stop()

显示如下。

    1 thread/s, time 1.2712764739990234s
    2 thread/s, time 2.33809232711792s
    3 thread/s, time 4.1362903118133545s
    4 thread/s, time 4.493982791900635s
    5 thread/s, time 5.679643154144287s
    6 thread/s, time 7.150028228759766s
    7 thread/s, time 7.83972954750061s
    8 thread/s, time 8.8699471950531s
    9 thread/s, time 10.216657876968384s

0 个答案:

没有答案
相关问题