Manages a pool of web servers and distributes incoming requests among them.
More...
#include <load_balancer.h>
|
|
int | num_servers |
| | Number of active web servers managed by the load balancer.
|
| |
|
int | time_to_run |
| | Total number of cycles to run the load balancer.
|
| |
|
int | time_elapsed = 0 |
| | Number of cycles elapsed since the load balancer started.
|
| |
|
int | min_request_time = 5 |
| | Minimum duration (in cycles) for a request.
|
| |
|
int | max_request_time = 45 |
| | Maximum duration (in cycles) for a request.
|
| |
|
std::ostream & | output_stream |
| | Output stream for logging and status messages.
|
| |
|
std::queue< Request > | request_queue |
| | Queue storing all pending requests.
|
| |
|
std::vector< WebServer * > | servers |
| | Vector holding pointers to all heap-allocated web servers.
|
| |
Manages a pool of web servers and distributes incoming requests among them.
◆ LoadBalancer()
| LoadBalancer::LoadBalancer |
( |
int | num_servers, |
|
|
int | time_to_run, |
|
|
std::ostream & | output_stream ) |
Constructs a LoadBalancer with a given number of servers and run time.
Constructs a LoadBalancer with a given number of servers and run time. Initializes the request queue and creates the initial set of servers.
- Parameters
-
| num_servers | Number of web servers to start with. |
| time_to_run | Number of cycles to run the load balancer. |
| output_stream | Output stream for logging. |
◆ add_request()
| void LoadBalancer::add_request |
( |
const Request & | req | ) |
|
|
inline |
Adds a request to the request queue.
- Parameters
-
◆ generate_random_request()
| Request LoadBalancer::generate_random_request |
( |
| ) |
|
Generates a random request with random IPs and duration.
- Returns
- A randomly generated Request object.
◆ handle_requests()
| void LoadBalancer::handle_requests |
( |
| ) |
|
Main loop for handling requests and managing servers. Continues until the specified run time is reached.
Main loop for handling requests and managing servers. Assigns requests to idle servers, scales server pool, and simulates new requests.
◆ is_finished()
| bool LoadBalancer::is_finished |
( |
| ) |
|
|
inline |
Checks if the load balancer has finished running.
- Returns
- True if the elapsed time is greater than or equal to the run time.
The documentation for this class was generated from the following files: