blob: 7b77cab1b08336ecadc679d139c82a13e0ad7c1f (
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "http_connection.h"
#include <vbench/core/timer.h>
#include <vespa/vespalib/util/arrayqueue.hpp>
#include <map>
namespace vbench {
/**
* A pool of http connections used to support persistent
* connections. The pool is shared between threads to reduce the
* number of needed connections when using many servers.
**/
class HttpConnectionPool
{
private:
using Queue = vespalib::ArrayQueue<HttpConnection::UP>;
using Map = std::map<ServerSpec, size_t>;
using CryptoEngine = vespalib::CryptoEngine;
std::mutex _lock;
Map _map;
std::vector<Queue> _store;
CryptoEngine::SP _crypto;
Timer &_timer;
public:
HttpConnectionPool(CryptoEngine::SP crypto, Timer &timer);
~HttpConnectionPool();
CryptoEngine &crypto() { return *_crypto; }
HttpConnection::UP getConnection(const ServerSpec &server);
void putConnection(HttpConnection::UP conn);
};
} // namespace vbench
|