Skip to content
Vibhrav Jha.Let’s talk
All projectsData Engineering

Concurrent Word Count

A benchmark for examining runtime and workload tradeoffs

My contributionThread-pool processing, synchronization and benchmark tooling within the course project.

FieldData Engineering

View repository

Academic benchmark project

Concurrent Word Count and Performance Benchmarking project image

The work
behind the interface.

Made concurrency tradeoffs measurable through a configurable word-count benchmark comparing thread pools, synchronization and CSV/Parquet/Arrow output.

  • Python 3.13
  • threading
  • Parquet
  • Apache Arrow

The result

A benchmark harness for CSV, Parquet and Arrow, including GIL and no-GIL comparisons.

The problem

Implemented configurable thread-pool processing and benchmark reporting for word-count workloads.

A decision worth examining

Compare synchronization and output formats under explicitly chosen Python runtime conditions.

Read the README.

View original README
READMEArchitecture, setup and usage

Concurrent Word Count & Performance Benchmarking System

A high-performance, multi-threaded word counting application with comprehensive benchmarking capabilities. This project explores concurrent programming patterns, Python's Global Interpreter Lock (GIL) behavior, and data format performance characteristics across CSV, Parquet, and Apache Arrow.

Features

πŸš€ Multi-threaded Processing

  • Configurable thread pool for parallel file processing
  • Thread-safe data structures with fine-grained locking
  • Efficient work distribution across compressed text files
  • Real-time processing status logging

πŸ“Š Multiple Output Formats

  • CSV: Human-readable tabular output
  • Parquet: Columnar storage with compression
  • Apache Arrow: Zero-copy in-memory format with memory mapping

πŸ”¬ Comprehensive Benchmarking Suite

  • Thread scaling analysis (GIL vs. No-GIL Python)
  • Format performance comparison
  • Automated test generation and validation
  • Visual performance reporting with SVG charts

Technical Stack

  • Language: Python 3.13 (with and without GIL)
  • Concurrency: Threading with mutex locks
  • Data Formats: CSV, Parquet, Apache Arrow
  • Testing: pytest framework
  • Containerization: Docker
  • Data Processing: pandas, pyarrow, fastparquet

Architecture

Core Components

Word Counter Engine (final.py)

  • Processes gzipped text files in parallel
  • Maintains per-file and aggregate word counts
  • Thread-safe accumulation with optimized locking strategy
  • Supports 3 output formats based on file extension

Test Suite (test.py)

  • 6+ comprehensive test cases covering edge cases
  • Format validation across CSV, Parquet, and Arrow
  • Concurrent processing correctness verification
  • Parameterized tests for format-agnostic validation

Thread Performance Benchmark (thread_bench.py)

  • Compares GIL vs. No-GIL Python performance
  • Tests thread scaling from 1-16+ threads
  • Generates synthetic datasets (256 files, 1M words each)
  • Produces comparative visualizations and CSV results

Format Performance Benchmark (format_bench.py)

  • Evaluates read performance across formats
  • Implements format-specific optimizations:
    • Parquet: Selective column reading
    • Arrow: Memory-mapped file access
  • Measures real-world query performance

Usage

Basic Word Counting

python3 final.py <input_directory> <output_file> <threads>

Arguments:

  • input_directory: Directory containing .txt.gz files
  • output_file: Output path (.csv, .parquet, or .arrow)
  • threads: Number of worker threads

Example:

python3 final.py ./data ./results/wordcount.parquet 8

Running Benchmarks

Thread Scaling Analysis:

python3 thread_bench.py ./outputs

Format Comparison:

python3 format_bench.py ./outputs

Docker Deployment

Build Image

docker build -t wordcount-benchmark .

Run with Standard Python (GIL)

docker run -v ./inputs:/inputs -v ./outputs:/outputs \
  wordcount-benchmark python3.13 final.py /inputs /outputs/output.csv 4

Run with Python No-GIL

docker run -v ./inputs:/inputs -v ./outputs:/outputs \
  wordcount-benchmark python3.13-nogil final.py /inputs /outputs/output.parquet 8

Run Test Suite

docker run -e PROGRAM=final.py wordcount-benchmark python3.13 -m pytest /app/test.py

Output Format

The word count table includes:

  • word: The word (case-insensitive)
  • count: Total occurrences across all files
  • [filename].gz: Per-file occurrence counts

Example:

wordcountfile1.gzfile2.gzfile3.gz
python150507525
data2001005050

Performance Insights

Thread Scaling (Sample Results)

Thread Benchmark

The benchmarks demonstrate:

  • Linear scaling in No-GIL Python up to CPU core count
  • GIL limitations in standard Python for CPU-bound tasks
  • Optimal thread count varies by workload characteristics

Format Performance (Sample Results)

Format Benchmark

Key findings:

  • Parquet: Best for selective column queries (5-10x faster reads)
  • Arrow: Optimal for zero-copy operations with memory mapping
  • CSV: Human-readable but slower for large datasets

Implementation Highlights

Concurrent Design

  • Lock Granularity: Fine-grained locks minimize contention
  • Work Distribution: File-level parallelism ensures balanced workloads
  • Thread Safety: All shared data structures protected by mutexes
  • Efficiency: I/O operations performed outside critical sections

Testing Strategy

  • Parameterized tests for format validation
  • Edge case coverage (empty files, single words, large vocabularies)
  • Performance regression detection
  • Cross-implementation validation

Benchmarking Methodology

  • Synthetic dataset generation (1000-word vocabulary, 256 files)
  • Consistent test conditions across runs
  • Multiple trials for statistical significance
  • Visual and tabular result presentation

Skills Demonstrated

  • Concurrent Programming: Thread management, synchronization, race condition prevention
  • Performance Engineering: GIL analysis, benchmarking, optimization
  • Data Engineering: Multi-format support, columnar storage, memory mapping
  • Software Testing: Comprehensive test design, edge case coverage
  • Containerization: Multi-stage Docker builds, Python version management
  • Data Visualization: Performance chart generation with matplotlib

Requirements

  • Python 3.13 (with/without GIL)
  • pandas, pyarrow, fastparquet
  • pytest (for testing)
  • Docker (for containerized execution)

A deep dive into Python concurrency, GIL behavior, and data format performance characteristics.

Algorithm Design

  1. Aranyaka wildlife-image application interface

    Fullstack

    Aranyaka

  2. DermaNet hackathon prototype showing classification output and a generated explanation

    ML & AI

    DermaNet

  3. AI-generated concept illustration of source documents connected to retrieved evidence and an answer

    ML & AI

    Private-Data RAG

  4. Before It Breaks dashboard separating real weather from synthetic equipment telemetry and estimated costs

    ML & AI

    Before It Breaks

  5. Architecture diagram of simulated stock records flowing through Kafka to HDFS

    Distributed Systems

    Stock Streaming Engine

  6. Vyaya dashboard with clearly labeled synthetic demonstration data

    Fullstack

    Vyaya

  7. Study assistant interface with retrieved source context

    ML & AI

    Fine-Tuning vs. RAG

  8. Architecture diagram of NOAA data, a Cassandra cluster and a query service

    Distributed Systems

    Distributed Weather Data System

  9. Distributed Property Lookup Service project image

    Distributed Systems

    Distributed Property Lookup Service

  10. Architecture diagram connecting MySQL, a gRPC service and HDFS storage

    Distributed Systems

    HDFS & SQL Pipeline

  11. Architecture diagram of Spark processing, SQL and analysis

    Distributed Systems

    Spark Analytics

  12. Multi-Source ELT Pipeline project image

    Data Engineering

    Multi-Source ELT Pipeline

  13. Wisconsin schools in their geographic context β€” explanatory architecture diagram

    Data Engineering

    GCP Geospatial Pipeline

  14. Chinook Music Store SQL Analytics project image

    Data Engineering

    Chinook Music Store SQL Analytics

  15. Yelp Geospatial Analytics project image

    Data Engineering

    Yelp Geospatial Analytics

  16. E-Commerce Semantic Search Engine project image

    Data Engineering

    E-Commerce Semantic Search Engine

  17. Retail Sales Forecasting project image

    ML & AI

    Retail Sales Forecasting

  18. Making tool dependencies inspectable β€” explanatory architecture diagram

    ML & AI

    AI Agent Tool Dependency Graph

  19. From public records to operational questions β€” explanatory architecture diagram

    Data Engineering

    Palantir Foundry and AIP Build Challenge

  20. StudyFlow study-session dashboard

    Fullstack

    StudyFlow

  21. Habit Command Center planning dashboard

    Fullstack

    Habit Command Center

  22. Interfaces across web and mobile β€” explanatory architecture diagram

    Fullstack

    React Web & Mobile

  23. Startup Scout project image

    Fullstack

    Startup Scout

  24. Inventory-Based Recipe Planner project image

    Fullstack

    Inventory-Based Recipe Planner

  25. Concurrent Word Count and Performance Benchmarking project image

    Data EngineeringViewing

    Concurrent Word Count

  26. Data structures matched to their assumptions β€” explanatory architecture diagram

    Computing Foundations

    Algorithm Design

  27. Campus Navigator project image

    Fullstack

    Campus Navigator

  28. i-Songly: Song Management Engine project image

    Fullstack

    i-Songly

  29. An experiment that can resume β€” explanatory architecture diagram

    ML & AI

    CIFAR-100 with LeNet

  30. Fashion-MNIST Neural Network Classifier project image

    ML & AI

    Fashion-MNIST Classifier

  31. PCA Eigenfaces and Image Reconstruction project image

    ML & AI

    PCA Eigenfaces

  32. Two routes to the same regression objective β€” explanatory architecture diagram

    ML & AI

    Lake Mendota Ice Regression

  33. Bayesian Language Detection project image

    ML & AI

    Bayesian Language Detection

  34. Explanatory diagram of the video-fingerprint benchmark: 25 sources, 75 transformed variants and 1,875 comparisons.

    ML & AI

    Video-Fingerprint Benchmark

All projects