Spark on Hadoop works on concept of data locality, such that code is tried to send to data rather then shuffling data to code.
We specify following resources when creating a Spark Job -
- executor cores
- executor memory
- driver cores
- driver memory
- number of executors
Data is distributed on HDFS in blocks, and an input split kind of determine size of a data partition. YARN tries to collocate executors as close to data as possible to minimize network transfer of data.
A task is a command sent from the driver to an executor by serializing your Function object. The executor deserializes the command, and executes it on a partition.
The number of the Spark tasks in a single stage equals to the number of RDD partitions.
- Now, "executor cores" or "spark.executor.cores" determines number of tasks that can be executed concurrently on an executor.
- What is a task ? As explained above, task is a function that needs to be executed on a partition of data. What function? function as defined by map(), flatMap(), forEach(), etc.
Now, one may further use ThreadPools or Streams within a task to do quick computation/ processing. In this scenario, we can configure "spark.task.cpus" to determine number of cores to allocate to each task. Make sure to use Java Concurrent API and proper Synchronization to avoid misleading results. That's how one can achieve Multi-Threading within a task.
A command-line utility “lscpu” in Linux is used to get CPU information of the system. The “lscpu” command fetches the CPU architecture information from the “sysfs” and /proc/cpuinfo files and displays it in a terminal. What matters to you is -
Thread(s) per core (t)
Core(s) per socket (c)
Socket (s)
Number of Cores = s*c
So, say if you have configuration like below -
Thread(s) per core: 2
Core(s) per socket: 12
Socket(s): 4
And, you want
Multi-Threading by 4 threads. Then set "spark.task.cpus=2", as each CPU can have 2 threads, meaning 2*2 = 4 threads.
Comments
Post a Comment