Python 在多进程下读 hdfs 文件会导致 cpu load 飙升

2018-11-28 18:01:51 +08:00
 fxxkgw

hdfs 集群通过 fuse_dfs 挂在本地使用

启动多进程,每个进程中读 hdfs 下一个普通文本文件,有一定概率导致 CPU 负载 100%,挂在的 hdfs hang 住,运行 df -h 等命令卡住。

t_file = "/hdfs/test.txt"
def func(msg): 
    print "msg:", msg 
    # 这步有一定概率 hang 住,导致 cpu 负载 100%,挂载的 hdfs 集群不可访问。
    with open(t_file, "r") as f: 
        print f.readlines() 
    print "end.., msg = ", msg


if __name__ == "__main__":
    pool = multiprocessing.Pool(processes = 7)
    for i in xrange(7):
        msg = "hello %d" %(i)
        pool.apply_async(func, (msg, ))

    pool.close()
    pool.join()
    print "done."
875 次点击
所在节点    程序员
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/512423

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX