The Multithreaded Database Server is a high-performance, concurrent key-value store designed to handle multiple client requests simultaneously. Built using advanced multithreading techniques, it ensures efficient workload distribution, data consistency, and optimized resource utilization. The server leverages worker threads and a dynamic work queue to process client operations (write
, read
, and delete
) while maintaining thread safety through robust synchronization mechanisms. With an emphasis on scalability and reliability, this project is designed to function as a backbone for data-intensive applications requiring low-latency responses.
- Highly Concurrent Architecture – Utilizes worker threads and a task queue to manage simultaneous client requests efficiently.
- Thread-Safe Operations – Implements mutexes and condition variables to ensure safe concurrent access to the key-value store.
- Persistent Storage – Supports file-based storage to maintain data integrity across server restarts.
- Optimized Work Queue – Uses a dynamically managed queue for efficient request handling and load balancing.
- Real-Time Statistics and Monitoring – Provides runtime statistics for performance monitoring.
- Automated Testing Suite – Includes a comprehensive test framework to validate the correctness, efficiency, and stability of the system.
-
dbserver.c
- The main entry point for the database server.
- Initializes system components such as the database, work queue, listener thread, and worker threads.
- Handles console commands like
stats
for monitoring andquit
for graceful shutdown.
-
dbservices.c
- Implements the server’s core multithreading logic, including the listener and worker threads.
- Manages incoming client requests, distributes them to available worker threads, and updates runtime statistics.
- Implements efficient cleanup mechanisms to manage resource deallocation and ensure optimal performance.
-
dboperations.c
- Defines the fundamental database operations (
db_write
,db_read
,db_delete
). - Uses file-based storage to ensure persistence across sessions.
- Implements synchronization mechanisms to prevent race conditions and data corruption.
- Defines the fundamental database operations (
-
queue.c
- Implements a custom work queue for managing and prioritizing client requests.
- Provides functions for enqueuing, dequeuing, and monitoring request loads to optimize processing efficiency.
-
dbtest.c
- The file simulates multiple client requests (write, read, delete, quit) to test the server's behavior under different scenarios.
- It uses multithreading to simulate concurrent client operations, ensuring the server handles simultaneous requests correctly.
- Includes overload tests to push the server beyond its normal operating limits, verifying its stability and error handling.
- Ensures that data written to the server can be read back correctly, with checks for consistency using CRC32 checksums.
- Tests edge cases such as invalid requests, maximum key limits, and simultaneous operations on the same key.
-
dbservices.h
- Declares functions and global variables for managing server services.
- Defines key constants such as
DEFAULT_PORT
andMAX_WORKERS
.
-
dboperations.h
- Specifies data structures and function prototypes for database operations.
- Defines storage constraints, key-value size limits, and synchronization policies.
-
queue.h
- Declares queue structures and utility functions for task management.
- Ensures seamless integration of the work queue into the server’s architecture.
-
Makefile
- Automates the build process with optimized compilation and linking settings.
- Ensures compatibility with essential libraries (
pthread
,zlib
). - Provides a
clean
target for streamlined project maintenance.
-
testing.sh
- A shell script that automates the deployment and verification of the server.
- Launches the server in a detached
tmux
session and executes a set of predefined tests. - Includes extensive test cases for concurrency handling, data integrity, and edge-case scenarios.
- Run tests by executing
sh testing.sh
in your terminal.
Ensure the following dependencies are installed:
- GCC compiler (
gcc
) - GNU Make (
make
) pthread
libraryzlib
library- A Linux-based x86 environment (Ubuntu, Debian, etc.)
-
Clone the repository:
git clone <repository-url> cd <repository-directory>
-
Build the Server:
make dbserver
-
Build the Test:
make dbtest
-
Run Automated test script:
sh testing.sh
- Start the server:
./dbserver
- The server will start listening for client connections on the default port.
- To print the server statistics, enter
stats
in the console - To stop the server, enter
quit
in the console.
- Keep the server running in a different terminal while doing the following.
- Write a key:
./dbtest -S name "johndoe"
- Read a key:
./dbtest -G name
- Delete a key:
./dbtest -D name
- Help for more commands:
./dbtest --help
- Stress testing:
./dbtest --threads=5 --count=1000
- Random simultaneous request testing:
./dbtest --test
Mitul Nakrani: Github
Meet Katrodiya: Github