140 bool admit(
const Request& request,
unsigned long cycle);
154 void processCycle(
unsigned long cycle,
const std::vector<Request>& arrivals);
167 std::string
statusLine(
unsigned long cycle)
const;
176 const std::string&
name()
const;
194 const std::vector<ScaleEvent>&
scaleEvents()
const;
196 const std::vector<Snapshot>&
snapshots()
const;
198 const std::vector<WebServer>&
servers()
const;
205 void completeWork(
unsigned long cycle);
206 void adjustCapacity(
unsigned long cycle);
207 void dispatch(
unsigned long cycle);
208 void addServer(
unsigned long cycle);
209 void recordScale(
ScaleEvent::Kind kind,
unsigned long cycle,
unsigned int serverId);
210 void updateExtremes(
unsigned long cycle);
211 std::string describe(
const Request& request)
const;
216 std::size_t maxQueue_;
218 std::queue<Request> pending_;
219 std::vector<WebServer> servers_;
220 unsigned int nextServerId_ = 1;
222 std::vector<ScaleEvent> scaleEvents_;
223 std::vector<Snapshot> snapshots_;
Declares the Firewall class, an IPv4 range blocker used before requests are queued.
Declares the Logger class that prints colored, mode-aware simulation events.
Defines the Request structure and its JobType that flow through the load balancer.
Declares the WebServer class, a worker that processes one Request at a time.
Rejects requests whose source address falls in a blocked IPv4 range.
void start()
Records the starting queue size and performs the first dispatch at time 0.
const ScalingPolicy & policy() const
std::size_t queueSize() const
const std::string & name() const
const LoadBalancerStats & stats() const
std::size_t busyServers() const
void summarize(std::ostream &out) const
Writes the end-of-run summary for this load balancer.
std::size_t activeServers() const
void processCycle(unsigned long cycle, const std::vector< Request > &arrivals)
Runs one clock cycle: complete work, admit arrivals, adjust capacity, dispatch.
const std::vector< Snapshot > & snapshots() const
std::size_t inService() const
std::size_t idleServers() const
std::string statusLine(unsigned long cycle) const
Builds a one-line status: queue, servers (busy/idle/retiring), completed, rejected.
void recordSnapshot(unsigned long cycle)
Saves a Snapshot of the current state for the periodic table in the log.
std::size_t retiringServers() const
std::size_t liveServers() const
LoadBalancer(std::string name, std::size_t initialServers, const ScalingPolicy &policy, const Firewall &firewall, std::size_t maxQueue, Logger &logger)
Creates a load balancer with an initial server pool.
const std::vector< ScaleEvent > & scaleEvents() const
const Firewall & firewall() const
const std::vector< WebServer > & servers() const
bool admit(const Request &request, unsigned long cycle)
Offers a request to the load balancer.
Writes simulation events to the console and, optionally, to a file.
Counters accumulated over a whole run.
unsigned long dispatched
Requests assigned to a server.
std::size_t peakLiveServers
Most live servers at any cycle.
std::size_t queueAfterFirstDispatch
Queue size at time 0, after the first dispatch.
unsigned long discarded
Requests dropped because the queue was full.
unsigned long completed
Requests finished by a server.
unsigned long admitted
Requests that entered the queue.
unsigned long peakQueueCycle
Cycle at which the largest queue was seen.
unsigned long long serverCycles
Sum over cycles of live servers (capacity offered).
std::size_t initialServers
Servers at the start of the run.
unsigned long scaleDowns
Servers removed or marked for retirement.
std::size_t peakQueue
Largest queue size seen.
unsigned long long busyCycles
Server cycles spent processing (capacity used).
unsigned long long totalWait
Sum of queue waits of dispatched requests.
unsigned long rejected
Requests blocked by the firewall.
unsigned long maxWait
Longest queue wait of any dispatched request.
std::size_t startingQueue
Queue size at time 0, before the first dispatch.
std::size_t minActiveServers
Fewest active servers at any cycle.
unsigned long scaleUps
Servers added or reactivated.
unsigned long received
Requests offered to admit().
A single web request waiting for, or receiving, service.
One change to the server pool, kept for the scaling timeline in the log.
std::size_t queueSize
Queue size that triggered the change.
unsigned long cycle
Clock cycle of the change.
Kind
What happened to the server.
@ Added
A new server was created.
unsigned int serverId
Server affected.
std::size_t activeServers
Active (non-retiring) servers after the change.
Rules for growing and shrinking the server pool.
unsigned int maxServers
Never more live servers (active + retiring) than this.
double lowerFactor
Scale down when queue < lowerFactor x active servers.
unsigned int cooldownCycles
Cycles between scaling evaluations.
unsigned int minServers
Never fewer active servers than this.
double upperFactor
Scale up when queue > upperFactor x active servers.
Point-in-time picture of the load balancer, recorded at regular intervals.
unsigned long rejected
Requests blocked by the firewall so far.
std::size_t liveServers
All servers, including retiring ones.
std::size_t queueSize
Requests waiting in the queue.
unsigned long completed
Requests completed so far.
std::size_t idleServers
Servers with no request (inactive).
std::size_t busyServers
Servers processing a request.
unsigned long cycle
Clock cycle of the snapshot.
std::size_t retiringServers
Servers finishing work before removal.