Welcome to the Lamport Clock Simulator! This Python project simulates the concept of Lamport clocks in a distributed system environment, allowing you to create local events, send time-stamped messages to other processes, and observe how the Lamport timestamps are updated. It provides an interactive, socket based locally distributed, & a sleek terminal-based user interface that helps in understanding the synchronization between distributed systems.
- Interactive TUI: Built using the
rich
Python library for a beautiful and interactive terminal interface. - Lamport Clock Implementation: Simulates the behavior of logical clocks.
- Real-time Communication: Supports sending and receiving time-stamped messages between real python processes.
- Event Handling: Trigger local events and simulate message exchanges.
- Port Validation: Checks if the port is available, ensuring no conflicts.
- Logs: Maintains a detailed event comunication log between the processes.
lamport.mp4
Clone this repository and install the dependencies using the following steps:
git clone https://github.com/AnolChakraborty/Lamport-Clock-Simulator.git
cd Lamport-Clock-Simulator
Make sure you have Python 3.8 or higher installed. Then, install the required packages using pip
:
pip install rich
NOTE: Use a terminal with True Colour support for the best experience.
To start the simulator, run the following command in your terminal:
python3 main.py
The Lamport Clock Simulator is a terminal-based user interface (TUI) application. When you run the application, you will interact with it entirely through your terminal window. Below is a step-by-step guide on how to use the application:
-
Port Configuration:
- The first prompt will ask you to enter a valid port number for this process. Ensure that the port number is between 1024 and 65535 and is not currently in use.
-
Multiple Sessions:
- To simulate interactions between multiple processes, open separate terminal sessions and run the simulator on different ports. For example:
In one terminal, run the simulator on port 5000:
In another terminal, run the simulator on port 5001:
python3 main.py
Simillarly run as many instance you want of the same program with different port number. This setup will allow you to simulate the behavior of multiple distributed processes communicating with each other in your local systen.python3 main.py
- To simulate interactions between multiple processes, open separate terminal sessions and run the simulator on different ports. For example:
In one terminal, run the simulator on port 5000:
-
Event Options:
- Once configured, you will be presented with two main options:
l
: Trigger a local event that increments the Lamport clock. This action updates the logical time of the process.s
: Send a message to another process with the current Lamport clock time.
- Once configured, you will be presented with two main options:
-
Sending Messages:
- If you choose to send a message (
s
), you will be prompted to input the destination port. The application checks if the port is valid and attempts to establish a connection. - If successful, the message containing the sender's port and the Lamport time is sent to the destination.
- If you choose to send a message (
-
Viewing Logs:
- The terminal will display a log of the last 10 events, including timestamps, sender/receiver details, and actions performed. This helps you track the sequence of events in the simulation.
- Port Configuration: When prompted, enter a valid port number for this process.
- Event Options:
l
: Trigger a local event to increment the Lamport clock.s
: Send a message to another process with the current Lamport time.
- View Logs: The terminal will display the last 10 events, including timestamps and sender/receiver information.
I welcome contributions! To contribute:
- Fork the repository.
- Create a new branch.
- Make your changes and commit them.
- Push your branch and create a pull request.
This project is licensed under the MIT License. See the LICENSE file for more details.
- This project is done on behalf of our academic requirement of the subject
Distributed Systems - CSE1817OE31
- Rich library for making terminal applications visually appealing.
- Concept of Lamport Clocks for logical time synchronization.
For questions or comments, please reach out to Anol Chakraborty or create an issue in the repository.