|
Aggie Student Toolkit — Load Balancer CSCE 412 Project 4
Arnav Fotedar · Fall 2026 · C++ load balancer simulation
|
Produces random requests from a single seeded Mersenne Twister engine. More...
#include <RequestGenerator.h>
Public Member Functions | |
| RequestGenerator (const GeneratorSettings &settings, std::uint32_t seed) | |
| Creates a generator. | |
| Request | makeRequest (unsigned long cycle) |
| Creates one random request. | |
| std::vector< Request > | makeInitialBatch (std::size_t count, unsigned long cycle) |
| Creates the initial queue contents. | |
| std::vector< Request > | arrivalsFor (unsigned long cycle) |
| Creates the random arrivals for one clock cycle. | |
| double | rateAt (unsigned long cycle) const |
| Returns the mean arrival rate at a given cycle. | |
| const GeneratorSettings & | settings () const |
| const GeneratorStats & | stats () const |
| std::uint32_t | seed () const |
| const std::vector< Request > & | samples () const |
Produces random requests from a single seeded Mersenne Twister engine.
Every random choice in the simulation comes from this class: source and destination IPv4 addresses, task length (uniform between the configured minimum and maximum), job type, and the number of new arrivals each cycle (Poisson distributed). Using one logged seed makes every run repeatable.
Definition at line 57 of file RequestGenerator.h.
| RequestGenerator::RequestGenerator | ( | const GeneratorSettings & | settings, |
| std::uint32_t | seed ) |
Creates a generator.
| settings | Task-length range, arrival rate and job mix. |
| seed | Seed for the random engine; the same seed reproduces the same run. |
Definition at line 17 of file RequestGenerator.cpp.
| Request RequestGenerator::makeRequest | ( | unsigned long | cycle | ) |
Creates one random request.
| cycle | Arrival cycle stamped on the request. |
Definition at line 45 of file RequestGenerator.cpp.
| std::vector< Request > RequestGenerator::makeInitialBatch | ( | std::size_t | count, |
| unsigned long | cycle ) |
Creates the initial queue contents.
| count | Number of requests to create. |
| cycle | Arrival cycle stamped on each request (normally 0). |
Definition at line 57 of file RequestGenerator.cpp.
| std::vector< Request > RequestGenerator::arrivalsFor | ( | unsigned long | cycle | ) |
Creates the random arrivals for one clock cycle.
The number of arrivals follows a Poisson distribution whose mean is rateAt(cycle), so most cycles bring zero or one request and occasional cycles bring bursts.
| cycle | Current clock cycle. |
Definition at line 67 of file RequestGenerator.cpp.
| double RequestGenerator::rateAt | ( | unsigned long | cycle | ) | const |
Returns the mean arrival rate at a given cycle.
The rate follows a sine wave around GeneratorSettings::arrivalRate to model busy and quiet periods (for example day and night traffic): rate(t) = arrivalRate x (1 + waveAmplitude x sin(2 pi t / wavePeriod)).
| cycle | Clock cycle. |
Definition at line 27 of file RequestGenerator.cpp.
| const GeneratorSettings & RequestGenerator::settings | ( | ) | const |
Definition at line 108 of file RequestGenerator.cpp.
| const GeneratorStats & RequestGenerator::stats | ( | ) | const |
Definition at line 112 of file RequestGenerator.cpp.
| std::uint32_t RequestGenerator::seed | ( | ) | const |
Definition at line 116 of file RequestGenerator.cpp.
| const std::vector< Request > & RequestGenerator::samples | ( | ) | const |
Definition at line 120 of file RequestGenerator.cpp.