Skip to content

Performance testing on android. #817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion external/boost/CMakeLists.txt.boost.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ include(ExternalProject)
ExternalProject_Add(boost-download
GIT_REPOSITORY @OLP_SDK_CPP_BOOST_URL@
GIT_TAG @OLP_SDK_CPP_BOOST_TAG@
GIT_SUBMODULES libs/any
GIT_SUBMODULES libs/algorithm
libs/any
libs/assert
libs/config
libs/container_hash
libs/core
libs/detail
libs/exception
libs/format
libs/function_types
libs/headers
Expand All @@ -43,6 +45,7 @@ ExternalProject_Add(boost-download
libs/predef
libs/preprocessor
libs/random
libs/range
libs/serialization
libs/smart_ptr
libs/static_assert
Expand Down
47 changes: 34 additions & 13 deletions tests/performance/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
# SPDX-License-Identifier: Apache-2.0
# License-Filename: LICENSE

if (ANDROID OR IOS)
message(STATUS "Currently the performance test runner for mobile platforms is not supported")
return()
endif()

set(OLP_SDK_PERFORMANCE_TESTS_SOURCES
./MemoryTest.cpp
./MemoryTestBase.h
Expand All @@ -28,11 +23,37 @@ set(OLP_SDK_PERFORMANCE_TESTS_SOURCES
./PrefetchTest.cpp
)

add_executable(olp-cpp-sdk-performance-tests ${OLP_SDK_PERFORMANCE_TESTS_SOURCES})
target_link_libraries(olp-cpp-sdk-performance-tests
PRIVATE
custom-params
gtest_main
olp-cpp-sdk-authentication
olp-cpp-sdk-dataservice-read
)
if (ANDROID OR IOS)
set(OLP_SDK_PERFORMANCE_TESTS_LIB olp-cpp-sdk-performance-tests-lib)

add_library(${OLP_SDK_PERFORMANCE_TESTS_LIB} ${OLP_SDK_PERFORMANCE_TESTS_SOURCES})
target_link_libraries(${OLP_SDK_PERFORMANCE_TESTS_LIB}
PRIVATE
custom-params
gtest
olp-cpp-sdk-authentication
olp-cpp-sdk-dataservice-read
)

if (ANDROID)
include(${CMAKE_SOURCE_DIR}/cmake/android/gen_android_test.cmake)
gen_android_test_runner(olp-cpp-sdk-performance-tests ${OLP_SDK_PERFORMANCE_TESTS_LIB})
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/android ${CMAKE_CURRENT_BINARY_DIR}/android)
else()
include(${CMAKE_SOURCE_DIR}/cmake/ios/gen_ios_test.cmake)
gen_ios_test_runner(olp-cpp-sdk-performance-tests ${OLP_SDK_PERFORMANCE_TESTS_LIB})
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/ios ${CMAKE_CURRENT_BINARY_DIR}/ios)
endif()

else()

add_executable(olp-cpp-sdk-performance-tests ${OLP_SDK_PERFORMANCE_TESTS_SOURCES})
target_link_libraries(olp-cpp-sdk-performance-tests
PRIVATE
custom-params
gtest_main
olp-cpp-sdk-authentication
olp-cpp-sdk-dataservice-read
)

endif()
89 changes: 42 additions & 47 deletions tests/performance/MemoryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,52 @@
#include <chrono>
#include <memory>

#include <boost/uuid/detail/sha1.hpp>
#include <boost/algorithm/hex.hpp>

#include <gtest/gtest.h>
#include <olp/core/client/HRN.h>
#include <olp/core/logging/Log.h>
#include <olp/dataservice/read/VersionedLayerClient.h>

#include "MemoryTestBase.h"

std::string ComputeSha1(const char* buffer, size_t length) {
using boost::uuids::detail::sha1;
sha1 hash;
sha1::digest_type digest;
sha1::digest_type digest_rotated;

hash.process_bytes(buffer, length);
hash.get_digest(digest);

// rotate bytes
for (int i = 0; i < 5; ++i)
{
const char* tmp = reinterpret_cast<char*>(&digest);
char* res = reinterpret_cast<char*>(&digest_rotated);
res[i*4] = tmp[i*4+3];
res[i*4+1] = tmp[i*4+2];
res[i*4+2] = tmp[i*4+1];
res[i*4+3] = tmp[i*4];
}

const auto charDigest = reinterpret_cast<const char*>(&digest_rotated);
std::string result;
boost::algorithm::hex(charDigest, charDigest + sizeof(sha1::digest_type),
std::back_inserter(result));
return result;
}

bool Validate(const std::vector<unsigned char>& buffer) {
// 40 first bytes is a string representation of hash
const char* bytes = reinterpret_cast<const char*>( buffer.data() );
std::string hash(bytes, bytes + 40);
std::string computed_hash = ComputeSha1(bytes + 40, buffer.size() - 40);
OLP_SDK_LOG_CRITICAL_INFO_F("HASH", "HASHES: %s %s", hash.c_str(), computed_hash.c_str());
return hash == computed_hash;
}

namespace {
using TestFunction = std::function<void(uint8_t thread_id)>;

Expand Down Expand Up @@ -183,53 +222,9 @@ TEST_P(MemoryTest, ReadNPartitionsFromVersionedLayer) {
request, [&](olp::dataservice::read::DataResponse response) {
if (response.IsSuccessful()) {
success_responses_.fetch_add(1);
} else {
failed_responses_.fetch_add(1);
ReportError(response.GetError());
}
});

RandomlyCancel(std::move(token));

std::this_thread::sleep_for(
GetSleepPeriod(parameter.requests_per_second));
}
});
}

TEST_P(MemoryTest, PrefetchPartitionsFromVersionedLayer) {
// Enable only errors to have a short output.
olp::logging::Log::setLevel(olp::logging::Level::Warning);

const auto& parameter = GetParam();

auto settings = CreateCatalogClientSettings();

StartThreads([=](uint8_t /*thread_id*/) {
olp::dataservice::read::VersionedLayerClient service_client(
kCatalog, kVersionedLayerId, boost::none, settings);

const auto end_timestamp =
std::chrono::steady_clock::now() + parameter.runtime;

while (end_timestamp > std::chrono::steady_clock::now()) {
const auto level = 10;
const auto tile_count = 1 << level;

std::vector<olp::geo::TileKey> tile_keys = {
olp::geo::TileKey::FromRowColumnLevel(rand() % tile_count,
rand() % tile_count, level)};

auto request = olp::dataservice::read::PrefetchTilesRequest()
.WithMaxLevel(level + 2)
.WithMinLevel(level)
.WithTileKeys(tile_keys);
total_requests_.fetch_add(1);
auto token = service_client.PrefetchTiles(
std::move(request),
[&](olp::dataservice::read::PrefetchTilesResponse response) {
if (response.IsSuccessful()) {
success_responses_.fetch_add(1);
if (!Validate(*response.GetResult())) {
abort();
}
} else {
failed_responses_.fetch_add(1);
ReportError(response.GetError());
Expand Down
5 changes: 5 additions & 0 deletions tests/performance/MemoryTestBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ class MemoryTestBase : public ::testing::TestWithParam<Param> {
protected:
olp::http::NetworkProxySettings GetLocalhostProxySettings() {
return olp::http::NetworkProxySettings()
#if ANDROID
.WithHostname("10.0.2.2")
#else
.WithHostname("localhost")
#endif
.WithPort(3000)
.WithUsername("test_user")
.WithPassword("test_password")
Expand Down Expand Up @@ -80,6 +84,7 @@ class MemoryTestBase : public ::testing::TestWithParam<Param> {
client_settings.cache =
parameter.cache_factory ? parameter.cache_factory() : nullptr;
client_settings.retry_settings.timeout = 1;
//client_settings.retry_settings.max_attempts = 0;

return client_settings;
}
Expand Down
9 changes: 8 additions & 1 deletion tests/utils/olp_server/blob_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
* License-Filename: LICENSE
*/

var crypto = require('crypto')

function computeHash(data) {
return crypto.createHash('sha1').update(data).digest('hex').toUpperCase();
}

function generateGetBlobApiResponse(request) {
const layer = request[1]
const dataHandle = request[2] // ignored
Expand All @@ -30,7 +36,8 @@ function generateGetBlobApiResponse(request) {
response += characters.charAt(Math.floor(Math.random() * charactersLength));
}

return response;
//console.log(computeHash(response))
return computeHash(response) + response;
}

const methods = [
Expand Down