|
Aggie Student Toolkit — Load Balancer CSCE 412 Project 4
Arnav Fotedar · Fall 2026 · C++ load balancer simulation
|
Routes each request to a processing or a streaming LoadBalancer. More...
#include <Switch.h>
Public Member Functions | |
| Switch (std::unique_ptr< LoadBalancer > processing, std::unique_ptr< LoadBalancer > streaming) | |
| Creates a switch that owns both load balancers. | |
| bool | route (const Request &request, unsigned long cycle) |
| Sends one request to the load balancer for its job type. | |
| void | start () |
| Starts both load balancers (records starting queues, dispatches at time 0). | |
| void | processCycle (unsigned long cycle, const std::vector< Request > &arrivals) |
| Splits this cycle's arrivals by job type and runs one cycle on both load balancers. | |
| LoadBalancer & | processing () |
| LoadBalancer & | streaming () |
| unsigned long | routedProcessing () const |
| unsigned long | routedStreaming () const |
Routes each request to a processing or a streaming LoadBalancer.
The switch sits in front of two independent load balancers. Requests with JobType::Processing ('P') go to one, requests with JobType::Streaming ('S') go to the other. Each load balancer keeps its own queue and scales its own server pool, so a surge in one kind of traffic does not slow the other.
| Switch::Switch | ( | std::unique_ptr< LoadBalancer > | processing, |
| std::unique_ptr< LoadBalancer > | streaming ) |
Creates a switch that owns both load balancers.
| processing | Load balancer for 'P' requests. |
| streaming | Load balancer for 'S' requests. |
Definition at line 11 of file Switch.cpp.
| bool Switch::route | ( | const Request & | request, |
| unsigned long | cycle ) |
Sends one request to the load balancer for its job type.
| request | Request to route. |
| cycle | Current clock cycle. |
Definition at line 18 of file Switch.cpp.
| void Switch::start | ( | ) |
Starts both load balancers (records starting queues, dispatches at time 0).
Definition at line 27 of file Switch.cpp.
| void Switch::processCycle | ( | unsigned long | cycle, |
| const std::vector< Request > & | arrivals ) |
Splits this cycle's arrivals by job type and runs one cycle on both load balancers.
| cycle | Clock cycle being simulated. |
| arrivals | Requests generated during this cycle. |
Definition at line 32 of file Switch.cpp.
| LoadBalancer & Switch::processing | ( | ) |
Definition at line 48 of file Switch.cpp.
| LoadBalancer & Switch::streaming | ( | ) |
Definition at line 50 of file Switch.cpp.
| unsigned long Switch::routedProcessing | ( | ) | const |
Definition at line 52 of file Switch.cpp.
| unsigned long Switch::routedStreaming | ( | ) | const |
Definition at line 54 of file Switch.cpp.