forked from rsocket/rsocket-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFireForgetThroughputTcp.cpp
More file actions
74 lines (56 loc) · 1.94 KB
/
FireForgetThroughputTcp.cpp
File metadata and controls
74 lines (56 loc) · 1.94 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2004-present Facebook. All Rights Reserved.
#include "benchmarks/Fixture.h"
#include "benchmarks/Latch.h"
#include <folly/Benchmark.h>
#include <folly/portability/GFlags.h>
#include "rsocket/RSocket.h"
using namespace rsocket;
DEFINE_int32(server_threads, 8, "number of server threads to run");
DEFINE_int32(
override_client_threads,
0,
"control the number of client threads (defaults to the number of clients)");
DEFINE_int32(clients, 10, "number of clients to run");
DEFINE_int32(items, 1000000, "number of items to fire-and-forget, in total");
namespace {
class Responder : public RSocketResponder {
public:
Responder(Latch& latch) : latch_{latch} {}
void handleFireAndForget(Payload, StreamId) override {
latch_.post();
}
private:
Latch& latch_;
};
}
BENCHMARK(FireForgetThroughput, n) {
(void)n;
Latch latch{static_cast<size_t>(FLAGS_items)};
std::unique_ptr<Fixture> fixture;
Fixture::Options opts;
BENCHMARK_SUSPEND {
auto responder = std::make_shared<Responder>(latch);
opts.serverThreads = FLAGS_server_threads;
opts.clients = FLAGS_clients;
if (FLAGS_override_client_threads > 0) {
opts.clientThreads = FLAGS_override_client_threads;
}
fixture = std::make_unique<Fixture>(opts, std::move(responder));
LOG(INFO) << "Running:";
LOG(INFO) << " Server with " << opts.serverThreads << " threads.";
LOG(INFO) << " " << opts.clients << " clients across "
<< fixture->workers.size() << " threads.";
LOG(INFO) << " Running " << FLAGS_items << " requests in total.";
}
for (int i = 0; i < FLAGS_items; ++i) {
for (auto& client : fixture->clients) {
client->getRequester()
->fireAndForget(Payload("TcpFireAndForget"))
->subscribe(yarpl::make_ref<yarpl::single::SingleObserverBase<void>>());
}
}
constexpr std::chrono::minutes timeout{5};
if (!latch.timed_wait(timeout)) {
LOG(ERROR) << "Timed out!";
}
}