Skip to content

Commit 3916495

Browse files
Update the performance test (#1240)
Update the performance test to collect total bytes written to disk by the cache. Relates-To: OLPEDGE-1771 Signed-off-by: Mykhailo Kuchma <[email protected]>
1 parent cab0309 commit 3916495

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

tests/performance/MemoryTest.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include <chrono>
2121
#include <memory>
2222
#include <thread>
23+
#include <fstream>
24+
#include <regex>
2325

2426
#include <gtest/gtest.h>
2527
#include <olp/core/client/HRN.h>
@@ -37,6 +39,7 @@ struct TestConfiguration : public TestBaseConfiguration {
3739
std::uint8_t calling_thread_count = 5;
3840
std::chrono::seconds runtime = std::chrono::minutes(5);
3941
float cancelation_chance = 0.f;
42+
bool collect_stats = false;
4043
};
4144

4245
std::ostream& operator<<(std::ostream& os, const TestConfiguration& config) {
@@ -45,7 +48,8 @@ std::ostream& operator<<(std::ostream& os, const TestConfiguration& config) {
4548
<< ", .calling_thread_count=" << config.calling_thread_count
4649
<< ", .task_scheduler_capacity=" << config.task_scheduler_capacity
4750
<< ", .requests_per_second=" << config.requests_per_second
48-
<< ", .runtime=" << config.runtime.count() << ")";
51+
<< ", .runtime=" << config.runtime.count()
52+
<< ", .collect_stats=" << config.collect_stats << ")";
4953
}
5054

5155
constexpr std::chrono::milliseconds GetSleepPeriod(uint32_t requests) {
@@ -60,6 +64,25 @@ bool ShouldCancel(const TestConfiguration& configuration) {
6064
return rand() % 100 <= thresold;
6165
}
6266

67+
uint64_t GetWrittenBytes() {
68+
std::ifstream fs("/proc/self/io");
69+
if (!fs) {
70+
return 0;
71+
}
72+
73+
uint64_t size = 0u;
74+
std::string line;
75+
while (std::getline(fs, line)) {
76+
std::regex rgx("write_bytes: ([0-9]+)");
77+
std::smatch match;
78+
if (std::regex_search(line, match, rgx)) {
79+
return size = std::stoull(match[1]);
80+
}
81+
}
82+
83+
return 0;
84+
}
85+
6386
constexpr auto kLogTag = "MemoryTest";
6487
const olp::client::HRN kCatalog("hrn:here:data::olp-here-test:testhrn");
6588
const std::string kVersionedLayerId("versioned_test_layer");
@@ -84,6 +107,8 @@ class MemoryTest : public MemoryTestBase<TestConfiguration> {
84107

85108
std::mutex errors_mutex_;
86109
std::map<int, int> errors_;
110+
111+
uint64_t previous_written_bytes_{};
87112
};
88113

89114
void MemoryTest::SetUp() {
@@ -93,6 +118,8 @@ void MemoryTest::SetUp() {
93118
success_responses_.store(0);
94119
failed_responses_.store(0);
95120
errors_.clear();
121+
122+
previous_written_bytes_ = GetWrittenBytes();
96123
}
97124

98125
void MemoryTest::TearDown() {
@@ -114,6 +141,16 @@ void MemoryTest::TearDown() {
114141

115142
size_t total_requests = success_responses_.load() + failed_responses_.load();
116143
EXPECT_EQ(total_requests_.load(), total_requests);
144+
145+
const auto& parameter = GetParam();
146+
if (parameter.collect_stats) {
147+
Test::RecordProperty("total_requests", std::to_string(total_requests_));
148+
Test::RecordProperty("total_succeed", std::to_string(success_responses_));
149+
150+
auto total_bytes_written = GetWrittenBytes() - previous_written_bytes_;
151+
Test::RecordProperty("total_written_to_disk_bytes",
152+
std::to_string(total_bytes_written));
153+
}
117154
}
118155

119156
void MemoryTest::StartThreads(TestFunction test_body) {
@@ -207,6 +244,7 @@ TestConfiguration LongRunningTest() {
207244
configuration.configuration_name = "15m_test";
208245
configuration.runtime = std::chrono::minutes(15);
209246
configuration.cancelation_chance = 0.25f;
247+
configuration.collect_stats = true;
210248
return configuration;
211249
}
212250

0 commit comments

Comments
 (0)