Aggie Student Toolkit — Load Balancer CSCE 412 Project 4
Arnav Fotedar · Fall 2026 · C++ load balancer simulation
Loading...
Searching...
No Matches
RequestGenerator.h
Go to the documentation of this file.
1
6
7#ifndef REQUESTGENERATOR_H
8#define REQUESTGENERATOR_H
9
10#include <array>
11#include <cstdint>
12#include <random>
13#include <string>
14#include <vector>
15
16#include "Request.h"
17
22 unsigned int minTaskCycles = 10;
23 unsigned int maxTaskCycles = 100;
24 double arrivalRate = 0.45;
25 double waveAmplitude = 0.6;
26 unsigned long wavePeriod = 25000;
27 double streamingShare = 0.35;
28};
29
34 static constexpr std::size_t kTaskBins = 10;
35 static constexpr std::size_t kArrivalBins = 5;
36
37 unsigned long total = 0;
38 unsigned long initial = 0;
39 unsigned long processing = 0;
40 unsigned long streaming = 0;
41 unsigned int minTaskSeen = 0;
42 unsigned int maxTaskSeen = 0;
43 unsigned long long taskCycleSum = 0;
44 std::array<unsigned long, kTaskBins> taskHistogram{};
45 std::array<unsigned long, kArrivalBins> arrivalHistogram{};
46 unsigned long maxArrivalsInCycle = 0;
47};
48
58public:
64 RequestGenerator(const GeneratorSettings& settings, std::uint32_t seed);
65
71 Request makeRequest(unsigned long cycle);
72
79 std::vector<Request> makeInitialBatch(std::size_t count, unsigned long cycle);
80
91 std::vector<Request> arrivalsFor(unsigned long cycle);
92
103 double rateAt(unsigned long cycle) const;
104
106 const GeneratorSettings& settings() const;
107
109 const GeneratorStats& stats() const;
110
112 std::uint32_t seed() const;
113
115 const std::vector<Request>& samples() const;
116
117private:
118 std::string randomIp();
119 void record(const Request& request);
120
121 GeneratorSettings settings_;
122 std::uint32_t seed_;
123 std::mt19937 engine_;
124 std::uniform_int_distribution<unsigned int> taskCycles_;
125 std::uniform_int_distribution<unsigned int> octet_;
126 std::uniform_int_distribution<unsigned int> firstOctet_;
127 std::uniform_int_distribution<unsigned int> hostOctet_;
128 std::bernoulli_distribution streaming_;
129 std::poisson_distribution<unsigned int> arrivals_;
130 GeneratorStats stats_;
131 std::vector<Request> samples_;
132 unsigned long nextId_ = 1;
133};
134
135#endif
Defines the Request structure and its JobType that flow through the load balancer.
RequestGenerator(const GeneratorSettings &settings, std::uint32_t seed)
Creates a generator.
Request makeRequest(unsigned long cycle)
Creates one random request.
const std::vector< Request > & samples() const
const GeneratorStats & stats() const
std::vector< Request > makeInitialBatch(std::size_t count, unsigned long cycle)
Creates the initial queue contents.
const GeneratorSettings & settings() const
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.
std::uint32_t seed() const
Tunable parameters for random request generation.
unsigned int minTaskCycles
Shortest possible task, in clock cycles.
double waveAmplitude
Traffic wave size: the rate swings between (1 - a) and (1 + a) x arrivalRate.
unsigned long wavePeriod
Cycles in one busy-to-quiet traffic wave; 0 disables the wave.
double arrivalRate
Average new requests per clock cycle (Poisson mean).
double streamingShare
Probability that a request is a streaming ('S') job.
unsigned int maxTaskCycles
Longest possible task, in clock cycles.
Running statistics that show the randomness of generated traffic.
static constexpr std::size_t kArrivalBins
Arrival-count buckets: 0, 1, 2, 3, 4+.
unsigned long streaming
Generated requests with JobType::Streaming.
unsigned int minTaskSeen
Shortest task actually generated.
std::array< unsigned long, kTaskBins > taskHistogram
Task lengths split into equal-width bins.
unsigned long initial
Requests generated for the initial queue.
unsigned int maxTaskSeen
Longest task actually generated.
std::array< unsigned long, kArrivalBins > arrivalHistogram
Cycles with 0, 1, 2, 3 and 4+ arrivals.
static constexpr std::size_t kTaskBins
Number of task-length histogram bins.
unsigned long maxArrivalsInCycle
Largest burst generated in a single cycle.
unsigned long processing
Generated requests with JobType::Processing.
unsigned long total
Requests generated, including the initial queue.
unsigned long long taskCycleSum
Sum of all task lengths, for the mean.
A single web request waiting for, or receiving, service.
Definition Request.h:41