Flare: Native Compilation for Heterogeneous Workloads in Apache Spark

Grégory M. Essertel, Ruby Y. Tahboub, James M. Decker, Kevin J. Brown, Kunle Olukotun, Tiark RompfarXiv 2017

Abstract

Apache Spark has become the industry standard for big data processing, yet it often lags behind specialized relational engines in raw performance. This gap stems from the overhead of the Java Virtual Machine (JVM) and the "black box" nature of user-defined functions (UDFs). Flare is a novel back-end for Spark that addresses these bottlenecks by compiling query plans and UDFs into optimized native C code. By integrating at multiple levels of the Spark stack, Flare achieves order-of-magnitude speedups for relational workloads and enables seamless optimization of heterogeneous pipelines combining SQL and machine learning.

The Performance Gap in Big Data

While Spark’s Tungsten execution engine significantly improved performance by generating Java bytecode, two primary issues remain:

  1. The "Java Tax": JVM-based execution incurs overhead from object allocation, garbage collection, and abstraction layers that prevent full exploitation of modern hardware features like SIMD or fine-grained memory control.
  2. The UDF Black Box: Spark’s optimizer cannot inspect or optimize inside UDFs. As workloads increasingly mix relational ETL with iterative machine learning, these unoptimized custom code blocks become the primary performance bottleneck.

Flare's Multi-Level Optimization Strategy

Flare introduces a tiered approach to optimization, allowing users to trade off integration depth for performance gains.

Flare Architecture and Optimization Levels
  • Level 1 (Native Tungsten): This level replaces Spark’s Java code generation with native C code. It utilizes the Java Native Interface (JNI) to execute compiled code while maintaining Spark’s existing distribution and fault-tolerance mechanisms.
  • Level 2 (Whole-Query Compilation): For single-node "scale-up" scenarios, Flare bypasses the RDD layer entirely. It compiles the entire query plan into a single, tight C loop, minimizing data movement overhead between query stages.
  • Level 3 (Heterogeneous Integration): Leveraging the Delite compiler framework, Flare treats UDFs as "white boxes." By using Domain-Specific Languages (DSLs) like OptiML, Flare can unify and optimize SQL and machine learning code within a single program.

Flare relies on Lightweight Modular Staging (LMS), a generative programming technique that enables the system to "stage" code execution—effectively writing a program that generates a more optimized version of itself at runtime.

Key Insights: Scaling Up vs. Scaling Out

A core insight of the Flare project is the "80% Rule": profiling shows that in many Spark SQL queries, up to 80% of execution time is spent on data access and decoding. Flare eliminates this by generating specialized, schema-aware data readers.

Furthermore, the authors argue that many "big data" problems actually fit on a single modern server with terabytes of RAM. Spark’s "scale-out" architecture, designed for clusters of commodity hardware, often introduces unnecessary overhead on these powerful "scale-up" machines. Flare is designed to exploit the full potential of such high-end hardware.

Key Results

The researchers evaluated Flare using the TPC-H benchmark and various machine learning kernels (k-means, Logistic Regression, etc.) across different hardware targets, including multi-core NUMA systems and GPUs.

Performance comparison and Spark execution plan for a join operation
  • Relational Performance: On TPC-H benchmarks, Flare Level 2 outperformed Spark SQL by 10x to 60x on many queries, matching or exceeding the performance of state-of-the-art compiled databases like HyPer. As shown in the figure above, Flare's in-memory hash join can be over 100x faster than Spark's sort-merge join for specific operations.
  • Data Loading: Specialized compiled readers for CSV and Parquet files outperformed Spark’s generic versions by an order of magnitude.
  • Heterogeneous Workloads: For machine learning tasks like k-means, Flare Level 3 provided massive speedups by leveraging NUMA-aware thread pinning and GPU acceleration through the Delite back-end.

Limitations and Future Work

While Flare demonstrates significant potential, several areas for future development remain. Level 2 optimizations are currently focused on single-node execution; extending these to distributed environments while preserving fault tolerance is a key goal. Additionally, Level 3 requires the use of Delite-compatible DSLs, which may present a learning curve for some users. Finally, while compilation overhead is low (typically <1.5s), it remains a factor for extremely short-lived queries.

Summary updated

BibTeX
@misc{essertel2017flare,
  author = {Grégory M. Essertel and Ruby Y. Tahboub and James M. Decker and Kevin J. Brown and Kunle Olukotun and Tiark Rompf},
  title = {{Flare: Native Compilation for Heterogeneous Workloads in Apache Spark}},
  year = {2017},
  eprint = {1703.08219},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1703.08219},
}
Figure