Skip to content

Latest commit

Β 

History

History
76 lines (51 loc) Β· 2.9 KB

File metadata and controls

76 lines (51 loc) Β· 2.9 KB

Java Load Balancer Simulation βš–οΈπŸ’»

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.


✨ Features

  • Three Load Balancing Algorithms βš™οΈ

    1. πŸ”„ Round Robin – Requests are distributed evenly in a circular order.
    2. πŸ“‰ Least Connections – Requests are assigned to the server with the fewest active connections.
    3. πŸ”’ 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 serialized UserRequest objects 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

πŸ›  Technologies & Concepts Used

  • Java Socket Programming

    • πŸ“‘ ServerSocket for listening to incoming client connections
    • πŸ“¦ ObjectOutputStream / ObjectInputStream for sending and receiving serialized objects
  • Object Serialization

    • πŸ“„ UserRequest objects 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, JLabel for the control panel
    • 🎨 Styled with Matrix πŸ’š / black πŸ–€ theme

πŸ“‚ Project Structure

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