neo4j 如何限制Spark使用或创建的线程数量?(数据砖)

33qvvth1  于 12个月前  发布在  Spark
关注(0)|答案(2)|浏览(90)

目前,我使用spark将数据写入neo4j,当开始写入时,会创建200个线程同时写入neo4j。有没有一种方法可以限制同时创建和使用的线程数量,或者是减少集群和示例大小的唯一方法?我知道这违背了Spark的本意,但我很想得到任何反馈。
我试过spark.conf.set("spark.executor.cores", 4)
没有运气。

edges.write.format("org.neo4j.spark.DataSource")\
.option("url", "neo4j://url:7687") \
.mode("overwrite")\
.option("relationship", "connected")\
.option("batch.size",1000)\
.option("relationship.save.strategy", "keys")\
.option("relationship.source.node.keys", "id:id")\
.option("relationship.target.node.keys", "id:id")\
.option("relationship.source.labels", "node")\
.option("relationship.target.labels", "node")\
.save()
voase2hg

voase2hg1#

尝试在写之前重新分区你的框架:

edges.repartition(parallelism)
...
.option("url", "neo4j://url:7687") \
.mode("overwrite")\
...

其中parallelism是将并发写入的任务数。

lb3vh1jj

lb3vh1jj2#

常见的解决方案是coalesce(类似于repartition,但效率更高,因为它不需要 Shuffle )。例如:

edges.coalesce(4).write...

这种解决方案的一个问题是,它假设edges/4适合执行器的内存。如果是这样,那就太好了;如果没有,我不认为有一种方法来限制作家的数量,除了通过减少集群。

相关问题