-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperformance_tests.cpp
More file actions
108 lines (91 loc) · 3.48 KB
/
Copy pathperformance_tests.cpp
File metadata and controls
108 lines (91 loc) · 3.48 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
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
#include "test_utils.hpp"
#include "universal_connection_pool/connection_pool.hpp"
#include <atomic>
#include <chrono>
#include <string>
namespace {
struct performance_connection {
int id = 0;
};
ucp::connection_factory<performance_connection> make_performance_factory(
std::atomic<int>& created) {
ucp::connection_factory<performance_connection> factory;
factory.create = [&] {
return performance_connection{++created};
};
return factory;
}
ucp::pool_options performance_options() {
ucp::pool_options options;
options.max_size = 1;
options.reaper_interval = std::chrono::milliseconds(0);
options.histogram_buckets = {std::chrono::hours(1)};
return options;
}
} // namespace
UCP_TEST(PerformanceProfile_LowLatencyDisablesHistogramButKeepsCoreState) {
std::atomic<int> created{0};
auto options = performance_options();
options.performance.profile = ucp::performance_profile::low_latency;
options.performance.lock_shard_count = 4;
ucp::connection_pool<performance_connection> pool(
make_performance_factory(created),
options);
{
auto connection = pool.borrow();
UCP_EXPECT_TRUE(connection.valid());
}
const auto stats = pool.stats();
UCP_EXPECT_EQ(stats.borrowed_total, 1u);
UCP_EXPECT_EQ(stats.idle_connections, 1u);
UCP_EXPECT_EQ(stats.wait_time_histogram.count, 0u);
UCP_EXPECT_TRUE(pool.to_prometheus("perf").find("ucp_wait_time_seconds_bucket") ==
std::string::npos);
const auto diagnostics = pool.dump_diagnostics_json();
UCP_EXPECT_TRUE(diagnostics.find("\"profile\":\"low_latency\"") != std::string::npos);
UCP_EXPECT_TRUE(diagnostics.find("\"lock_shard_count\":4") != std::string::npos);
}
UCP_TEST(PerformanceMetricsSampling_ReducesHistogramSamplesOnly) {
std::atomic<int> created{0};
auto options = performance_options();
options.performance.metrics_sampling.wait_time_histogram_sample_rate = 2;
ucp::connection_pool<performance_connection> pool(
make_performance_factory(created),
options);
for (int i = 0; i < 4; ++i) {
auto connection = pool.borrow();
UCP_EXPECT_TRUE(connection.valid());
}
const auto stats = pool.stats();
UCP_EXPECT_EQ(stats.borrowed_total, 4u);
UCP_EXPECT_EQ(stats.returned_total, 4u);
UCP_EXPECT_EQ(stats.wait_time_histogram.count, 2u);
UCP_EXPECT_EQ(stats.wait_time_histogram.buckets[0].count, 2u);
UCP_EXPECT_TRUE(pool.dump_diagnostics_json().find(
"\"wait_time_histogram_sample_rate\":2") != std::string::npos);
}
UCP_TEST(PerformanceOptions_RejectInvalidShardOrSampleRate) {
std::atomic<int> created{0};
bool rejected_shards = false;
try {
auto options = performance_options();
options.performance.lock_shard_count = 0;
ucp::connection_pool<performance_connection> pool(
make_performance_factory(created),
options);
} catch (const ucp::invalid_pool_options&) {
rejected_shards = true;
}
UCP_EXPECT_TRUE(rejected_shards);
bool rejected_sample_rate = false;
try {
auto options = performance_options();
options.performance.metrics_sampling.wait_time_histogram_sample_rate = 0;
ucp::connection_pool<performance_connection> pool(
make_performance_factory(created),
options);
} catch (const ucp::invalid_pool_options&) {
rejected_sample_rate = true;
}
UCP_EXPECT_TRUE(rejected_sample_rate);
}