aboutsummaryrefslogtreecommitdiffstats
path: root/vbench/src/vbench/vbench/worker.cpp
blob: 894c8d4bf36c0abdbf60a2effe51e3d97d1823f8 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "worker.h"
#include <vbench/http/http_client.h>

namespace vbench {

VESPA_THREAD_STACK_TAG(vbench_worker_thread);

void
Worker::run()
{
    for (;;) {
        Request::UP request = _provider.provide();
        if (request.get() == 0) {
            break;
        }
        request->startTime(_timer.sample());
        HttpClient::fetch(_pool, request->server(), request->url(), *request);
        request->endTime(_timer.sample());
        _next.handle(std::move(request));
    }
}

Worker::Worker(Provider<Request> &provider, Handler<Request> &next,
               HttpConnectionPool &pool, Timer &timer)
    : _thread(),
      _provider(provider),
      _next(next),
      _pool(pool),
      _timer(timer)
{
    _thread = vespalib::thread::start(*this, vbench_worker_thread);
}

} // namespace vbench