This project is a Java-based Load Balancer Simulation that demonstrates how a load balancer distributes client requests to multiple servers using different load balancing algorithms.
It includes a Swing-based GUI π¨ for real-time monitoring and control.
-
Three Load Balancing Algorithms βοΈ
- π Round Robin β Requests are distributed evenly in a circular order.
- π Least Connections β Requests are assigned to the server with the fewest active connections.
- π’ IP Hashing β Requests are mapped to servers based on the client IP hash.
-
Auto-Scaling ππ
Automatically adds or removes server threads based on the average number of pending requests per server. -
Socket Programming π
Uses Java Sockets to send serializedUserRequestobjects from clients to the load balancer. -
Thread-based Server Simulation π§΅
Each server runs on its own thread and processes incoming requests from a shared BlockingQueue. -
Swing GUI π₯οΈ
A Matrix-style control panel ππ€ that allows:- β Adding/removing servers manually
- π Switching between algorithms
- π Toggling auto-scaling ON/OFF
- π Viewing real-time stats: current algorithm, total running servers, total requests handled
-
Java Socket Programming
- π‘
ServerSocketfor listening to incoming client connections - π¦
ObjectOutputStream/ObjectInputStreamfor sending and receiving serialized objects
- π‘
-
Object Serialization
- π
UserRequestobjects are serialized and sent over the network
- π
-
Multithreading
- π§΅ Each server is a separate thread
- π Dispatcher thread in the load balancer distributes requests to the appropriate server
-
BlockingQueue (LinkedBlockingQueue)
- ποΈ Used to store incoming requests and allow thread-safe processing
-
Swing GUI
- ποΈ
JFrame,JButton,JToggleButton,JLabelfor the control panel - π¨ Styled with Matrix π / black π€ theme
- ποΈ
src/
βββ π Main.java β Sends UserRequest objects (Client simulation)
βββ π LoadBalancer.java β Receives requests, distributes to servers
βββ π LoadBalancerConsoleUI.java β Swing control panel for managing servers & settings
βββ π Server.java β Simulated server processing requests
βββ π UserRequest.java β Serializable request object
π Key Learning Points
π§ Understanding how load balancers work
π Implementing different distribution algorithms
π Using Java sockets to send serialized objects
π§΅ Managing concurrency with threads and BlockingQueue
π¨ Creating a functional Swing GUI for system control