blob: 5dd9eb6361c6c7ec9635a6969b5eb5ed5da630ba (
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
|
// Copyright 2017 Yahoo Holdings. 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 <vespa/vespalib/util/sync.h>
#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:
typedef vespalib::ArrayQueue<HttpConnection::UP> Queue;
typedef std::map<ServerSpec, size_t> Map;
using CryptoEngine = vespalib::CryptoEngine;
vespalib::Lock _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
|