关注 spark技术分享,
撸spark源码 玩spark最佳实践

Spark on Mesos

Spark on Mesos

spark mesos.png
Figure 1. Spark on Mesos Architecture

Running Spark on Mesos

A Mesos cluster needs at least one Mesos Master to coordinate and dispatch tasks onto Mesos Slaves.

Visit the management console at http://localhost:5050.

mesos console.png
Figure 2. Mesos Management Console

Run Mesos Slave onto which Master will dispatch jobs.

Switch to the management console at http://localhost:5050/#/slaves to see the slaves available.

mesos console slaves.png
Figure 3. Mesos Management Console (Slaves tab) with one slave running
Important

You have to export MESOS_NATIVE_JAVA_LIBRARY environment variable before connecting to the Mesos cluster.

Note

The preferred approach to launch Spark on Mesos and to give the location of Spark binaries is through spark.executor.uri setting.

For us, on a bleeding edge of Spark development, it is very convenient to use spark.mesos.executor.home setting, instead.

In Frameworks tab you should see a single active framework for spark-shell.

spark mesos frameworks one active.png
Figure 4. Mesos Management Console (Frameworks tab) with Spark shell active
Tip
Consult slave logs under /tmp/mesos/slaves when facing troubles.
Important
Ensure that the versions of Spark of spark-shell and as pointed out by spark.executor.uri are the same or compatible.

spark mesos completed tasks.png
Figure 5. Completed tasks in Mesos Management Console

Stop Spark shell.

CoarseMesosSchedulerBackend

CoarseMesosSchedulerBackend is the scheduler backend for Spark on Mesos.

It requires a Task Scheduler, Spark context, mesos:// master URL, and Security Manager.

It is a specialized CoarseGrainedSchedulerBackend and implements Mesos’s org.apache.mesos.Scheduler interface.

It accepts only two failures before blacklisting a Mesos slave (it is hardcoded and not configurable).

It tracks:

  • the number of tasks already submitted (nextMesosTaskId)

  • the number of cores per task (coresByTaskId)

  • the total number of cores acquired (totalCoresAcquired)

  • slave ids with executors (slaveIdsWithExecutors)

  • slave ids per host (slaveIdToHost)

  • task ids per slave (taskIdToSlaveId)

  • How many times tasks on each slave failed (failuresBySlaveId)

Tip
createSchedulerDriver instantiates Mesos’s org.apache.mesos.MesosSchedulerDriver

CoarseMesosSchedulerBackend starts the MesosSchedulerUtils-mesos-driver daemon thread with Mesos’s org.apache.mesos.MesosSchedulerDriver.

Settings

  • spark.cores.max (default: Int.MaxValue) – maximum number of cores to acquire

  • spark.mesos.extra.cores (default: 0) – extra cores per slave (extraCoresPerSlave) FIXME

  • spark.mesos.constraints (default: (empty)) – offer constraints FIXME slaveOfferConstraints

  • spark.mesos.rejectOfferDurationForUnmetConstraints (default: 120s) – reject offers with mismatched constraints in seconds

  • spark.mesos.executor.home (default: SPARK_HOME) – the home directory of Spark for executors. It is only required when no spark.executor.uri is set.

MesosExternalShuffleClient

(Fine)MesosSchedulerBackend

When spark.mesos.coarse is false, Spark on Mesos uses MesosSchedulerBackend

reviveOffers

It calls mesosDriver.reviveOffers().

Caution
FIXME

Settings

  • spark.mesos.coarse (default: true) controls whether the scheduler backend for Mesos works in coarse- (CoarseMesosSchedulerBackend) or fine-grained mode (MesosSchedulerBackend).

Caution

FIXME Review

Schedulers in Mesos

Available scheduler modes:

  • fine-grained mode

  • coarse-grained modespark.mesos.coarse=true

The main difference between these two scheduler modes is the number of tasks per Spark executor per single Mesos executor. In fine-grained mode, there is a single task in a single Spark executor that shares a single Mesos executor with the other Spark executors. In coarse-grained mode, there is a single Spark executor per Mesos executor with many Spark tasks.

Coarse-grained mode pre-starts all the executor backends, e.g. Executor Backends, so it has the least overhead comparing to fine-grain mode. Since the executors are up before tasks get launched, it is better for interactive sessions. It also means that the resources are locked up in a task.

Spark on Mesos supports dynamic allocation in the Mesos coarse-grained scheduler since Spark 1.5. It can add/remove executors based on load, i.e. kills idle executors and adds executors when tasks queue up. It needs an external shuffle service on each node.

Mesos Fine-Grained Mode offers a better resource utilization. It has a slower startup for tasks and hence it is fine for batch and relatively static streaming.

Commands

The following command is how you could execute a Spark application on Mesos:

Other Findings

Spark workloads can also be sensitive to the physical characteristics of the infrastructure, such as memory size of the node, access to fast solid state disk, or proximity to the data source.

to run Spark workloads well you need a resource manager that not only can handle the rapid swings in load inherent in analytics processing, but one that can do to smartly. Matching of the task to the RIGHT resources is crucial and awareness of the physical environment is a must. Mesos is designed to manage this problem on behalf of workloads like Spark.

赞(0) 打赏
未经允许不得转载:spark技术分享 » Spark on Mesos
分享到: 更多 (0)

关注公众号:spark技术分享

联系我们联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏