-
Notifications
You must be signed in to change notification settings - Fork 4
/
sender.h
100 lines (87 loc) · 2.51 KB
/
sender.h
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#pragma once
#include <chrono>
#include <optional>
#include <string>
#include <vector>
#include "util.h"
struct GlobalSendOptions {
bool zero_send_buf = true;
float run_seconds = 5;
int maxOutstanding = 16000;
size_t response_size = 1;
std::string host;
bool ipv6 = true;
};
struct PerSendOptions {
int threads = 4;
int per_thread = 64;
size_t size = 64;
size_t resp = 64;
size_t workload = 0;
static std::pair<std::string, PerSendOptions> parseOptions(std::string const& tx);
};
struct LatencyResult {
std::chrono::microseconds p100 = {};
std::chrono::microseconds p95 = {};
std::chrono::microseconds p50 = {};
std::chrono::microseconds avg = {};
double count = 0.0 /* avg count done per burst */;
static LatencyResult from(std::vector<std::chrono::microseconds>&& durations);
void mergeIn(LatencyResult&& l);
static LatencyResult avgMerge(std::vector<LatencyResult> const& bs);
std::string toString() const;
};
struct SendResults {
double packetsPerSecond = 0;
double bytesPerSecond = 0;
size_t connects = 0;
size_t connectErrors = 0;
size_t sendErrors = 0;
size_t recvErrors = 0;
LatencyResult latencies;
std::vector<LatencyResult> burstResults;
void mergeIn(SendResults&& b) {
packetsPerSecond += b.packetsPerSecond;
bytesPerSecond += b.bytesPerSecond;
sendErrors += b.sendErrors;
recvErrors += b.recvErrors;
connectErrors += b.connectErrors;
connects += b.connects;
latencies.mergeIn(std::move(b.latencies));
burstResults.insert(
burstResults.end(), b.burstResults.begin(), b.burstResults.end());
}
std::string burstString() const {
if (burstResults.empty()) {
return {};
}
auto r = LatencyResult::avgMerge(burstResults);
return strcat(" burst={", r.toString(), "}");
}
std::string latencyString() const {
if (!latencies.count) {
return {};
}
return strcat(" latency={", latencies.toString(), "}");
}
std::string toString() const {
return strcat(
"packetsPerSecond=",
leftpad(strcat((int)(packetsPerSecond / 1000)), 7),
"k bytesPerSecond=",
leftpad(strcat((int)(bytesPerSecond / 1000000)), 5),
"M connectErrors=",
connectErrors,
" sendErrors=",
sendErrors,
" recvErrors=",
recvErrors,
" connects=",
connects,
latencyString(),
burstString());
}
};
SendResults
runSender(std::string const& test, GlobalSendOptions const& options, uint16_t port);
std::vector<std::string> allScenarios();