-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathperf.cpp
132 lines (100 loc) · 3.36 KB
/
perf.cpp
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#define _1GB (1 * 1024 * 1024 * 1024)
#include <arpa/inet.h>
static const char *tls_cert;
static const char *tls_key;
static const char *tls_chain;
static struct in6_addr serverAddress = {};
#include <thread>
#include "perf.services.h"
// mode (client or server) networking (iouring or syscall) serverIpAddress (any, loopback, or ipv6)
int main (int argc, char *argv[])
{
constexpr uint32_t bytesForTest = _1GB;
if (strcmp(argv[3], "any") == 0)
{
serverAddress = in6addr_any;
}
else if (strcmp(argv[3], "loopback") == 0)
{
serverAddress = in6addr_loopback;
}
else
{
inet_pton(AF_INET6, argv[3], &serverAddress);
}
if (strcmp(argv[1], "server") == 0)
{
tls_cert = "tls/server.cert.pem";
tls_key = "tls/server.key.pem";
tls_chain = "tls/chain.cert.pem";
globalSetup<Mode::server>();
auto runServerTest = [&] <Mode mode> (QuicLibrary<mode> *server) -> void {
server->instanceSetup(4433, argc - 4, argv + 4);
server->startPerfTest();
};
if (strcmp(argv[2], "iouring") == 0)
{
runServerTest(libraryForChoice<Mode::server | Mode::iouring>());
}
else if (strcmp(argv[2], "syscall") == 0)
{
runServerTest(libraryForChoice<Mode::server | Mode::syscall>());
}
}
else
{
tls_cert = "tls/client.cert.pem";
tls_key = "tls/client.key.pem";
tls_chain = "tls/chain.cert.pem";
globalSetup<Mode::client>();
// multiple client threads disabled for now
uint16_t nThreads = 1;
if (nThreads == 0) nThreads = std::thread::hardware_concurrency();
std::vector<std::jthread> threads;
double seconds[nThreads];
std::atomic<uint16_t> clientsReady = 0;
struct sockaddr_in6 *server_in6 = (struct sockaddr_in6 *)calloc(1, sizeof(struct sockaddr_in6));
server_in6->sin6_family = AF_INET6;
server_in6->sin6_flowinfo = 0;
server_in6->sin6_port = htons(4433);
server_in6->sin6_addr = serverAddress;
auto runClientTest = [=] <Mode mode> (QuicLibrary<mode> *client, uint16_t threadIndex, std::atomic<uint16_t>& clientsReady, double *seconds) -> void {
client->instanceSetup(1111 + threadIndex, argc - 4, argv + 4);
client->connectToServer((struct sockaddr *)server_in6);
client->openStream();
// signal we're ready and wait for other clients
clientsReady += 1;
while (clientsReady != nThreads) {}
// everyone is ready, blast the server
auto start = std::chrono::high_resolution_clock::now();
client->startPerfTest(bytesForTest);
auto end = std::chrono::high_resolution_clock::now();
double time = (double)std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
printf("%f seconds\n", time / 1000.0f);
seconds[threadIndex] = time / 1000.0f;
};
for (uint16_t threadIndex = 0; threadIndex < nThreads; ++threadIndex)
{
threads.emplace_back([&, threadIndex] (std::stop_token st) {
if (strcmp(argv[2], "iouring") == 0)
{
runClientTest(libraryForChoice<Mode::client | Mode::iouring>(), threadIndex, clientsReady, seconds);
}
else if (strcmp(argv[2], "syscall") == 0)
{
runClientTest(libraryForChoice<Mode::client | Mode::syscall>(), threadIndex, clientsReady, seconds);
}
});
}
for (auto& thread : threads)
{
thread.join();
}
float totalSeconds = 0;
for (uint16_t threadIndex = 0; threadIndex < nThreads; ++threadIndex)
{
totalSeconds += seconds[threadIndex];
}
printf("%f Gb/s\n", (nThreads / totalSeconds) * 8.0);
}
}