PyFroid: Scaling Data Analysis on a Commodity Workstation

K. Venkatesh Emani, Avrilia Floratou, Carlo CurinoEDBT 2024

Abstract

PyFroid is a framework designed to scale Pandas-based data analysis on commodity workstations. By utilizing a dual-engine architecture that combines the standard Pandas engine with a high-performance SQL engine (DuckDB), PyFroid enables processing datasets up to 20x larger than standard Pandas without requiring code changes. This paper details the hybrid lazy evaluation mechanism and evaluates its performance across diverse real-world workloads, demonstrating significant improvements in memory efficiency and scalability.

Introduction

Pandas is the undisputed king of data manipulation in Python, but it has a major weakness: memory efficiency. It often requires 5x to 10x more RAM than the size of the dataset itself. When a data scientist’s dataset grows from 1GB to 5GB, their 16GB RAM workstation often chokes, leading to crashes or agonizingly slow performance. This "memory wall" forces practitioners to choose between two suboptimal paths: adopting heavyweight distributed systems like Spark or Modin, which introduce significant overhead on single-node setups, or switching to new APIs like Polars or Ibis, which require a steep learning curve and extensive code rewrites.

PyFroid addresses this "commodity workstation" gap by providing a solution that scales Pandas on a single machine without forcing the user to learn a new language or manage a cluster.

The PyFroid Architecture

PyFroid acts as a transparent, "drop-in" replacement for Pandas. Under the hood, it employs a dual-engine architecture consisting of the standard Pandas engine and a high-performance, embedded SQL engine (DuckDB). The core innovation is its Hybrid Lazy Evaluation mechanism.

The PyFroid dual-engine architecture and execution flow, showing the transition between Lazy and Eager frames.

As shown in Figure 1, PyFroid manages data through two primary structures:

  • LazyFrame: When a user performs operations like filters or joins, PyFroid does not execute them immediately. Instead, it builds a SQL query plan to be executed by DuckDB.
  • EagerFrame: If an operation cannot be translated to SQL (such as complex Python UDFs or specific time-series resampling), PyFroid "materializes" only the necessary data into a standard Pandas DataFrame to complete the task.

This system automatically decides which parts of the code can be pushed into the SQL engine, managing the movement of data between the SQL and Pandas environments transparently. Furthermore, PyFroid maintains a separate metadata structure to ensure that row ordering and indexing remain consistent with standard Pandas behavior, despite SQL tables being inherently unordered.

Evaluation Methodology

The authors evaluated PyFroid using a mix of real-world and synthetic workloads:

  1. Kaggle Notebooks (N1-N10): Ten popular public notebooks using CSV datasets between 1GB and 5GB.
  2. Production Notebooks (P11-P12): Real-world data analysis workloads used internally at Microsoft.
  3. Micro-benchmarks: Synthetic tests designed to measure specific operations like joins, groups, and reads.

Key Results and Insights

PyFroid successfully ran notebooks on datasets up to 20x larger than what standard Pandas could handle on the same hardware. By pushing "thinning" operations (like filters and projections) to DuckDB, PyFroid ensures that only the final, smaller result set ever hits the memory-heavy Pandas engine.

Peak memory utilization comparison across various workloads (N1-P12) and dataset sizes (GB).

As illustrated in Figure 4, PyFroid maintains stability where standard Pandas often fails (indicated by the infinity symbol). In some workloads, PyFroid used 84x less peak memory than Pandas because it avoided materializing massive intermediate dataframes. For large datasets, PyFroid was significantly faster than both Pandas and Modin. For example, on a 1.5GB merge operation where Pandas failed entirely, PyFroid completed the task efficiently.

While Modin (on Ray) is a popular alternative, the study found it often consumed 100% of available memory even on small datasets due to its distributed architecture overhead, whereas PyFroid remained lightweight and efficient on a single workstation.

Limitations and Future Work

Despite its advantages, PyFroid faces a "materialization tax." If a user frequently calls operations that cannot be translated to SQL (like .head() or .info() inside a loop), the system is forced to repeatedly execute queries and move data to Pandas, which can lead to higher latency than standard "eager" Pandas.

Future research will focus on translating arbitrary Python User Defined Functions (UDFs) into SQL and developing a cost-based optimizer. Such an optimizer would consider data size and operation complexity to make more informed decisions about when to move data between engines, further enhancing performance.

Summary updated

BibTeX
@inproceedings{emani2024pyfroid,
  author = {K. Venkatesh Emani and Avrilia Floratou and Carlo Curino},
  title = {{PyFroid: Scaling Data Analysis on a Commodity Workstation}},
  booktitle = {EDBT},
  year = {2024},
  doi = {10.48786/edbt.2024.06},
}
Figure