I implement Apache Spark Scheduling Within like that (Scala code) :
// group into list of 10 items...
val maxSimultaneousSubmitAndMonitorThreadsInDriver = 10
// ... in order to throttle the number of threads submitting and monitoring apps at a time
val lists = myList grouped maxSimultaneousThreadsInDriver
for (aList <- lists) {
// pick a list, then convert it to Scala Parallel list
aList.par.foreach { // so 10 threads MAX at a time, that can handle job submission and monitoring
case (file_name) => {
// in each driver thread, create different Spark session
val sparkChild = sparkMain.newSession()
// then do specific stuff with such session
val childDF = sparkChild.read.parquet( filename + "_directory/*.parquet")
...
}
}
}
So as you know with the concept of Scheduling Within such single driver instance can monitor multiples Spark applications. so I can have multiples Spark applications that run simultaneously. (In my case Each Spark app, can then do very specific tasks per file read, based on the name, depending on business rules).
The scheduler is configured in FIFO mode per default :
By default, Spark’s scheduler runs jobs in FIFO fashion. Each job is divided into “stages” (e.g. map and reduce phases), and the first job gets priority on all available resources while its stages have tasks to launch, then the second job gets priority, etc. If the jobs at the head of the queue don’t need to use the whole cluster, later jobs can start to run right away [...]
Such solution works for me. However I found Spark Scheduling Within a bit slow. For instance, when I see the Spark UI Executors tab, I can see that most of the time, only few cores are used.
It's the opposite of classical Spark apps I have that naturally fully consume CPU almost all of the time !
So my final question, is how to optimize performance of Spark Scheduling Within ?
What I tried :
- changing the
maxSimultaneousSubmitAndMonitorThreadsInDriver, in order to throttle the number of threads that are submitting and monitoring an app at a given time - trying to increase
spark.scheduler.listenerbus.eventqueue.capacity - trying to increase / decrease
spark.default.parallelism - trying to increase / decrease
spark.sql.shuffle.partitions
If I increase the number of threads that can submit and monitor Spark apps simultaneously (with a throttle system), I end up with OOM.
Regarding spark.default.parallelism and spark.sql.shuffle.partitions, I don't know how to choose a relevant value. If I do NOT Scheduling Within (with only one application per driver) the value I set would probably be 192 (the number of cores) to have good results.
But with Scheduling Within it's unclear. Each submitted job is small, and parallelism 192 for each job seems overkill (and slow ?)..
Any input would be greatly appreciated
