<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: JY @ DataMechanics</title>
    <description>The latest articles on DEV Community by JY @ DataMechanics (@jystephan).</description>
    <link>https://dev.to/jystephan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F383959%2F32eeb0a8-d58a-4190-921d-890a1f36011b.jpg</url>
      <title>DEV Community: JY @ DataMechanics</title>
      <link>https://dev.to/jystephan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jystephan"/>
    <language>en</language>
    <item>
      <title>The New &amp; Improved Spark UI &amp; Spark History Server is now Generally Available</title>
      <dc:creator>JY @ DataMechanics</dc:creator>
      <pubDate>Fri, 07 May 2021 10:56:18 +0000</pubDate>
      <link>https://dev.to/jystephan/the-new-improved-spark-ui-spark-history-server-is-now-generally-available-4j71</link>
      <guid>https://dev.to/jystephan/the-new-improved-spark-ui-spark-history-server-is-now-generally-available-4j71</guid>
      <description>&lt;p&gt;Delight is a free, hosted, cross-platform monitoring dashboard for Apache Spark with memory and CPU metrics that will hopefully delight you!&lt;/p&gt;

&lt;p&gt;A year ago, we released a widely shared blog post: &lt;a href="https://www.datamechanics.co/blog-post/building-a-better-spark-ui-data-mechanics-delight"&gt;We’re building a better Spark UI&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;After a lot of engineering work, we’re proud to finally release &lt;a href="https://www.datamechanics.co/delight"&gt;Delight&lt;/a&gt;, our free, hosted, cross-platform monitoring dashboard for &lt;a href="https://www.datamechanics.co/apache-spark"&gt;Apache Spark&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It works on top of Databricks, EMR, Dataproc, HDInsight, HDP/CDP, and open-source platforms too (anything spark-submit, or using the spark-on-kubernetes operator, or using Apache Livy).&lt;/p&gt;

&lt;p&gt;Delight helps you understand and improve the performance of your Spark applications. It provides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Spark-centric CPU &amp;amp; memory metrics that we hope will delight you!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Spark UI — so you don’t need to run the Spark History Server yourself.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What we’ll cover in this article:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The motivation and timeline of the project&lt;/li&gt;
&lt;li&gt;Its high-level architecture&lt;/li&gt;
&lt;li&gt;A tour of the main screens and how they can help you in your day-to-day work&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Our vision and motivations for Delight
&lt;/h2&gt;

&lt;p&gt;It’s difficult to troubleshoot the performance of an application for the Spark UI. There’s useful information in the UI, but it’s buried under a lot of noise, and there’s a lot of tribal knowledge involved in understanding it. Moreover, the Spark UI does not show critical system metrics such as CPU Usage, Memory Usage, and I/O.&lt;/p&gt;

&lt;p&gt;For this, you have to use a general purpose observability tool (such as Ganglia). The problem with these tools is that they were not built for Spark. You’ll need to jump between metrics for each node, to try to get a rough estimate in your head, and then look at the timestamps to jump back and forth between them and the Spark UI.&lt;/p&gt;

&lt;p&gt;Our mission at &lt;a href="https://www.datamechanics.co"&gt;Data Mechanics&lt;/a&gt; is to make Apache Spark much more developer-friendly and cost-effective. This is why we built our managed &lt;a href="https://www.datamechanics.co/apache-spark-on-kubernetes"&gt;Spark-on-Kubernetes&lt;/a&gt; platform (available on AWS, GCP, and Azure), which automates the infrastructure parameters and Spark configurations to make our customers pipelines stable and performant.&lt;/p&gt;

&lt;p&gt;We also wanted to simplify the developer experience of data scientists and engineers, and the observability layer is a critical piece of this puzzle. We want to make it easy for anyone to understand the performance of their Spark code.&lt;/p&gt;

&lt;p&gt;This is why we set out to build Delight, an open-source monitoring dashboard for Spark. In June 2020, we shared &lt;a href="https://www.datamechanics.co/blog-post/building-a-better-spark-ui-data-mechanics-delight"&gt;our vision for Delight in a widely shared blog post&lt;/a&gt; featuring the GIF below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cAZCTttP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2AQs2SXH0uhNaQIwmv.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cAZCTttP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2AQs2SXH0uhNaQIwmv.gif" alt="Our Delight design prototype, published in June 2020. Image by Author."&gt;&lt;/a&gt;&lt;em&gt;Our Delight design prototype, published in June 2020. Image by Author.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Encouraged by hundreds of sign-ups and comments on our announcement, we set out to build Delight, which turned out to be a large-scale engineering effort.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In November 2020, we released an MVP consisting of a hosted dashboard giving you access to the Spark UI for your terminated applications (avoiding you the trouble to run and maintain your own Spark History Server).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In Q1 2021, we released Delight internally to our customers, and iterated on the feedback they gave, fixing many bugs and stability issues as we uncovered them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Today there still remains a lot of work to achieve our final vision. But Delight has already proven valuable to many, and so we’re excited to open it up to the Spark community!&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Architecture: Open-Source Agent + Hosted Backend
&lt;/h2&gt;

&lt;p&gt;Delight works for free on top of any Spark platform, including Databricks, Amazon EMR, Google Dataproc, or an open-source Spark-on-Kubernetes or Spark-on-YARN setup. It is compatible with running Spark applications using spark-submit, Apache Livy, or the Spark-on-Kubernetes operator.&lt;/p&gt;

&lt;p&gt;Delight consists of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;An &lt;a href="https://github.com/datamechanics/delight"&gt;open-sourced agent&lt;/a&gt; running inside your Spark applications, streaming Spark event metrics to the Delight backend.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A hosted backend responsible for collecting these metrics, parsing them, and hosting the dashboard at &lt;a href="https://delight.datamechanics.co/"&gt;https://delight.datamechanics.co&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fKSNuBOC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3200/0%2AZhf6ZndZUeNEo8I5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fKSNuBOC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3200/0%2AZhf6ZndZUeNEo8I5.png" alt="High-level architecture: an open-source agent &amp;amp; a hosted backend. Image by Author."&gt;&lt;/a&gt;&lt;em&gt;High-level architecture: an open-source agent &amp;amp; a hosted backend. Image by Author.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The metrics collected by Delight contain low-level metadata about your Spark application execution, like how much data is read/written by each task, how much memory &amp;amp; cpu is used. These metrics are called Spark event logs ( &lt;a href="https://github.com/datamechanics/delight/blob/main/documentation/resources/example_spark_event_log.txt"&gt;view an example&lt;/a&gt;), and they’re the same information that lets the Spark History Server play back the Spark UI of completed applications.&lt;/p&gt;

&lt;p&gt;These metrics are protected using a secret access token you can generate in our dashboard, which uniquely identifies you. They are not shared with any third party, and they are automatically deleted from our servers after 30 days. An additional limit of 1,000 applications stored per organization applies (if you run more than 1,000 applications within 30 days, we’ll start deleting the oldest ones).&lt;/p&gt;

&lt;h2&gt;
  
  
  Taking a tour of the main screens
&lt;/h2&gt;

&lt;h2&gt;
  
  
  1. The Main Dashboard
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NmD6_uOC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3200/0%2AJV-CkRDKsR_mlHL-.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NmD6_uOC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3200/0%2AJV-CkRDKsR_mlHL-.png" alt="The main dashboard of Delight lists all your recently completed Spark applications. Image by Author."&gt;&lt;/a&gt;&lt;em&gt;The main dashboard of Delight lists all your recently completed Spark applications. Image by Author.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;‍When you log in to Delight, you see this table of the most recent Spark applications you ran. Note that live applications are not visible yet, they only appear a couple of minutes after their completion. Most of the information in this screen should be self-explanatory, except 3 columns: Spark tasks, CPU, and Efficiency. Before explaining them, here’s a quick reminder of how Spark distributed execution works.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;In a Spark **application&lt;/em&gt;&lt;em&gt;, you have a single **driver&lt;/em&gt;* process (the “brain” of your application), and many &lt;strong&gt;executor&lt;/strong&gt; processes. The driver is responsible for understanding your code and splitting it into &lt;strong&gt;jobs&lt;/strong&gt;, &lt;strong&gt;stages&lt;/strong&gt; and &lt;strong&gt;tasks&lt;/strong&gt;. A stage is a set of tasks which can be executed in parallel on your executors. One executor core can run (at most) one Spark task at a time ; in other words, a Spark executor with 4 CPUs can run up to 4 tasks in parallel.*&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let’s now define three columns:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Spark Tasks&lt;/strong&gt;. This is the sum of the duration of all the tasks in your application. &lt;em&gt;Side-note: This is the metric that the Data Mechanics platform &lt;a href="https://www.datamechanics.co/pricing"&gt;pricing&lt;/a&gt; is based on.&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;CPU&lt;/strong&gt;. This is the sum of the lifetime duration of your Spark executors, multiplied by how many cores are allocated to each executors. In other words, this is your “Executor Cores uptime”. This metric is generally proportional to your infrastructure costs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Efficiency&lt;/strong&gt;. This is the ratio Spark Tasks divided by CPU, expressed as a percentage. This represents the fraction of the time that your CPU resources are effectively used to run Spark tasks. 100% is ideal (perfect parallelism), 0% means your compute resources are wasted (you have containers running, but they’re idle).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is one of the key metric we look at at Data Mechanics, as our platform has automation features (autoscaling, autotuning, …) to increase our customers efficiency, and therefore reduce their cloud costs (check this &lt;a href="https://www.datamechanics.co/blog-post/migrating-from-emr-to-spark-on-kubernetes-with-data-mechanics"&gt;story of a customer who migrated away from &lt;/a&gt;EMR to learn more about this).&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Executor Cores Usage
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;‍&lt;/strong&gt;Once you click on a specific application, you get to an app overview page with high-level statistics and a link to the Spark UI at the top. The next information you will find is the executor cores usage graph.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nF0MKxIv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3200/0%2AyQRCXpWAJlzJec6A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nF0MKxIv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3200/0%2AyQRCXpWAJlzJec6A.png" alt="The executor cores usage graph gives a high-level view of your application’s performance. Image by Author."&gt;&lt;/a&gt;&lt;em&gt;The executor cores usage graph gives a high-level view of your application’s performance. Image by Author.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The executor cores usage graph aggregates low-level CPU metrics measured by Spark during your application execution, into a simple visual overview. You first get a summary of your executor cores usage, broken down by the main categories (click the ℹ️ icon to read their definitions):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;CPU&lt;/strong&gt; — Time spent actually computing the Spark task.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;I/O&lt;/strong&gt; — Time spent waiting for data to be read or written (usually from network). &lt;em&gt;Note: Spark currently treats work done in a Python process as I/O (from the JVM point of view, this is I/O waiting for python to provide data). This happens for example when you execute python User-Defined Functions. Check this &lt;a href="https://stackoverflow.com/questions/61816236/does-pyspark-code-run-in-jvm-or-python-subprocess"&gt;StackOverflow post&lt;/a&gt; to better understand how the JVM and Python work together in PySpark.&lt;/em&gt;&lt;strong&gt;‍&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Shuffle&lt;/strong&gt; — Time spent waiting for data blocks to be written or fetched during shuffle (data exchange phases across your Spark executors).&lt;strong&gt;‍&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Garbage Collection&lt;/strong&gt; — Time spent doing by the JVM doing GC. For most (healthy) applications, this shouldn’t be more than a few percentage points.&lt;strong&gt;‍&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Spark Internals&lt;/strong&gt; — Time spent by Spark on overhead operations such as scheduler delay, task serialization and deserialization. Again, this should be small for most apps.&lt;strong&gt;‍&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;*&lt;em&gt;Some Cores Idle *&lt;/em&gt;— Time during which tasks are executed, but only on a portion of your executor cores. A high value there is the sign of imperfect parallelism.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;All Cores Idle&lt;/strong&gt; — Time during which no Spark tasks are running. This could be full idleness, which happens often e.g. when you use Spark in an interactive way, then take a break. Or this could mean that some non-Spark work is happening, for example you may be executing pure Python or Scala code on the driver, so all the executors are idle.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This information is then visible on a graph where the X-Axis is the timeline of your app, the Y-axis is the number of executor cores you have (which may vary over time if you enable dynamic allocation). Under this graph, you can see a timeline of your Spark jobs and stages.&lt;/p&gt;

&lt;p&gt;The main benefit of this graph is that you can very quickly focus your attention on the main performance bottleneck of your application. In this example, it’s clear that &lt;strong&gt;job-1/stage-1&lt;/strong&gt; take up most of the application time. The large gray area indicates that most of the cores are idle during this time. If you click on “stage-1”, you will be taken to the Spark UI, so you can troubleshoot this further (in this example, the problem is that the stage only has 2 tasks).&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Executors Peak Memory Usage
&lt;/h2&gt;

&lt;p&gt;This graph is only visible if you use Spark 3.0 or later, as it depends on new capabilities introduced in Spark 3.0 ( &lt;a href="https://issues.apache.org/jira/browse/SPARK-23429"&gt;SPARK-23429&lt;/a&gt; and &lt;a href="https://issues.apache.org/jira/browse/SPARK-27189"&gt;SPARK-27189&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--01RVbint--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3200/0%2A6xXkHhdE7mFom5y1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--01RVbint--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3200/0%2A6xXkHhdE7mFom5y1.png" alt="The executors peak memory usage graphs shops the memory usage breakdown of your Spark executors, at the time they reached their maximum memory usage. Image by Author."&gt;&lt;/a&gt;&lt;em&gt;The executors peak memory usage graphs shops the memory usage breakdown of your Spark executors, at the time they reached their maximum memory usage. Image by Author.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;‍While your app is running, Spark measures the memory usage of each executor. This graph reports the peak memory usage observed for your top 5 executors, broken down between different categories:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Memory used by the &lt;strong&gt;JVM&lt;/strong&gt; (this is your maximum heap size)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Memory used by &lt;strong&gt;Python&lt;/strong&gt; processes (if you’re using PySpark)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Memory used by &lt;strong&gt;other&lt;/strong&gt; processes (if you’re using R, then R is currently listed as “Others”)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This graph should be particularly useful to PySpark users, who currently have no simple way of knowing how much memory their python processes consume. This graph could help you decide whether it’s safe to use a different type of instance / size of container than you currently use. It could also warn you that you are flirting with the maximum allowed memory usage. As a reminder, if your Python processes use too much memory, then your resource manager will kill your Spark executor (for example on Kubernetes, you will get the docker exit code 137).&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion: Try it out, and let us know your feedback!
&lt;/h2&gt;

&lt;p&gt;We hope Delight will be true to its word and help you have a delightful developer experience with Spark.&lt;/p&gt;

&lt;p&gt;We encourage you to try it out! &lt;a href="https://www.datamechanics.co/delight"&gt;Sign up&lt;/a&gt;, follow the installation instructions &lt;a href="https://github.com/datamechanics/delight"&gt;on our github page&lt;/a&gt;, and let us know your feedback over email (by replying to the welcome email) or using the live chat window in the product.&lt;/p&gt;

&lt;p&gt;We have ambitious plans for Delight. Our future roadmap includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A page for each executor, and for the driver, to track their memory usage over time, with more detailed breakdown (Offheap memory usage)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Automated performance tuning recommendations (e.g. alerts on data skew / inefficient data partitioning, …)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Making Delight accessible in real-time while the app is running&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And much more based on your feedback: let us know what’s your priority!&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We will soon be publishing follow-up articles with concrete troubleshooting steps and Spark performance tuning sessions using Delight. We will also be giving meetups and conferences about it, including at the upcoming &lt;a href="https://databricks.com/session_na21/delight-a-free-and-cross-platform-apache-spark-ui-complement"&gt;Data + AI Summit&lt;/a&gt;). So stay tuned, and thank you for your support!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://www.datamechanics.co/blog-post/delight-the-new-improved-spark-ui-spark-history-server-is-now-ga"&gt;https://www.datamechanics.co&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>apachespark</category>
      <category>sparkui</category>
      <category>bigdata</category>
      <category>monitoring</category>
    </item>
    <item>
      <title>Spark on Kubernetes Made Easy - How Data Mechanics Improves on the Open-Source version</title>
      <dc:creator>JY @ DataMechanics</dc:creator>
      <pubDate>Wed, 09 Dec 2020 15:40:27 +0000</pubDate>
      <link>https://dev.to/jystephan/spark-on-kubernetes-made-easy-how-data-mechanics-improves-on-the-open-source-version-52fj</link>
      <guid>https://dev.to/jystephan/spark-on-kubernetes-made-easy-how-data-mechanics-improves-on-the-open-source-version-52fj</guid>
      <description>&lt;p&gt;&lt;em&gt;If you’re looking for a high-level introduction about &lt;a href="https://www.datamechanics.co/apache-spark-on-kubernetes"&gt;Spark on Kubernetes&lt;/a&gt;, check out &lt;a href="https://www.datamechanics.co/blog-post/pros-and-cons-of-running-apache-spark-on-kubernetes"&gt;The Pros And Cons of Running Spark on Kubernetes&lt;/a&gt;, and if you’re looking for a deeper technical dive, then read our guide &lt;a href="https://www.datamechanics.co/blog-post/setting-up-managing-monitoring-spark-on-kubernetes"&gt;Setting Up, Managing &amp;amp; Monitoring Spark on Kubernetes&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Data Mechanics is a managed &lt;a href="https://www.datamechanics.co/apache-spark"&gt;Spark&lt;/a&gt; platform deployed on a Kubernetes cluster inside our customers’ cloud account, available on AWS, GCP, and Azure. So our entire company is built on top of Spark on Kubernetes, and we are often asked &lt;strong&gt;how we’re different from simply running Spark on Kubernetes open-source&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The short answer is that our platform implements many features which make &lt;a href="https://www.datamechanics.co/apache-spark-on-kubernetes"&gt;Spark on Kubernetes&lt;/a&gt; much more easy-to-use and cost-effective. By taking care of the setup and the maintenance, our goal is to accelerate your data engineering projects by making &lt;a href="https://www.datamechanics.co/apache-spark"&gt;Spark&lt;/a&gt; as simple, flexible and performant as it should be.&lt;/p&gt;

&lt;p&gt;Let’s go over our main improvements on top of Spark-on-Kubernetes.&lt;/p&gt;

&lt;h2&gt;
  
  
  An intuitive user interface
&lt;/h2&gt;

&lt;p&gt;Data Mechanics users get a dashboard where they can view the logs and metrics for each of their Spark applications. They can also access the Spark UI, soon-to-be replaced with our homegrown monitoring tool called &lt;a href="https://www.datamechanics.co/delight"&gt;Data Mechanics Delight&lt;/a&gt; (Update, December 2020: First &lt;a href="https://www.datamechanics.co/blog-post/were-releasing-a-free-cross-platform-spark-ui-and-spark-history-server"&gt;milestone&lt;/a&gt; of delight has been released!). The goal of this project is to make it easy for Spark developers to troubleshoot their application when there’s a failure, and to give them high-level recommendations to increase its performance when necessary (for example around data partitioning and memory management).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GXHZG11U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3680/0%2AGFtfwNigL3lofoAQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GXHZG11U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3680/0%2AGFtfwNigL3lofoAQ.png" alt="[Data Mechanics Delight](https://www.datamechanics.co/delight)"&gt;&lt;/a&gt;&lt;em&gt;&lt;a href="https://www.datamechanics.co/delight"&gt;Data Mechanics Delight&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;They also have access to a “Jobs UI” which gives a historical graph of your pipelines main metrics like the volume of data processed, the duration, and the costs. So that your team can easily make sure that your production pipelines are running as expected, as well as to track your costs when necessary.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xZvY49Zv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3840/0%2AhCDwfBh1KRYpFmb-.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xZvY49Zv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3840/0%2AhCDwfBh1KRYpFmb-.png" alt="Data Mechanics Jobs UI"&gt;&lt;/a&gt;&lt;em&gt;Data Mechanics Jobs UI&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Dynamic optimizations
&lt;/h2&gt;

&lt;p&gt;The Data Mechanics platform automatically and dynamically optimises your pipelines infrastructure parameters and Spark configurations to make them fast and stable. Here are the settings that we tune: your pod’s memory and cpu allocations, your disk settings, and your Spark configurations around parallelism, shuffle, and memory management. We do this by analysing the logs and metrics of your applications, and using the history of the past runs of your applications to find out its bottleneck and optimise it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6n3To91h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3840/0%2Aj0_l4EUU3bUebOkD.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6n3To91h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3840/0%2Aj0_l4EUU3bUebOkD.png" alt="Data Mechanics’ Auto Tuning Feature"&gt;&lt;/a&gt;&lt;em&gt;Data Mechanics’ Auto Tuning Feature&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In addition to automated tuning, our platform also implements automated scaling at the level of your Spark application (dynamic allocation) and at the level of the Kubernetes cluster. This means we manage the Kubernetes node pools to scale up the cluster when you need more resources, and scale them down to zero when they’re unnecessary. We also make it easy to use spot nodes for your Spark executors to reduce your cloud costs further.&lt;strong&gt;‍&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4TtTx6sN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3840/0%2AQrAA3vVD3X6sLdWc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4TtTx6sN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3840/0%2AQrAA3vVD3X6sLdWc.png" alt="Data Mechanics’ Autoscaling Feature"&gt;&lt;/a&gt;&lt;em&gt;Data Mechanics’ Autoscaling Feature&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;‍&lt;/strong&gt;Last but not least, we offer a list of Spark images which contain optimised connectors to common data sources and sinks. You can either use these images directly, or use them as a base to &lt;a href="https://www.datamechanics.co/blog-post/spark-and-docker-your-spark-development-cycle-just-got-ten-times-faster"&gt;build your own Docker Images&lt;/a&gt; with your custom dependencies.&lt;/p&gt;

&lt;p&gt;The goal of these optimizations is to give you the maximum performance Spark should provide and to reduce your cloud costs. In fact, the &lt;a href="https://www.datamechanics.co/pricing"&gt;management fee&lt;/a&gt; that we charge for our services is more than compensated by the savings we generate on your cloud provider bill. We’ve helped customers migrating from competing Spark platforms reduce their cloud bill by 50 to 75%.&lt;/p&gt;

&lt;h2&gt;
  
  
  Integrations
&lt;/h2&gt;

&lt;p&gt;Data Mechanics has integrations with notebooks services (like &lt;a href="https://docs.datamechanics.co/docs/jupyter-notebooks"&gt;Jupyter&lt;/a&gt;, JupyterLab, JupyterHub) and scheduler/workflows services (like &lt;a href="https://docs.datamechanics.co/docs/airflow-plugin"&gt;Airflow&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Since our platform is deployed on a Kubernetes cluster that you have control over, the full ecosystem of Docker/Kubernetes compatible tools is also available to you. And since we’re deployed inside your cloud account, inside your VPC, you can also easily build your own integrations with your home-grown tools inside your company’s network.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ndpLOrYH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3840/0%2A99VhGQ3rgS-W9tO8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ndpLOrYH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3840/0%2A99VhGQ3rgS-W9tO8.png" alt="Data Mechanics’ Native Integrations With Jupyter, Docker, Kubernetes, Airflow"&gt;&lt;/a&gt;&lt;em&gt;Data Mechanics’ Native Integrations With Jupyter, Docker, Kubernetes, Airflow&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The peace of mind of a managed service
&lt;/h2&gt;

&lt;p&gt;As a managed service, we take care of the setup and the maintenance of your infrastructure. When you sign up for Data Mechanics, you give us scoped permission on your cloud account, and we use these permissions to create the Kubernetes cluster, keep it up-to-date with the latest security fixes, and push releases with new features every two weeks.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MMd1L411--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3840/0%2A96hH_gK9UVC6poNm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MMd1L411--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3840/0%2A96hH_gK9UVC6poNm.png" alt="The Data Mechanics Platform Architecture"&gt;&lt;/a&gt;&lt;em&gt;The Data Mechanics Platform Architecture&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It’s also our responsibility to keep your deployment secure. We can deploy within your company’s VPC and make your cluster private, so that it can only be accessed through your company’s VPN. We give you the tools to apply the security best practices with multiple options for data access and for user authentication (Single Sign On).&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We’re proud to build on top, and sometimes contribute to, &lt;a href="https://www.datamechanics.co/apache-spark-on-kubernetes"&gt;Spark-on-Kubernetes&lt;/a&gt; as well as other open source projects. We’re trying to build the data platform you would build for yourself — in an open and transparent way. By being deployed in your cloud account and in your VPC, you get the flexibility of a home-grown project, and the ease-of-use of a managed platform.&lt;/p&gt;

&lt;p&gt;The optimizations we built internally will more than make up for our &lt;a href="https://www.datamechanics.co/pricing"&gt;pricing&lt;/a&gt;, in fact we’ve helped some of our customers reduce their total costs by 50 to 75% as they migrated from competing platforms.&lt;/p&gt;

&lt;p&gt;If this sounds interesting, &lt;a href="https://calendly.com/datamechanics/demo"&gt;book a time&lt;/a&gt; with our team. We’ll be happy to answer your questions and show you how to get started!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://www.datamechanics.co/blog-post/spark-on-kubernetes-made-easy-how-data-mechanics-improves-on-spark-on-k8s-open-source"&gt;https://www.datamechanics.co&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>bigdata</category>
      <category>kubernetes</category>
      <category>datascience</category>
    </item>
    <item>
      <title>How to Use our Free Open-Source Spark UI &amp; Spark History Server + Spark Dashboard</title>
      <dc:creator>JY @ DataMechanics</dc:creator>
      <pubDate>Wed, 09 Dec 2020 13:31:08 +0000</pubDate>
      <link>https://dev.to/jystephan/how-to-use-our-free-open-source-spark-ui-spark-history-server-spark-dashboard-8fj</link>
      <guid>https://dev.to/jystephan/how-to-use-our-free-open-source-spark-ui-spark-history-server-spark-dashboard-8fj</guid>
      <description>&lt;p&gt;Accessing the Spark UI for live Spark applications is easy, but having access to it for terminated applications requires persisting logs to a cloud storage and running a server called the Spark History Server. While some commercial Spark platform provides this automatically (e.g. Databricks, EMR) ; for many Spark users (e.g. on Dataproc, Spark-on-Kubernetes) getting this requires a bit of work.&lt;/p&gt;

&lt;p&gt;Today, we’re releasing a free, hosted, partly &lt;a href="https://github.com/datamechanics/delight"&gt;open sourced&lt;/a&gt;, Spark UI and Spark History Server that work on top of any Spark platform (whether it’s on-premise or in the cloud, over Kubernetes or over YARN, using a commercial platform or not).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gWu48QvY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/5200/0%2A5ZFpi4bkjHkXl6Jo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gWu48QvY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/5200/0%2A5ZFpi4bkjHkXl6Jo.png" alt="Spark UI Screenshot. Image by Author."&gt;&lt;/a&gt;&lt;em&gt;Spark UI Screenshot. Image by Author.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It consists of a dashboard listing your Spark applications, and a hosted Spark History Server that will give you access to the Spark UI for your recently finished applications at the click of a button.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Can I Use it?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Create an account on &lt;a href="https://www.datamechanics.co/delight"&gt;Data Mechanics Delight&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You should use your company’s Google account if you want to share a single dashboard with your colleagues, or your personal Google account if you want the dashboard to be private to you.&lt;/p&gt;

&lt;p&gt;Once your account is created, go under Settings and create a personal access token. This will be needed in the next step.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Attach our open-source agent to your Spark applications.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Follow the instructions on our &lt;a href="https://github.com/datamechanics/delight"&gt;Github page&lt;/a&gt;. We have instructions available for the most common setups of Spark:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://spark.apache.org/docs/latest/submitting-applications.html"&gt;Spark-submit&lt;/a&gt; (on any platform)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://databricks.com/"&gt;Databricks&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://aws.amazon.com/emr/"&gt;EMR&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://cloud.google.com/dataproc"&gt;Dataproc&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.datamechanics.co/apache-spark-on-kubernetes"&gt;Spark-on-Kubernetes&lt;/a&gt; using the spark-operator&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://livy.incubator.apache.org/"&gt;Apache Livy&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you’re not sure how to install it on your infrastructure, &lt;a href="https://www.datamechanics.co/contact"&gt;let us know&lt;/a&gt; and we’ll add instructions that fit your needs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--F1LvCu5P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3836/0%2Am3Lnvx_YTP8e0bgD.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--F1LvCu5P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3836/0%2Am3Lnvx_YTP8e0bgD.png" alt="This is the dashboard that you’ll see once logged in. Image by Author."&gt;&lt;/a&gt;&lt;em&gt;This is the dashboard that you’ll see once logged in. Image by Author.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Your applications will automatically appear on the web dashboard once they complete. Clicking on an application opens up the corresponding Spark UI. That’s it!&lt;/p&gt;

&lt;h2&gt;
  
  
  How Does It Work? Is It Secure?
&lt;/h2&gt;

&lt;p&gt;This project consists of two parts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;An &lt;a href="https://github.com/datamechanics/delight"&gt;open-source&lt;/a&gt; Spark agent which runs inside your Spark applications. This agent will stream non-sensitive Spark event logs from your Spark application to our backend.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A closed-source backend consisting of a real-time logs ingestion pipeline, storage services, a web application, and an authentication layer to make this secure.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ooKIWJtM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3840/0%2AZQ8fS6d0VfDbwdGz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ooKIWJtM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3840/0%2AZQ8fS6d0VfDbwdGz.png" alt="Architecture of [Data Mechanics Delight](https://www.datamechnaics.co/delight)."&gt;&lt;/a&gt;&lt;em&gt;Architecture of &lt;a href="https://www.datamechnaics.co/delight"&gt;Data Mechanics Delight&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The agent collects your Spark applications event logs. This is non-sensitive information about the metadata of your Spark application. For example, for each Spark task there is metadata on memory usage, CPU usage, network traffic (&lt;a href="https://github.com/datamechanics/delight/blob/main/documentation/resources/example_spark_event_log_message.json"&gt;view a sample event log&lt;/a&gt;). The agent does not record sensitive information such as the data that your Spark applications actually work on. The agent does not collect your application logs either — as typically they may contain sensitive information.&lt;/p&gt;

&lt;p&gt;This data is encrypted using your personal access token and sent over the internet using the HTTPS protocol. This information is then stored securely inside the Data Mechanics control plane behind an authentication layer. Only you and your colleagues will be able to see your application in our dashboard. The collected data will automatically be deleted 30 days after your Spark application completion.&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s Next?
&lt;/h2&gt;

&lt;p&gt;The release of this hosted Spark History Server is a first step towards a Spark UI replacement tool called Data Mechanics Delight. Our &lt;a href="https://www.datamechanics.co/blog-post/building-a-better-spark-ui-data-mechanics-delight"&gt;announcement in June 2020&lt;/a&gt; to build a Spark UI replacement with new metrics and visualizations generated a lot of interest from the Spark community.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--U38JzlB2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2AEwg731-aMtPWuopd.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--U38JzlB2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2AEwg731-aMtPWuopd.gif" alt="Design prototype for the next releases of Data Mechanics Delight. Image by Author."&gt;&lt;/a&gt;&lt;em&gt;Design prototype for the next releases of Data Mechanics Delight. Image by Author.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The current release does not yet replace the Spark UI, but we hope it will still be valuable to some of you. The next release of &lt;a href="https://www.datamechanics.co/delight"&gt;Delight&lt;/a&gt;, scheduled in January 2021, will consist of an overview screen giving a bird’s-eye view of your applications’ performance. Links to specific jobs, stages or executor pages will still take you to the corresponding Spark UI pages until we gradually replace these pages too.&lt;/p&gt;

&lt;p&gt;Our mission at Data Mechanics is to make &lt;a href="https://www.datamechanics.co/apache-spark"&gt;Apache Spark&lt;/a&gt; much more developer-friendly and cost-effective. We hope this tool will contribute to this goal and prove useful to the Spark community!&lt;/p&gt;

</description>
      <category>apachespark</category>
      <category>monitoring</category>
      <category>opensource</category>
      <category>datascience</category>
    </item>
    <item>
      <title>Spark and Docker: Your Spark development cycle just got 10x faster !</title>
      <dc:creator>JY @ DataMechanics</dc:creator>
      <pubDate>Mon, 23 Nov 2020 23:06:51 +0000</pubDate>
      <link>https://dev.to/jystephan/spark-and-docker-your-spark-development-cycle-just-got-10x-faster-12hm</link>
      <guid>https://dev.to/jystephan/spark-and-docker-your-spark-development-cycle-just-got-10x-faster-12hm</guid>
      <description>&lt;h1&gt;
  
  
  Why Spark and Docker?
&lt;/h1&gt;

&lt;p&gt;The benefits that come with using Docker containers are well known: they provide consistent and isolated environments so that applications can be deployed anywhere - locally, in dev / testing / prod environments, across all cloud providers, and on-premise - in a repeatable way. &lt;/p&gt;

&lt;p&gt;The software engineering world has fully adopted Docker, and a lot of tools around Docker have changed the way we build and deploy software - testing, CI/CD, dependency management, versioning, monitoring, security. The popularity of &lt;a href="https://kubernetes.io/"&gt;Kubernetes&lt;/a&gt; as the new standard for container orchestration and infrastructure management follows from the popularity of &lt;a href="https://www.docker.com/"&gt;Docker&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;In the big data and &lt;a href="https://www.datamechanics.co/apache-spark"&gt;Apache Spark&lt;/a&gt; scene, most applications still run directly on virtual machines without benefiting from containerization. The dominant cluster manager for Spark, Hadoop YARN, did not support Docker containers until &lt;a href="https://hadoop.apache.org/docs/r3.1.1/hadoop-yarn/hadoop-yarn-site/DockerContainers.html"&gt;recently (Hadoop 3.1 release)&lt;/a&gt;, and even today the support for Docker remains “experimental and non-complete”. &lt;/p&gt;

&lt;p&gt;Native support for Docker is in fact one of the main reasons companies choose to deploy &lt;a href="https://www.datamechanics.co/blog-post/pros-and-cons-of-running-apache-spark-on-kubernetes"&gt;Spark on top of Kubernetes instead of YARN&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In this article, we will illustrate the benefits of Docker for Apache Spark by going through the end-to-end development cycle used by many of our users at &lt;a href="https://www.datamechanics.co/blog-post/video-tour-of-data-mechanics-the-serverless-spark-platform"&gt;Data Mechanics&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The benefits of Docker for Apache Spark
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Build your dependencies once, run everywhere
&lt;/h3&gt;

&lt;p&gt;Your application will run the same way wherever you run it: on your laptop for dev / testing, or in any of your production environments.In your Docker image, you will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Package your application code&lt;/li&gt;
&lt;li&gt;Package all your dependencies (python: pypi, eggs, conda, scala / java: jars, maven ; system dependencies)&lt;/li&gt;
&lt;li&gt;Define environment variables to tweak behavior at runtime&lt;/li&gt;
&lt;li&gt;Customize your operating system the way you want&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If running on Kubernetes: you’re free to choose your Spark version for each separate Docker image! This is in contrast to YARN, where you must use the same global Spark version for the entire cluster.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Make Spark more reliable and cost-efficient in production.
&lt;/h3&gt;

&lt;p&gt;Since you can control your entire environment when you build your Docker image, this means you don’t need any init scripts / bootstrap actions to execute at runtime.&lt;br&gt;
These scripts have several issues:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;They’re not reliable - a library installation can fail due to a spurious network failure and be responsible for your Spark pipeline failure in production.&lt;/li&gt;
&lt;li&gt;They’re slow - these runtime scripts can add multiple minutes to the setup time of each of your Spark nodes, which increases your costs.&lt;/li&gt;
&lt;li&gt;They’re hard to develop, maintain, and debug. 
### 3. Speed up your iteration cycle.
At Data Mechanics, our users enjoy a 20-30s iteration cycle, from the time they make a code change in their IDE to the time this change runs as a Spark app on our platform.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is mostly thanks to the fact that Docker caches previously built layers and that Kubernetes is really fast at starting / restarting Docker containers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s_UHf27w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f86d89460c9ff56e7b351c6_Spark%2520%2526%2520Docker%2520Development%2520Iteration%2520Cycle%2520with%2520logo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s_UHf27w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f86d89460c9ff56e7b351c6_Spark%2520%2526%2520Docker%2520Development%2520Iteration%2520Cycle%2520with%2520logo.png" alt="Spark &amp;amp; Docker Development Iteration Cycle"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Tutorial: How to speed up your Spark development cycle by 10x with Docker
&lt;/h2&gt;

&lt;p&gt;In this section, we’ll show you how to work with Spark and Docker, step-by-step. Example screenshots and code samples are taken from running a PySpark application on the Data Mechanics platform, but this example can be simply adapted to work on other environments.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Building the Docker Image
&lt;/h3&gt;

&lt;p&gt;We’ll start from a local PySpark project with some dependencies, and a Dockerfile that will explain how to build a Docker image for this project. Once the Docker image is built, we can directly run it locally, or push to a Docker registry first then run it on the Data Mechanics cluster.&lt;/p&gt;

&lt;p&gt;Thanks to Docker, there's no need to package third-party dependencies and custom modules in brittle zip files. You can just co-locate your main script and its dependencies.&lt;/p&gt;

&lt;p&gt;In this example, we adopt a layout for our project that should feel familiar to most Python developers: a main script, a requirements file, and custom modules.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s6or_0Vu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f85e0c67cb1002d75d75bf0_Spark%2520%2526%2520Docker%2520Building%2520The%2520Docker%2520Image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s6or_0Vu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f85e0c67cb1002d75d75bf0_Spark%2520%2526%2520Docker%2520Building%2520The%2520Docker%2520Image.png" alt="Spark &amp;amp; Docker Dockerfile Config"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s look at the Dockerfile. In this example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We start from a base image published by Data Mechanics. This image corresponds to a major Spark image (3.0 here). We discuss this choice in detail at the end of this article.&lt;/li&gt;
&lt;li&gt;We then install our dependencies. We used pip here, but we could use conda too.&lt;/li&gt;
&lt;li&gt;We finally copy our own code and main file. Since this is the code we’ll be primarily iterating on, it’s recommended to do this at the end, so that when we change this code Docker doesn’t need to rebuild the image from scratch. &lt;/li&gt;
&lt;li&gt;It’s also easy to set up environment variables at this step.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TYYYciCM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f85d35f1d9606c034a5f707_Spark%2520%2526%2520Docker%2520Config.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TYYYciCM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f85d35f1d9606c034a5f707_Spark%2520%2526%2520Docker%2520Config.png" alt="Spark &amp;amp; Docker Config"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Local Run
&lt;/h3&gt;

&lt;p&gt;You can then build this image and run it locally. This means Spark will run in local mode; as a single container on your laptop. You will not be able to process large amounts of data, but this is useful if you just want to test your code correctness (maybe using a small subset of the real data), or run unit tests.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--stsOhkiE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f85e0fb54b3fca4caf81b43_Spark%2520%2526%2520Docker%2520Local%2520Run%2520Build.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--stsOhkiE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f85e0fb54b3fca4caf81b43_Spark%2520%2526%2520Docker%2520Local%2520Run%2520Build.png" alt="Spark &amp;amp; Docker Local Run Build"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On an average laptop, this took 15 seconds. If you’re going to iterate a lot at this stage and want to optimize the speed further; then instead of re-building the image, you can simply mount your local files (from your working directory on your laptop) to your working directory in the image.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gJJYAJug--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f85e122c11b766f9e5feb51_Spark%2520%2526%2520Docker%2520Local%2520Run%2520Mount.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gJJYAJug--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f85e122c11b766f9e5feb51_Spark%2520%2526%2520Docker%2520Local%2520Run%2520Mount.png" alt="Spark &amp;amp; Docker Local Run"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Run at Scale
&lt;/h3&gt;

&lt;p&gt;The code looks correct, and we now want to run this image at scale (in a distributed way) on the full dataset. We’re going to push the image to our Docker registry and then provide the image name as a parameter in the &lt;a href="https://docs.datamechanics.co/docs/first-application"&gt;REST API call&lt;/a&gt; to submit this Spark application to Data Mechanics.&lt;/p&gt;

&lt;p&gt;It’s important to have a fast iteration cycle at this stage too - even though you ran the image locally - as you’ll need to verify the correctness and stability of your pipeline on the full dataset. It’s likely you will need to keep iterating on your code and on your infrastructure configurations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WVT77sP2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f85e138c0babd9e7ad941ee_Spark%2520%2526%2520Docker%2520Run%2520At%2520Scale%2520Kubernetes.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WVT77sP2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f85e138c0babd9e7ad941ee_Spark%2520%2526%2520Docker%2520Run%2520At%2520Scale%2520Kubernetes.png" alt="Spark &amp;amp; Docker Run At Scale Kubernetes"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On an average laptop, this step took 20 seconds to complete: 10 seconds to build and push the image, 10 seconds for the app to start on Data Mechanics - meaning the Spark driver starts executing our main.py code. &lt;/p&gt;

&lt;p&gt;In less than 30 seconds, you’re able to iterate on your Spark code and run it on production data! And you can do this without leaving your IDE (you don’t need to paste your code to a notebook or an interactive shell). This is a game-changer for Spark developers, a 10x speed-up compared to industry average.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"I really love that we can use Docker to package our code on Data Mechanics. It’s a huge win for simplifying PySpark deployment. Based on the iterations I have completed it takes less than 30 seconds to deploy and run the app" - Max, Data Engineer at Weather2020. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This fast iteration cycle is thanks to Docker caching the previous layers of the image, and the Data Mechanics platform (deployed on Kubernetes) optimizing fast container launches and application restarts.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to choose your Spark base Docker image
&lt;/h2&gt;

&lt;p&gt;To run a Spark application on Data Mechanics, you should use one of our published Spark images as a base image (in the first line of your Dockerfile). We publish new images regularly, including whenever a new Spark version is released or when a security fix is available.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ElzkGWCo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f86d72e42ebdd8aedd2fa1b_Data%2520Mechanics%2520Spark-Based%2520Docker%2520Images.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ElzkGWCo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f86d72e42ebdd8aedd2fa1b_Data%2520Mechanics%2520Spark-Based%2520Docker%2520Images.png" alt="Data Mechanics Spark-Based Docker Images"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These Spark images contain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A Spark version, e.g. 2.4 or 3.0&lt;/li&gt;
&lt;li&gt;Some data connectors, e.g. to S3, GCS, Azure Blob Storage, and Snowflake&lt;/li&gt;
&lt;li&gt;Dependencies required by our platform features such as the jupyter integration or data mechanics delight (our Spark UI replacement)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;They are freely available to everyone, and you can also use them to run Spark locally or on other platforms.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We’ve demonstrated how Docker can help you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Package your dependencies and control your environment in a simple way.&lt;/li&gt;
&lt;li&gt;Iterate on your code from your IDE by quickly running Spark locally or at scale&lt;/li&gt;
&lt;li&gt;Make Spark more reliable and cost-efficient in production. Finally, you can say goodbye to slow and flaky bootstrap scripts and runtime downloads!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If this sounds like something you would like to try out on the Data Mechanics platform, &lt;a href="https://calendly.com/datamechanics/demo"&gt;book a demo&lt;/a&gt; with our team to start a trial of Data Mechanics - we’ll help you adopt this Docker-based dev workflow as one of the first steps of our onboarding.&lt;/p&gt;

&lt;p&gt;Running Spark on Kubernetes in a Docker native and cloud agnostic way has many other benefits. For example, you can use the steps above to build a CI/CD pipeline that automates the building and deployment of Spark test applications whenever you submit a pull request to modify one of your production pipelines. We will cover this in a future blog post - so stay tuned!&lt;/p&gt;

</description>
      <category>spark</category>
      <category>docker</category>
      <category>kubernetes</category>
      <category>devops</category>
    </item>
    <item>
      <title>How-to guide: Set up, Manage &amp; Monitor Spark on Kubernetes</title>
      <dc:creator>JY @ DataMechanics</dc:creator>
      <pubDate>Fri, 20 Nov 2020 12:28:33 +0000</pubDate>
      <link>https://dev.to/jystephan/how-to-guide-set-up-manage-monitor-spark-on-kubernetes-2p8k</link>
      <guid>https://dev.to/jystephan/how-to-guide-set-up-manage-monitor-spark-on-kubernetes-2p8k</guid>
      <description>&lt;h1&gt;
  
  
  Here's your how to guide to set up, manage and monitor Spark on k8s
&lt;/h1&gt;

&lt;p&gt;In this post we’d like to expand on that presentation and talk to you about: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is Kubernetes?&lt;/li&gt;
&lt;li&gt;Why run Spark on Kubernetes?&lt;/li&gt;
&lt;li&gt;Getting started with Spark on Kubernetes&lt;/li&gt;
&lt;li&gt;Optimizing performance and cost&lt;/li&gt;
&lt;li&gt;Monitoring your Spark applications on Kubernetes&lt;/li&gt;
&lt;li&gt;The future of Spark on Kubernetes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you’re already familiar with k8s and why Spark on Kubernetes might be a fit for you, feel free to skip the first couple of sections and get straight to the meat of the post!&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Kubernetes (k8s)?
&lt;/h2&gt;

&lt;p&gt;Kubernetes (also known as Kube or k8s) is an open-source container orchestration system initially developed at Google, open-sourced in 2014 and maintained by the Cloud Native Computing Foundation. Kubernetes is used to automate deployment, scaling and management of containerized apps - most commonly Docker containers.&lt;/p&gt;

&lt;p&gt;It offers many features critical to stability, security, performance, and scalability, like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Horizontal Scalability&lt;/li&gt;
&lt;li&gt;Automated Rollouts &amp;amp; Rollbacks&lt;/li&gt;
&lt;li&gt;Load Balancing&lt;/li&gt;
&lt;li&gt;Secrets &amp;amp; Config Management &lt;/li&gt;
&lt;li&gt;...and many more&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://www.kubernetes.io"&gt;Kubernetes&lt;/a&gt; has become the standard for infrastructure management in the traditional software development world. But Kubernetes isn’t as popular in the big data scene which is too often stuck with older technologies like &lt;a href="https://www.datamechanics.co/blog-post/pros-and-cons-of-running-apache-spark-on-kubernetes"&gt;Hadoop YARN&lt;/a&gt;. Until Spark-on-Kubernetes joined the game!&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Spark on Kubernetes?
&lt;/h2&gt;

&lt;p&gt;When support for natively running Spark on Kubernetes was added in Apache Spark 2.3, many companies decided to switch to it. The main reasons for this popularity include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Native containerization and Docker support.&lt;/li&gt;
&lt;li&gt;The ability to run Spark applications in full isolation of each other (e.g. on different Spark versions) while enjoying the cost-efficiency of a shared infrastructure. &lt;/li&gt;
&lt;li&gt;Unifying your entire tech infrastructure under a single cloud agnostic tool (if you already use Kubernetes for your non-Spark workloads).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On top of this, there is no setup penalty for running on Kubernetes compared to YARN (as shown by &lt;a href="https://www.datamechanics.co/blog-post/apache-spark-performance-benchmarks-show-kubernetes-has-caught-up-with-yarn"&gt;benchmarks&lt;/a&gt;, and Spark 3.0 brought many additional improvements to Spark-on-Kubernetes like support for dynamic allocation. &lt;/p&gt;

&lt;p&gt;Read our previous post on the &lt;a href="https://www.datamechanics.co/blog-post/pros-and-cons-of-running-apache-spark-on-kubernetes"&gt;Pros and Cons of Running Spark on Kubernetes&lt;/a&gt; for more details on this topic and comparison with main alternatives.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started with Spark on Kubernetes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Architecture: What happens when you submit a Spark app to Kubernetes
&lt;/h3&gt;

&lt;p&gt;You submit a &lt;a href="https://www.datamechanics.co/apache-spark"&gt;Spark&lt;/a&gt; application by talking directly to Kubernetes (precisely to the Kubernetes API server on the master node) which will then schedule a pod (simply put, a container) for the Spark driver. Once the Spark driver is up, it will communicate directly with Kubernetes to request Spark executors, which will also be scheduled on pods (one pod per executor). If dynamic allocation is enabled the number of Spark executors dynamically evolves based on load, otherwise it’s a static number.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LkDlnlB6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5fa6747b59a7f8bb12677e03_Apache%2520Spark%2520Architecture%2520on%2520Kubernetes%2520Wireframe%2520by%2520Data%2520Mechanics%2520Smaller.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LkDlnlB6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5fa6747b59a7f8bb12677e03_Apache%2520Spark%2520Architecture%2520on%2520Kubernetes%2520Wireframe%2520by%2520Data%2520Mechanics%2520Smaller.png" alt="Spark on Kubernetes Architecture"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to submit applications: spark-submit vs spark-operator
&lt;/h2&gt;

&lt;p&gt;This is a high-level choice you need to do early on. There are two ways to submit Spark applications to Kubernetes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using the spark-submit method which is bundled with Spark. Further operations on the Spark app will need to interact directly with Kubernetes pod objects&lt;/li&gt;
&lt;li&gt;Using the spark-operator. This project was developed (and open-sourced) by GCP, but it works everywhere. It requires running a (single) pod on the cluster, but will turn Spark applications into custom Kubernetes resources which can be defined, configured and described like other Kubernetes objects. It adds other niceties like support for mounting ConfigMaps and Volumes directly from your Spark app configuration. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0tQKjSj---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f693bb9211b213475ad36c6_npc-7Nne0i47USFOPi68nmGcihI-1mA6_m8dq9pUEoFXn3eSvujoNQN8GFWzhX5kecVsqjb3ajsBaA59fiS3IXHzbgXvfRHxtEwWqH4g1XTGjrFn5-VbfMEajkhPtahcl5w3oVEl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0tQKjSj---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f693bb9211b213475ad36c6_npc-7Nne0i47USFOPi68nmGcihI-1mA6_m8dq9pUEoFXn3eSvujoNQN8GFWzhX5kecVsqjb3ajsBaA59fiS3IXHzbgXvfRHxtEwWqH4g1XTGjrFn5-VbfMEajkhPtahcl5w3oVEl.png" alt="Spark Submit vs. Spark on Kubernetes Operator App Management"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We recommend working with the spark-operator as it’s much more easy-to-use!&lt;/p&gt;

&lt;h3&gt;
  
  
  Setup Checklist
&lt;/h3&gt;

&lt;p&gt;The steps below will vary depending on your current infrastructure and your cloud provider (or on-premise setup). But at the high-level, here are the main things you need to setup to get started with Spark on Kubernetes entirely by yourself:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a Kubernetes cluster&lt;/li&gt;
&lt;li&gt;Define your desired node pools based on your workloads requirements&lt;/li&gt;
&lt;li&gt;Tighten security based on your networking requirements (we recommend making the Kubernetes cluster private)&lt;/li&gt;
&lt;li&gt;Create a docker registry to host your own Spark docker images (or use open-source ones)&lt;/li&gt;
&lt;li&gt;Install the Spark-operator&lt;/li&gt;
&lt;li&gt;Install the Kubernetes cluster autoscaler&lt;/li&gt;
&lt;li&gt;Setup the collection of Spark driver logs and Spark event logs to a persistent storage&lt;/li&gt;
&lt;li&gt;Install the Spark history server (to be able to replay the Spark UI after a Spark application has completed from the aforementioned Spark event logs)&lt;/li&gt;
&lt;li&gt;Setup the collection of node and Spark metrics (CPU, Memory, I/O, Disks)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As you see, this is a lot of work, and a lot of moving open-source projects to maintain if you do this in-house. &lt;/p&gt;

&lt;p&gt;This is the reason why we built our managed Spark platform (Data Mechanics), to make Spark on Kubernetes as easy and accessible as it should be. Our platform takes care of this setup and offers additional integrations (e.g. Jupyter, Airflow, IDEs) as well as powerful optimizations on top to make your Spark apps faster and reduce your cloud costs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Optimizing performance and cost
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Use SSDs or large disks whenever possible to get the best shuffle performance for Spark-on-Kubernetes
&lt;/h3&gt;

&lt;p&gt;Shuffles are the expensive all-to-all data exchanges steps that often occur with Spark. They can take up a large portion of your entire Spark job and therefore optimizing Spark shuffle performance matters. We’ve already covered this topic in our YARN vs Kubernetes performance benchmarks article, (read “How to optimize shuffle with Spark on Kubernetes”) so we’ll just give our high-level tips here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use local SSD disks whenever possible&lt;/li&gt;
&lt;li&gt;When they’re not available, increase the size of your disks to boost their bandwidth&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Optimize your Spark pod sizes to avoid wasting capacity
&lt;/h3&gt;

&lt;p&gt;Let’s go through an example. Suppose:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your Kubernetes nodes have 4 CPUs&lt;/li&gt;
&lt;li&gt;You want to fit exactly one Spark executor pod per Kubernetes node&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then you would submit your Spark apps with the configuration spark.executor.cores=4 right? Wrong. Your Spark app will get stuck because executors cannot fit on your nodes. You should account for overheads described in the graph below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--njDJe-x5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f6a999f59b3370e65550de8_Overheads%2520from%2520Kubernetes%2520and%2520Daemonsets%2520for%2520Apache%2520Spark%2520Nodes.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--njDJe-x5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f6a999f59b3370e65550de8_Overheads%2520from%2520Kubernetes%2520and%2520Daemonsets%2520for%2520Apache%2520Spark%2520Nodes.png" alt="Overheads from Kubernetes and Daemonsets for Apache Spark Nodes"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Typically node allocatable represents 95% of the node capacity. The resources reserved to &lt;a href="https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/"&gt;DaemonSets&lt;/a&gt; depends on your setup, but note that DaemonSets are popular for log and metrics collection, networking, and security. Let’s assume that this leaves you with 90% of node capacity available to your Spark executors, so 3.6 CPUs. &lt;/p&gt;

&lt;p&gt;This means you could submit a Spark application with the configuration  &lt;strong&gt;spark.executor.cores=3&lt;/strong&gt;. But this will reserve only 3 CPUs and some capacity will be wasted. Therefore in this case we recommend the following configuration:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;spark.executor.cores=4&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;spark.kubernetes.executor.request.cores=3600m&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This means your Spark executors will request exactly the 3.6 CPUs available, and Spark will schedule up to 4 tasks in parallel on this executor.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Advanced tip:&lt;br&gt;
Setting spark.executor.cores greater (typically 2x or 3x greater) than spark.kubernetes.executor.request.cores is called oversubscription and can yield a significant performance boost for workloads where CPU usage is low.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this example we’ve shown you how to size your Spark executor pods so they fit tightly into your nodes (1 pod per node). Companies also commonly choose to use larger nodes and fit multiple pods per node. In this case you should still pay attention to your Spark CPU and memory requests to make sure the bin-packing of executors on nodes is efficient. This is one of the dynamic optimizations provided by the &lt;a href="https://www.datamechanics.co/blog-post/video-tour-of-data-mechanics-the-serverless-spark-platform"&gt;Data Mechanics&lt;/a&gt; platform.&lt;/p&gt;

&lt;h3&gt;
  
  
  Enable app-level dynamic allocation and cluster-level autoscaling
&lt;/h3&gt;

&lt;p&gt;This is an absolute must-have if you’re running in the cloud and want to make your data infrastructure reactive and cost efficient. There are two level of dynamic scaling:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;App-level dynamic allocation. This is the ability for each Spark application to request Spark executors at runtime (when there are pending tasks) and delete them (when they’re idle). Dynamic allocation is available on Kubernetes since Spark 3.0 by setting the following configurations:&lt;br&gt;
--- &lt;strong&gt;spark.dynamicAllocation.enabled=true&lt;/strong&gt;&lt;br&gt;
--- &lt;strong&gt;spark.dynamicAllocation.shuffleTracking.enabled=true&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cluster-level autoscaling. This means the Kubernetes cluster can request more nodes from the cloud provider when it needs more capacity to schedule pods, and vice-versa delete the nodes when they become unused. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--U4SJMFQ0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f6a66fbd0fb8b722a4b7a98_Kubernetes%2520Cluster%2520Autoscaling%2520for%2520Apache%2520Spark.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--U4SJMFQ0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f6a66fbd0fb8b722a4b7a98_Kubernetes%2520Cluster%2520Autoscaling%2520for%2520Apache%2520Spark.png" alt="Kubernetes Cluster Dynamic Allocation and Autoscaling for Apache Spark"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Together, these two settings will make your entire data infrastructure dynamically scale when Spark apps can benefit from new resources and scale back down when these resources are unused. In practice, starting a Spark pod takes just a few seconds when there is capacity in the cluster. If a new node must first be acquired from the cloud provider, you typically have to wait 1-2 minutes (depending on the cloud provider, region, and type of instance).&lt;/p&gt;

&lt;p&gt;If you want to guarantee that your applications always start in seconds, you can oversize your Kubernetes cluster by scheduling what is called “pause pods” on it. These are low-priority pods which basically do nothing. When a Spark app requires space to run, Kubernetes will delete these lower priority pods, and then reschedule them (causing the cluster to scale up in the background).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u9xFjWcA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f6a9f8752836a0704b27e2b_App%2520level%2520dynamic%2520allocation%2520and%2520cluster%2520level%2520autoscaling%2520-%2520Apache%2520Spark%2520on%2520Kubernetes.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u9xFjWcA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f6a9f8752836a0704b27e2b_App%2520level%2520dynamic%2520allocation%2520and%2520cluster%2520level%2520autoscaling%2520-%2520Apache%2520Spark%2520on%2520Kubernetes.png" alt="Illustration of app-level dynamic allocation and cluster-level autoscaling in action"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Use Spot nodes to reduce cloud costs
&lt;/h3&gt;

&lt;p&gt;Spot (also known as preemptible) nodes typically cost around 75% less than on-demand machines, in exchange for lower availability (when you ask for Spot nodes there is no guarantee that you will get them) and unpredictable interruptions (these nodes can go away at any time).  &lt;/p&gt;

&lt;p&gt;Spark workloads work really well on spot nodes as long as you make sure that only Spark executors get placed on spot while the Spark driver runs on an on-demand machine. Indeed Spark can recover from losing an executor (a new executor will be placed on an on-demand node and rerun the lost computations) but not from losing its driver.&lt;/p&gt;

&lt;p&gt;To enable spot nodes in Kubernetes you should create multiple node pools (some on-demand and some spot) and then use node-selectors and node affinities to put the driver on an on-demand node and executors preferably on spot nodes. &lt;/p&gt;

&lt;h2&gt;
  
  
  Monitoring your Spark applications on Kubernetes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Monitor pod resource usage using the Kubernetes Dashboard
&lt;/h3&gt;

&lt;p&gt;The Kubernetes Dashboard is an open-source general purpose web-based monitoring UI for Kubernetes. It will give you visibility over the apps running on your clusters with essential metrics to troubleshoot their performance like memory usage, CPU utilization, I/O, disks, etc. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--R4CsqJOn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f693b3a21d3db447ce240d1_MuWKwYUadSAVfdBDc_iJaLezxf83Z0nQsgTuAfQF-gYewuSnlODKFUs4vfQwBUY-QuUmwsRn8CE8P3_YPNL8OZ8wLpWIK_z8GPHdTyxfK51qfBZyYFAiLVAeYbVIuwUqhbgw2CzD.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--R4CsqJOn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f693b3a21d3db447ce240d1_MuWKwYUadSAVfdBDc_iJaLezxf83Z0nQsgTuAfQF-gYewuSnlODKFUs4vfQwBUY-QuUmwsRn8CE8P3_YPNL8OZ8wLpWIK_z8GPHdTyxfK51qfBZyYFAiLVAeYbVIuwUqhbgw2CzD.png" alt="Pod Resource Usage Monitoring On The Kubernetes Dashboard"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The main issues with this project is that it’s cumbersome to reconcile these metrics with actual Spark jobs/stages, and that most of these metrics are lost when a Spark application finishes. Persisting these metrics is a bit challenging but possible for example using &lt;a href="https://www.slideshare.net/databricks/native-support-of-prometheus-monitoring-in-apache-spark-30"&gt;Prometheus&lt;/a&gt; (with a built-in servlet since Spark 3.0) or &lt;a href="https://github.com/cerndb/spark-dashboard"&gt;InfluxDB&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to access the Spark UI
&lt;/h3&gt;

&lt;p&gt;The Spark UI is the essential monitoring tool built-in with Spark. It’s a different way to access it whether the app is live or not:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When the app is running, the Spark UI is served by the Spark driver directly on port 4040. To access it, you should port-forward by running the following command:
--- $ kubectl port-forward  4040:4040
--- You can then open up the Spark UI at &lt;a href="http://localhost:4040/"&gt;http://localhost:4040/&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;When the app is completed, you can replay the Spark UI by running the Spark History Server and configuring it to read the Spark event logs from a persistent storage. You should first use the configuration spark.eventLog.dir to write these event logs to the storage backend of your choice. You should then follow this &lt;a href="https://github.com/helm/charts/tree/master/stable/spark-history-server"&gt;documentation&lt;/a&gt; to install the Spark History Server from a Helm Chart and point it to your storage backend.
UPDATE: As of November 2020, we have released a &lt;a href="https://www.datamechanics.co/blog-post/setting-up-managing-monitoring-spark-on-kubernetes"&gt;free, hosted, cross-platform Spark History Server&lt;/a&gt;. This is a simpler alternative than hosting the Spark History Server yourself!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The main issue with the Spark UI is that it’s hard to find the information you’re looking for, and it lacks the system metrics (CPU, Memory, IO usage) from the previous tools.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WkiFrrYn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f693b3afda6435c30ceb42d_zEjfyrQ6_B_boGGsRdJdA3Ntifl7s3ag6RnEv_tb5K0D_Xk9QJsXJlDEPIlJs5dbK2fRbS9PzBEbZmQc58dSIcMwlokEGtUnBKPGIvyB3HMovWAD50MfM3SFmXlamYuWhdSnTul5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WkiFrrYn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f693b3afda6435c30ceb42d_zEjfyrQ6_B_boGGsRdJdA3Ntifl7s3ag6RnEv_tb5K0D_Xk9QJsXJlDEPIlJs5dbK2fRbS9PzBEbZmQc58dSIcMwlokEGtUnBKPGIvyB3HMovWAD50MfM3SFmXlamYuWhdSnTul5.png" alt="Data Mechanics Delight"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For this reason, we’re developing Data Mechanics Delight, a new and improved Spark UI with new metrics and visualizations. This product will be free, partially open-source, and it will work on top of any Spark platform. We're targeting a release early 2021. Read more about it here.&lt;/p&gt;

&lt;h2&gt;
  
  
  The future of Spark on Kubernetes
&lt;/h2&gt;

&lt;p&gt;In the upcoming Apache Spark 3.1 release (expected to December 2020), Spark on Kubernetes will be declared Generally Available -- while today the official documentation still marks it as experimental. This is due to a series of usability, stability, and performance improvements that came in Spark 2.4, 3.0, and continue to be worked on. &lt;/p&gt;

&lt;p&gt;The most exciting features that are currently being worked on around Spark-on-Kubernetes include: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[SPARK-20624] Better handling for node shutdown. This feature targeted for Spark 3.1 will let Kubernetes use the few seconds of notice it gets when a Spark executor is going down (due to dynamic allocation, or a Kubernetes node going down) to copy the shuffle and cache data files to other executors so that this work isn’t lost.&lt;/li&gt;
&lt;li&gt;[SPARK-25299] Use remote storage for persisting shuffle data. This feature will let Spark asynchronously copy shuffle files to remote storage (like S3), which will make the shuffle architecture more robust on Kubernetes (leading to an end-state where compute and storage resources are fully disaggregated). Another option which is evaluated is the possibility to implement an external shuffle service using Kubernetes sidecars (SPARK-32642).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XBXjtd9r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f6a9a7d45559549157db420_%255BSPARK-25299%255D%2520Using%2520remote%2520storage%2520to%2520store%2520shuffle%2520files%2520without%2520impacting%2520performance.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XBXjtd9r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://uploads-ssl.webflow.com/5e72486289a61e0d8c9dbb56/5f6a9a7d45559549157db420_%255BSPARK-25299%255D%2520Using%2520remote%2520storage%2520to%2520store%2520shuffle%2520files%2520without%2520impacting%2520performance.png" alt="SPARK-25299 Using remote storage to store shuffle files without impacting performance"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At Data Mechanics, we firmly believe that the future of Spark on Kubernetes is simply the future of Apache Spark. As one the first commercial Spark platforms deployed on Kubernetes (alongside Google Dataproc which has beta support for Kubernetes), we are certainly biased, but the adoption trends in the community speak for themselves.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We hope this article has given you useful insights into Spark-on-Kubernetes and how to be successful with it. If you’d like to get started with Spark-on-Kubernetes the easy way, &lt;a href="https://calendly.com/datamechanics/demo"&gt;book a time with us&lt;/a&gt;, our team at Data Mechanics will be more than happy to help you deliver on your use case. Focus on your data, while we handle the mechanics.&lt;/p&gt;

</description>
      <category>spark</category>
      <category>kubernetes</category>
      <category>docker</category>
      <category>cloudnative</category>
    </item>
  </channel>
</rss>
