|
Aggie Student Toolkit — Load Balancer CSCE 412 Project 4
Arnav Fotedar · Fall 2026 · C++ load balancer simulation
|
A simulated web server that processes at most one request at a time. More...
#include <WebServer.h>
Public Member Functions | |
| WebServer (unsigned int id, unsigned long createdCycle=0) | |
| Creates an idle server. | |
| unsigned int | id () const |
| bool | isIdle () const |
| bool | isRetiring () const |
| void | setRetiring (bool retiring) |
| Marks or unmarks the server for retirement. | |
| void | assign (const Request &request, unsigned long cycle) |
| Starts processing a request. | |
| bool | tick () |
| Advances the server by one clock cycle. | |
| const std::optional< Request > & | current () const |
| const Request & | lastCompleted () const |
| unsigned int | remainingCycles () const |
| unsigned long | completedCount () const |
| unsigned long | busyCycles () const |
| unsigned long | createdCycle () const |
A simulated web server that processes at most one request at a time.
The LoadBalancer assigns a Request to an idle server. Every clock cycle the load balancer calls tick(), which consumes one cycle of the request's remaining work. When the remaining work reaches zero the server reports the completion and becomes idle again.
A server can be marked as retiring during a scale-down. A retiring server receives no new work; the load balancer removes it as soon as it is idle, so in-progress requests are never dropped.
Definition at line 26 of file WebServer.h.
|
explicit |
Creates an idle server.
| id | Unique identifier shown in logs. |
| createdCycle | Clock cycle at which the server was brought online. |
Definition at line 11 of file WebServer.cpp.
| unsigned int WebServer::id | ( | ) | const |
Definition at line 14 of file WebServer.cpp.
| bool WebServer::isIdle | ( | ) | const |
Definition at line 18 of file WebServer.cpp.
| bool WebServer::isRetiring | ( | ) | const |
Definition at line 22 of file WebServer.cpp.
| void WebServer::setRetiring | ( | bool | retiring | ) |
Marks or unmarks the server for retirement.
| retiring | True to stop accepting new work; false to return it to service. |
Definition at line 26 of file WebServer.cpp.
| void WebServer::assign | ( | const Request & | request, |
| unsigned long | cycle ) |
Starts processing a request.
Work begins on the next tick(), so a request with taskCycles = 1 that is assigned at cycle t completes at cycle t + 1.
| request | Request to process; its taskCycles must be at least 1. |
| cycle | Clock cycle of the assignment, used for statistics. |
| std::logic_error | if the server is busy, retiring, or the task length is zero. |
Definition at line 30 of file WebServer.cpp.
| bool WebServer::tick | ( | ) |
Advances the server by one clock cycle.
Definition at line 44 of file WebServer.cpp.
| const std::optional< Request > & WebServer::current | ( | ) | const |
Definition at line 59 of file WebServer.cpp.
| const Request & WebServer::lastCompleted | ( | ) | const |
Definition at line 63 of file WebServer.cpp.
| unsigned int WebServer::remainingCycles | ( | ) | const |
Definition at line 67 of file WebServer.cpp.
| unsigned long WebServer::completedCount | ( | ) | const |
Definition at line 71 of file WebServer.cpp.
| unsigned long WebServer::busyCycles | ( | ) | const |
Definition at line 75 of file WebServer.cpp.
| unsigned long WebServer::createdCycle | ( | ) | const |
Definition at line 79 of file WebServer.cpp.