|
Cade Royal CSCE 412 Project 3
|
A class that represents a load balancer for distributing requests to web servers. More...
#include <LoadBalancer.h>
Public Member Functions | |
| LoadBalancer (int numberServers) | |
| Constructor to initialize the LoadBalancer with the specified number of servers. | |
| ~LoadBalancer () | |
| Destructor to clean up resources used by the LoadBalancer. | |
| void | start () |
| Starts the load balancer, allowing it to begin processing requests. | |
| void | stop () |
| Stops the load balancer and all managed web servers. | |
| void | sendRequest (const Request &req) |
| Sends a request to the load balancer for processing. | |
| void | evaluate () |
| Evaluates the current load and adjusts the number of active servers accordingly. | |
| void | work () |
| The main work loop of the load balancer that processes incoming requests. | |
A class that represents a load balancer for distributing requests to web servers.
The LoadBalancer class encapsulates the logic for managing multiple web servers, distributing incoming requests, and adjusting server count based on current load.
| LoadBalancer::LoadBalancer | ( | int | numberServers | ) |
Constructor to initialize the LoadBalancer with the specified number of servers.
Constructs a LoadBalancer object.
| numberServers | The initial number of web servers to create and manage. |
Initializes the load balancer with the specified number of web servers. Each server starts on a separate thread.
| numberServers | The number of web servers to initialize with. |
| LoadBalancer::~LoadBalancer | ( | ) |
Destructor to clean up resources used by the LoadBalancer.
Destructor for LoadBalancer.
Joins the load balancer thread to ensure all resources are cleaned up before destruction.
| void LoadBalancer::evaluate | ( | ) |
Evaluates the current load and adjusts the number of active servers accordingly.
Evaluates the state of the request queue and adjusts the number of web servers.
This function checks the difference in request queue size since the last evaluation and decides whether to add or remove web servers. Servers are added if the queue size exceeds a threshold or if the size difference increases significantly. Servers are removed if the queue size drops below a threshold or the size difference decreases significantly.
| void LoadBalancer::sendRequest | ( | const Request & | req | ) |
| void LoadBalancer::start | ( | ) |
Starts the load balancer, allowing it to begin processing requests.
Starts the load balancer.
Launches the load balancer's work loop in a separate thread.
| void LoadBalancer::stop | ( | ) |
Stops the load balancer and all managed web servers.
Stops the load balancer and all associated web servers.
Signals the load balancer and web servers to stop, then joins the threads.
| void LoadBalancer::work | ( | ) |
The main work loop of the load balancer that processes incoming requests.
Main work loop of the load balancer.
The load balancer repeatedly checks the request queue and dispatches requests to available web servers. It dynamically adjusts the number of web servers based on the request load.