Cade Royal CSCE 412 Project 3
Loading...
Searching...
No Matches
Public Member Functions | List of all members
LoadBalancer Class Reference

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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ LoadBalancer()

LoadBalancer::LoadBalancer ( int  numberServers)

Constructor to initialize the LoadBalancer with the specified number of servers.

Constructs a LoadBalancer object.

Parameters
numberServersThe 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.

Parameters
numberServersThe number of web servers to initialize with.

◆ ~LoadBalancer()

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.

Member Function Documentation

◆ evaluate()

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.

◆ sendRequest()

void LoadBalancer::sendRequest ( const Request req)

Sends a request to the load balancer for processing.

Sends a Request to the load balancer.

Parameters
reqThe Request object to be processed.

Adds a Request object to the internal request queue for processing.

Parameters
reqThe Request object to enqueue.

◆ start()

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.

◆ stop()

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.

◆ work()

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.


The documentation for this class was generated from the following files: