14constexpr std::size_t kSampleCount = 10;
25 streaming_(
settings.streamingShare) {}
28 if (settings_.wavePeriod == 0 || settings_.waveAmplitude == 0.0) {
29 return settings_.arrivalRate;
31 const double pi = std::acos(-1.0);
32 const double phase = 2.0 * pi *
static_cast<double>(cycle % settings_.wavePeriod) / settings_.wavePeriod;
33 return std::max(0.0, settings_.arrivalRate * (1.0 + settings_.waveAmplitude * std::sin(phase)));
36std::string RequestGenerator::randomIp() {
37 unsigned int first = firstOctet_(engine_);
38 while (first == 127) {
39 first = firstOctet_(engine_);
41 return std::to_string(first) +
"." + std::to_string(octet_(engine_)) +
"." +
42 std::to_string(octet_(engine_)) +
"." + std::to_string(hostOctet_(engine_));
47 request.
id = nextId_++;
58 std::vector<Request> batch;
60 for (std::size_t i = 0; i < count; ++i) {
63 stats_.initial += count;
68 const double rate =
rateAt(cycle);
69 unsigned int count = 0;
71 arrivals_.param(std::poisson_distribution<unsigned int>::param_type(rate));
72 count = arrivals_(engine_);
75 stats_.maxArrivalsInCycle = std::max<unsigned long>(stats_.maxArrivalsInCycle, count);
76 std::vector<Request> batch;
78 for (
unsigned int i = 0; i < count; ++i) {
84void RequestGenerator::record(
const Request& request) {
85 if (stats_.
total == 0) {
95 stats_.minTaskSeen = std::min(stats_.minTaskSeen, request.
taskCycles);
96 stats_.maxTaskSeen = std::max(stats_.maxTaskSeen, request.
taskCycles);
99 const unsigned long span = settings_.maxTaskCycles - settings_.minTaskCycles + 1UL;
100 const unsigned long offset = request.
taskCycles - settings_.minTaskCycles;
103 if (samples_.size() < kSampleCount) {
104 samples_.push_back(request);
@ Processing
Short computational job, such as rendering a page or running a query.
@ Streaming
Long-lived transfer, such as streaming media or a large download.
Declares the RequestGenerator class, the seeded source of random traffic.
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.
Running statistics that show the randomness of generated traffic.
static constexpr std::size_t kArrivalBins
Arrival-count buckets: 0, 1, 2, 3, 4+.
unsigned int minTaskSeen
Shortest task actually generated.
unsigned int maxTaskSeen
Longest task actually generated.
static constexpr std::size_t kTaskBins
Number of task-length histogram bins.
unsigned long total
Requests generated, including the initial queue.
A single web request waiting for, or receiving, service.
unsigned int taskCycles
Clock cycles of processing required (always at least 1).
unsigned long arrivalCycle
Clock cycle at which the request was generated.
JobType jobType
Processing ('P') or streaming ('S') work.
std::string destinationIp
IPv4 address the response is returned to.
unsigned long id
Sequential identifier assigned by the generator.
std::string sourceIp
IPv4 address of the client sending the request.