aboutsummaryrefslogtreecommitdiffstats
path: root/vbench/src/vbench/vbench/request_scheduler.h
blob: e93912cd0644cf2c1907f8ea7ff8cc9ecf88c495 (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
46
47
48
// Copyright Vespa.ai. 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 <mutex>
#include <condition_variable>

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
{
private:
    Timer                   _timer;
    HandlerThread<Request>  _proxy;
    TimeQueue<Request>      _queue;
    DroppedTagger           _droppedTagger;
    Dispatcher<Request>     _dispatcher;
    std::thread             _thread;
    HttpConnectionPool      _connectionPool;
    std::vector<Worker::UP> _workers;
    std::mutex              _lock;
    std::condition_variable _cond;
    bool                    _may_slumber;
    
    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();
    RequestScheduler &stop();
    void join();
};

} // namespace vbench