The Final Project for COMPSCI CS532 - Systems for Data Science.
This project showcases the complete workflow of handling large datasets, including ingestion, cleaning, transformation, and storage using modern data engineering tools. The pipeline involves downloading datasets from Kaggle, processing them with PySpark, and storing the cleaned data in a MySQL database hosted in a Docker container. Additionally, the project evaluates system performance by benchmarking batch ingestion under different configurations.
Key components:
- Data Download: Automate dataset retrieval from Kaggle using the Kaggle API.
- Data Cleaning: Use PySpark to clean and preprocess raw datasets.
- Data Storage: Store cleaned data into a MySQL database using PySpark and JDBC.
- Performance Benchmarking: Analyze ingestion and query processing performance under varying configurations.
- Set up a MySQL database in a Docker container.
- Test Python connectivity to the MySQL database.
- Find and load the dataset with correct instructions.
- Clean each relevant dataset and combine datasets using PySpark.
- Ingest cleaned data into the MySQL database.
- Benchmark batch ingestion performance with varying hardware configurations.
- Plot performance insights comparing execution time vs hardware constraints.
- Plot performance insights comparing rows processed per second.
- Configure the Read and Write Speeds of the Database to simulate the SSD and HDD.
- Measure the performance for performing queries on the data using Htop/lotop
- Plot a chart highlighting insights comparing query time vs. drive technology
- Docker Daemon
- Docker Compose
- Python 3.x
- PySpark
- MySQL Connector for Python
- Python-dotenv
- Kaggle API
- MatPlotLib
- Tabulate
- CPU(# vCPU):12th Gen Intel® Core™ i9-12900H, 2901 MHz, 14 Cores(s), 20 Logical Processors(s)
- GPU (model, # gpu): NVIDIA RTX A2000 8GB Laptop GPU
- OS version: Microsoft Windows 11 10.0.22621 N/A Build 22621
- VM Ubuntu Version : 24.04
- Spark 3.5.5
- Python 3.12.3
- Docker 26.1.3
-
Update package lists
sudo apt update
-
Install OpenJDK 8
sudo apt install openjdk-8-jdk -y
-
Install PySpark
pip install pyspark
-
Install Python-dotenv
pip install python-dotenv
-
Install Kaggle API
pip install kaggle
-
Install MatPlotLib
pip install matplotlib
-
Install Tabulate
pip install tabulate
Create a .env file in the setup directory and enter the following values. This file should not be committed to version control.
Update the Mysql username and password at this stage if required.
MYSQL_DATABASE=mydb
MYSQL_USER=myuser
MYSQL_PASSWORD=mypassword
MYSQL_ROOT_PASSWORD=rootpass
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_DRIVER=com.mysql.cj.jdbc.Driver
KAGGLE_USERNAME=your_kaggle_username
KAGGLE_KEY=your_kaggle_api_key- Go to Kaggle Account Settings.
- Scroll down to the API section.
- Click on
Create New API Token. This will download a file calledkaggle.json. - Open the
kaggle.jsonfile in a text editor. It will look like this:
{
"username": "your_kaggle_username",
"key": "your_kaggle_api_key"
}- Copy the
usernameandkeyvalues and paste them into the.envfile underKAGGLE_USERNAMEandKAGGLE_KEY.
To download the dataset, follow these steps:
- Ensure the
.envfile is correctly set up with your Kaggle credentials:
KAGGLE_USERNAME=your_kaggle_username
KAGGLE_KEY=your_kaggle_api_key- Run the
DataDownload.pyscript:
cd src
python DataDownload.py- The dataset will be downloaded and unzipped into the data directory.
-
Verify if all the MYSQL configuratations are added in
.envas desired. -
Start the database container From the setup directory, run :
`docker-compose up -d` This starts the database in detached mode with the credentials specified in the .env file.
- Verify if the container started up, run:
`docker ps` - Create a sample database to test connectivity, run:
`docker exec -it mysqldb mysql -u MYSQL_USER -D MYSQL_DATABASE -p` Make sure to replace the correct values from the .env file
- Execute the following script
create an
employeestable with some sample data:
CREATE TABLE IF NOT EXISTS employees (
id INT PRIMARY KEY,
name VARCHAR(100),
age INT,
department VARCHAR(100)
);
INSERT INTO employees (id, name, age, department)
VALUES
(1, 'Alice', 30, 'Engineering'),
(2, 'Bob', 25, 'Marketing'),
(3, 'Charlie', 35, 'HR'),
(4, 'David', 40, 'Engineering'),
(5, 'Eve', 28, 'Finance');- Run
TestDatabaseSetup.pyto verify the data:
cd src
python TestDatabaseSetup.py- You should see the following output:
+---+-------+---+-----------+
| id| name|age| department|
+---+-------+---+-----------+
| 1| Alice| 30|Engineering|
| 2| Bob| 25| Marketing|
| 3|Charlie| 35| HR|
| 4| David| 40|Engineering|
| 5| Eve| 28| Finance|
+---+-------+---+-----------+- Start the database container From the setup directory, run
`docker-compose up -d`- Switch to src directory
cd src- Run
TestDatabaseSetup.pyto ensure the Database is set up correctly
python TestDatabaseSetup.py- Run
DataCleaning.pyto prepare datasets for benchmarking full data pipeline and store as parquet files in the data directory.
python DataCleaning.py- Run
BenchmarkFullDataPipeline.pyto run benchmarking on full data pipeline. This will measure performance analysis on master dataframe creation and store it in the database. Once the benchmarking is complete, results will be printed in the console and stored in results
python BenchmarkFullDataPipeline.py- Run
BenchmarkDataCleaning.pyto run benchmarking on data cleaning process. This will measure performance analysis on cleaning the 20% sample of title_akas dataset. Once the benchmarking is complete, results will be printed in the console and stored in results
python BenchmarkDataCleaning.py- Once multiple runs of the benchmarking has been done and results seem stable, store the averaged data in the results folder to be later plotted using matplotlib.
Store the results from BenchmarkFullDataPipeline.py as contents in PerformanceAverageResults.csv. The name and format MUST match as the sample already available in the results folder.
Store the results from BenchmarkDataCleaning.py as contents in CleaningAverageResults.csv.The name and format MUST match as the sample already available in the results folder.
- Once the above steps are done to generate the average results, run
SparkPerformanceVisualizer.pyto plot the final charts. All the charts are stored in the charts folder.
python SparkPerformanceVisualizer.py-
Create a linux VM (this was tested and configured on Kali Linux VM Specifically but should work on any non-Apple Silicon envirorment)
-
Run the following command(s):
docker run -it --rm \
--device-read-bps /dev/sda:100mb \
--device-write-bps /dev/sda:100mb \
-v "$PWD/data:/app/data" \
my-benchmark-image
docker run -it --rm \
--device-read-bps /dev/sda:500mb \
--device-write-bps /dev/sda:500mb \
-v "$PWD/data:/app/data" \
my-benchmark-imagepython DataStorage.pyThis should load the kaggle data into the database.
python BenchmarkQueries.pyThis command will run the queries and output a csv file called storage_performance_results.csv
python BenchmarkGraph.pyThis command will generate a graph comparing the performance of queries between HDD and SSD
