Abstract: This paper details the architectural foundations for distributed linear algebra and optimization within the Apache Spark framework. By decoupling distributed matrix operations from local vector updates, Spark enables large-scale computations that leverage high-performance native libraries. We discuss matrix formats, the matrix-vector separation paradigm, and the integration of legacy numerical code, demonstrating performance across massive datasets and diverse hardware configurations.
Introduction
As datasets grow into the petabyte scale, they are increasingly represented as massive matrices exceeding the memory capacity of individual machines. Traditional tools like NumPy or MATLAB are insufficient for such scales. The challenge lies in partitioning data to minimize communication overhead and adapting single-node algorithms for a distributed, fault-tolerant environment like the Java Virtual Machine (JVM).
Distributed Matrix Representations
Spark introduces three primary distributed matrix formats to address varying sparsity and structure:
- CoordinateMatrix: Stores entries as $(i, j, value)$ tuples, ideal for extremely sparse, massive matrices.
- BlockMatrix: Partitions the matrix into dense sub-matrices, serving as the primary format for general distributed linear algebra.
- RowMatrix: Designed for "tall and skinny" matrices where each row fits in memory but the total row count is massive.
The Matrix-Vector Separation Paradigm
A key insight is the asymmetry between matrix and vector sizes ($O(n^2)$ vs $O(n)$). Many iterative algorithms interact with matrices solely through matrix-vector products. Spark exploits this by keeping the parameter vector local to the driver node while distributing the matrix-vector multiplication across the cluster. This approach allowed for the distribution of legacy libraries like ARPACK for Singular Value Decomposition (SVD) and the porting of TFOCS (Templates for First-Order Conic Solvers) for convex optimization.
Hardware Acceleration and the JVM
Despite running on the JVM, Spark achieves high performance by using the Java Native Interface (JNI) to call optimized C and Fortran libraries such as Intel MKL or OpenBLAS. Benchmarks indicate that while GPUs offer significant acceleration, they only outperform CPUs once matrix sizes are large enough (e.g., 10k x 10k) to offset the data transfer overhead to GPU memory.
Optimization and Convergence
The Spark-TFOCS implementation demonstrates that accelerated gradient methods (e.g., Nesterov’s) and L-BFGS converge significantly faster than standard gradient descent in distributed settings. This efficiency is crucial as each iteration in a distributed environment incurs communication costs.
Key Results and Scaling
- SVD Scaling: The Spark implementation of ARPACK successfully factorized a matrix with 1.6 billion non-zeros in approximately 50 seconds using 68 executors.
- Optimization Efficiency: Accelerated methods and L-BFGS proved superior for distributed workloads where communication latency is a factor.
- Native Performance: Using OpenBLAS or Intel MKL provided a massive speedup over standard Java-based math, allowing Spark to reach near-metal performance.
Limitations and Future Work
The current framework assumes the parameter vector fits on the driver node. For models with billions of features, fully distributed BlockMatrix operations would be required. Additionally, while backtracking line search is effective, it introduces extra communication rounds. Future work involves maturing JVM-based sparse matrix-vector product libraries to match the performance of dense counterparts.
Summary updated