Skip to content

Commit 8b2c430

Browse files
Andrei Popescuandescu
authored andcommitted
Adds performance test for CatalogClient.
Adds performance testing for CatalogClient::GetLatestVersion() and CatalogClient::GetCatalog(). Relates-to: OLPEDGE-1151 Signed-off-by: Andrei Popescu <[email protected]>
1 parent 9f41166 commit 8b2c430

File tree

2 files changed

+114
-53
lines changed

2 files changed

+114
-53
lines changed

tests/performance/MemoryTest.cpp

Lines changed: 103 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <memory>
2222

2323
#include <gtest/gtest.h>
24-
2524
#include <olp/core/cache/CacheSettings.h>
2625
#include <olp/core/cache/KeyValueCache.h>
2726
#include <olp/core/client/HRN.h>
@@ -30,16 +29,16 @@
3029
#include <olp/core/logging/Log.h>
3130
#include <olp/core/porting/make_unique.h>
3231
#include <olp/core/utils/Dir.h>
32+
#include <olp/dataservice/read/CatalogClient.h>
3333
#include <olp/dataservice/read/VersionedLayerClient.h>
3434
#include <testutils/CustomParameters.hpp>
35-
3635
#include "NetworkWrapper.h"
3736
#include "NullCache.h"
3837

3938
namespace {
40-
41-
using CacheFactory =
42-
std::function<std::shared_ptr<olp::cache::KeyValueCache>()>;
39+
using KeyValueCachePtr = std::shared_ptr<olp::cache::KeyValueCache>;
40+
using CacheFactory = std::function<KeyValueCachePtr()>;
41+
using TestFunction = std::function<void(uint8_t thread_id)>;
4342

4443
struct TestConfiguration {
4544
std::string configuration_name;
@@ -59,6 +58,11 @@ std::ostream& operator<<(std::ostream& os, const TestConfiguration& config) {
5958
<< ", .runtime=" << config.runtime.count() << ")";
6059
}
6160

61+
constexpr std::chrono::milliseconds GetSleepPeriod(uint32_t requests) {
62+
return std::chrono::milliseconds(1000 / requests);
63+
}
64+
65+
constexpr auto kLogTag = "MemoryTest";
6266
const olp::client::HRN kCatalog("hrn:here:data::olp-here-test:testhrn");
6367
const std::string kVersionedLayerId("versioned_test_layer");
6468

@@ -68,17 +72,12 @@ class MemoryTest : public ::testing::TestWithParam<TestConfiguration> {
6872
static void TearDownTestSuite();
6973

7074
olp::http::NetworkProxySettings GetLocalhostProxySettings();
71-
7275
olp::client::OlpClientSettings CreateCatalogClientSettings();
7376

7477
void SetUp() override;
75-
7678
void TearDown() override;
7779

78-
using TestFunction = std::function<void(const std::uint8_t thread_id)>;
79-
8080
void StartThreads(TestFunction test_body);
81-
8281
void ReportError(const olp::client::ApiError& error);
8382

8483
protected:
@@ -98,9 +97,9 @@ class MemoryTest : public ::testing::TestWithParam<TestConfiguration> {
9897
std::shared_ptr<olp::http::Network> MemoryTest::s_network;
9998

10099
void MemoryTest::SetUpTestSuite() {
101-
auto network = std::make_shared<olp::tests::http::Http2HttpNetworkWrapper>();
102-
network->EnableErrors(true);
103-
network->EnableTimeouts(true);
100+
auto network = std::make_shared<Http2HttpNetworkWrapper>();
101+
network->WithErrors(false);
102+
network->WithTimeouts(false);
104103
s_network = std::move(network);
105104
}
106105

@@ -156,27 +155,30 @@ void MemoryTest::TearDown() {
156155
}
157156
client_threads_.clear();
158157

159-
OLP_SDK_LOG_CRITICAL_INFO_F("MemoryTest",
160-
"Test finished. Total requests %zu, succeed "
158+
OLP_SDK_LOG_CRITICAL_INFO_F(kLogTag,
159+
"Test finished, total requests %zu, succeed "
161160
"responses %zu, failed responses %zu",
162161
total_requests_.load(), success_responses_.load(),
163162
failed_responses_.load());
164163

165164
for (const auto& error : errors_) {
166-
OLP_SDK_LOG_CRITICAL_INFO_F("MemoryTest", "error %d - count %d",
167-
error.first, error.second);
165+
OLP_SDK_LOG_CRITICAL_INFO_F(kLogTag, "error %d - count %d", error.first,
166+
error.second);
168167
}
169168

170169
size_t total_requests = success_responses_.load() + failed_responses_.load();
171170
EXPECT_EQ(total_requests_.load(), total_requests);
171+
172+
// Reset network flags
173+
auto& network = dynamic_cast<Http2HttpNetworkWrapper&>(*s_network);
174+
network.WithErrors(false);
175+
network.WithTimeouts(false);
172176
}
173177

174178
void MemoryTest::StartThreads(TestFunction test_body) {
175-
using namespace olp;
176-
177179
const auto& parameter = GetParam();
178180

179-
for (std::uint8_t i = 0; i < parameter.calling_thread_count; ++i) {
181+
for (uint8_t i = 0; i < parameter.calling_thread_count; ++i) {
180182
client_threads_.emplace_back(std::thread(test_body, i));
181183
}
182184
}
@@ -193,9 +195,80 @@ void MemoryTest::ReportError(const olp::client::ApiError& error) {
193195
}
194196
}
195197

198+
///
199+
/// CatalogClient
200+
///
201+
202+
TEST_P(MemoryTest, ReadLatestVersionCatalogClient) {
203+
const auto& parameter = GetParam();
204+
auto settings = CreateCatalogClientSettings();
205+
206+
StartThreads([=](uint8_t thread_id) {
207+
olp::dataservice::read::CatalogClient service_client(kCatalog, settings);
208+
209+
const auto end_timestamp =
210+
std::chrono::steady_clock::now() + parameter.runtime;
211+
212+
while (end_timestamp > std::chrono::steady_clock::now()) {
213+
int64_t start_version = rand() % (100 + 1);
214+
215+
auto request =
216+
olp::dataservice::read::CatalogVersionRequest().WithStartVersion(
217+
start_version);
218+
total_requests_.fetch_add(1);
219+
service_client.GetLatestVersion(
220+
request,
221+
[&](olp::dataservice::read::CatalogVersionResponse response) {
222+
if (response.IsSuccessful()) {
223+
success_responses_.fetch_add(1);
224+
} else {
225+
failed_responses_.fetch_add(1);
226+
ReportError(response.GetError());
227+
}
228+
});
229+
230+
std::this_thread::sleep_for(
231+
GetSleepPeriod(parameter.requests_per_second));
232+
}
233+
});
234+
}
235+
236+
TEST_P(MemoryTest, ReadMetadataCatalogClient) {
237+
const auto& parameter = GetParam();
238+
auto settings = CreateCatalogClientSettings();
239+
240+
StartThreads([=](uint8_t thread_id) {
241+
olp::dataservice::read::CatalogClient service_client(kCatalog, settings);
242+
243+
const auto end_timestamp =
244+
std::chrono::steady_clock::now() + parameter.runtime;
245+
246+
while (end_timestamp > std::chrono::steady_clock::now()) {
247+
auto request = olp::dataservice::read::CatalogRequest();
248+
total_requests_.fetch_add(1);
249+
service_client.GetCatalog(
250+
request, [&](olp::dataservice::read::CatalogResponse response) {
251+
if (response.IsSuccessful()) {
252+
success_responses_.fetch_add(1);
253+
} else {
254+
failed_responses_.fetch_add(1);
255+
ReportError(response.GetError());
256+
}
257+
});
258+
259+
std::this_thread::sleep_for(
260+
GetSleepPeriod(parameter.requests_per_second));
261+
}
262+
});
263+
}
264+
265+
///
266+
/// VersionedLayerClient
267+
///
268+
196269
/*
197-
* Test performs N requests per second for M duration. All requests are unique.
198-
* Total requests number calculated as:
270+
* Test performs N requests per second for M duration. All requests are
271+
* unique. Total requests number calculated as:
199272
*
200273
* total_count = requests_per_second * calling_thread_count
201274
*
@@ -206,12 +279,9 @@ void MemoryTest::ReportError(const olp::client::ApiError& error) {
206279
TEST_P(MemoryTest, ReadNPartitionsFromVersionedLayer) {
207280
const auto& parameter = GetParam();
208281

209-
const auto sleep_interval =
210-
std::chrono::milliseconds(1000 / parameter.requests_per_second);
211-
212282
auto settings = CreateCatalogClientSettings();
213283

214-
StartThreads([=](const std::uint8_t thread_id) {
284+
StartThreads([=](uint8_t thread_id) {
215285
olp::dataservice::read::VersionedLayerClient service_client(
216286
kCatalog, kVersionedLayerId, settings);
217287

@@ -234,20 +304,18 @@ TEST_P(MemoryTest, ReadNPartitionsFromVersionedLayer) {
234304
}
235305
});
236306

237-
std::this_thread::sleep_for(sleep_interval);
307+
std::this_thread::sleep_for(
308+
GetSleepPeriod(parameter.requests_per_second));
238309
}
239310
});
240311
}
241312

242313
TEST_P(MemoryTest, PrefetchPartitionsFromVersionedLayer) {
243314
const auto& parameter = GetParam();
244315

245-
const auto sleep_interval =
246-
std::chrono::milliseconds(1000 / parameter.requests_per_second);
247-
248316
auto settings = CreateCatalogClientSettings();
249317

250-
StartThreads([=](const std::uint8_t thread_id) {
318+
StartThreads([=](uint8_t thread_id) {
251319
olp::dataservice::read::VersionedLayerClient service_client(
252320
kCatalog, kVersionedLayerId, settings);
253321

@@ -281,7 +349,8 @@ TEST_P(MemoryTest, PrefetchPartitionsFromVersionedLayer) {
281349
}
282350
});
283351

284-
std::this_thread::sleep_for(sleep_interval);
352+
std::this_thread::sleep_for(
353+
GetSleepPeriod(parameter.requests_per_second));
285354
}
286355
});
287356
}
@@ -319,8 +388,8 @@ TestConfiguration ShortRunningTestWithMemoryCache() {
319388
}
320389

321390
/*
322-
* Short 5 minutes test to collect SDK allocations with both in memory cache and
323-
* disk cache.
391+
* Short 5 minutes test to collect SDK allocations with both in memory cache
392+
* and disk cache.
324393
*/
325394
TestConfiguration ShortRunningTestWithDiskCache() {
326395
using namespace olp;

tests/performance/NetworkWrapper.h

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,19 @@
2121

2222
#include <olp/core/http/Network.h>
2323

24-
namespace olp {
25-
namespace tests {
26-
namespace http {
27-
28-
using namespace olp::http;
29-
3024
/*
3125
* Node test server is limited to http proxy. Wrapper alters ongoing requests
3226
* from https to http.
3327
*/
34-
class Http2HttpNetworkWrapper : public Network {
28+
class Http2HttpNetworkWrapper : public olp::http::Network {
3529
public:
3630
Http2HttpNetworkWrapper()
3731
: network_{std::move(olp::http::CreateDefaultNetwork(32))} {}
3832

39-
SendOutcome Send(NetworkRequest request, Payload payload, Callback callback,
40-
HeaderCallback header_callback = nullptr,
41-
DataCallback data_callback = nullptr) override {
33+
olp::http::SendOutcome Send(olp::http::NetworkRequest request,
34+
Payload payload, Callback callback,
35+
HeaderCallback header_callback = nullptr,
36+
DataCallback data_callback = nullptr) override {
4237
ReplaceHttps2Http(request);
4338
InsertDebugHeaders(request);
4439

@@ -47,22 +42,22 @@ class Http2HttpNetworkWrapper : public Network {
4742
std::move(data_callback));
4843
}
4944

50-
void Cancel(RequestId id) override { network_->Cancel(id); }
45+
void Cancel(olp::http::RequestId id) override { network_->Cancel(id); }
5146

5247
/*
5348
* Adds special header, which signal mock server to generate timeouts and
5449
* stalls when serving requests.
5550
*/
56-
void EnableTimeouts(bool with_timeouts) { with_timeouts_ = with_timeouts; }
51+
void WithTimeouts(bool with_timeouts) { with_timeouts_ = with_timeouts; }
5752

5853
/*
5954
* Adds special header, which signal mock server to generate errors when
6055
* serving requests. Error rate is 10%.
6156
*/
62-
void EnableErrors(bool with_errors) { with_errors_ = with_errors; }
57+
void WithErrors(bool with_errors) { with_errors_ = with_errors; }
6358

6459
private:
65-
static void ReplaceHttps2Http(NetworkRequest &request) {
60+
static void ReplaceHttps2Http(olp::http::NetworkRequest &request) {
6661
auto url = request.GetUrl();
6762
auto pos = url.find("https");
6863
if (pos != std::string::npos) {
@@ -74,7 +69,7 @@ class Http2HttpNetworkWrapper : public Network {
7469
/*
7570
* Note: headers with empty values are optimized out.
7671
*/
77-
void InsertDebugHeaders(NetworkRequest &request) {
72+
void InsertDebugHeaders(olp::http::NetworkRequest &request) {
7873
if (with_errors_) {
7974
request.WithHeader("debug-with-errors", "Ok");
8075
}
@@ -86,8 +81,5 @@ class Http2HttpNetworkWrapper : public Network {
8681

8782
bool with_timeouts_ = false;
8883
bool with_errors_ = false;
89-
std::shared_ptr<Network> network_;
84+
std::shared_ptr<olp::http::Network> network_;
9085
};
91-
} // namespace http
92-
} // namespace tests
93-
} // namespace olp

0 commit comments

Comments
 (0)