In Spark, custom Partitioner
s can be supplied for RDD's. Normally, the produced partitions are randomly distributed to set of workers. For example if we have 20 partitions and 4 workers, each worker will (approximately) get 5 partitions. However the placement of partitions to workers (nodes) seems random like in the table below.
trial 1 trial 2
worker 1: [10-14] [15-19]
worker 2: [5-9] [5-9]
worker 3: [0-4] [10-14]
worker 4: [15-19] [0-4]
This is fine for operations on a single RDD, but when you are using join()
or cogroup()
operations that span multiple RDD's, the communication between those nodes becomes a bottleneck. I would use the same partitioner for multiple RDDs and want to be sure they will end up on the same node so the subsequent join() would not be costly. Is it possible to control the placement of partitions to workers (nodes)?
desired
worker 1: [0-4]
worker 2: [5-9]
worker 3: [10-14]
worker 4: [15-19]