aboutsummaryrefslogtreecommitdiffstats
path: root/vbench/src/vbench/vbench/request_scheduler.h
blob: a0fb1eda4e70a02184c1c9e31165070829f9a4cc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "worker.h"
#include "dropped_tagger.h"
#include <vbench/core/time_queue.h>
#include <vbench/core/dispatcher.h>
#include <vbench/core/handler_thread.h>
#include <vespa/vespalib/util/active.h>

namespace vbench {

/**
 * Component responsible for dispatching requests to workers at the
 * appropriate time based on what start time the requests are tagged
 * with.
 **/
class RequestScheduler : public Handler<Request>,
                         public vespalib::Runnable,
                         public vespalib::Active
{
private:
    Timer                   _timer;
    HandlerThread<Request>  _proxy;
    TimeQueue<Request>      _queue;
    DroppedTagger           _droppedTagger;
    Dispatcher<Request>     _dispatcher;
    vespalib::Thread        _thread;
    HttpConnectionPool      _connectionPool;
    std::vector<Worker::UP> _workers;

    void run() override;
public:
    using UP = std::unique_ptr<RequestScheduler>;
    using CryptoEngine = vespalib::CryptoEngine;
    RequestScheduler(CryptoEngine::SP crypto, Handler<Request> &next, size_t numWorkers);
    void abort();
    void handle(Request::UP request) override;
    void start() override;
    RequestScheduler &stop() override;
    void join() override;
};

} // namespace vbench