diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ad30a35..cdd908f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -15,6 +15,7 @@ set(AZURE_STORAGE_TEST_SOURCES integration/block_blob_integration_test.cpp integration/append_blob_integration_test.cpp integration/page_blob_integration_test.cpp + integration/performance_test.cpp ) add_executable(azure-storage-test ${AZURE_STORAGE_TEST_SOURCES}) diff --git a/test/integration/performance_test.cpp b/test/integration/performance_test.cpp new file mode 100644 index 0000000..29acb28 --- /dev/null +++ b/test/integration/performance_test.cpp @@ -0,0 +1,121 @@ +#include "blob_integration_base.h" +#include "mstream.h" + +#include "catch2/catch.hpp" + +#include +#include +#include +#include + +TEST_CASE("SingleThreadPerformance", "[performance][!hide]") +{ + azure::storage_lite::blob_client client = as_test::base::test_blob_client(); + + std::string container_name = "large-scale-test"; + std::string blob_name = as_test::get_random_string(10); + + auto ret = client.create_container(container_name).get(); + if (!ret.success() && ret.error().code != "409") + { + std::cout << "Failed to create container, Error: " << ret.error().code << ", " << ret.error().code_name << std::endl; + } + + std::size_t buffer_size = 1024 * 1024 * 1024; + std::string buffer; + buffer.resize(buffer_size); + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution distrib(0, std::numeric_limits::max()); + for (std::size_t i = 0; i < buffer_size; i += sizeof(uint64_t)) + *(reinterpret_cast(&buffer[0] + i)) = distrib(gen); + azure::storage_lite::imstream istream(buffer.data(), buffer.size()); + std::vector> metadata; + auto timer_start = std::chrono::system_clock::now(); + ret = client.upload_block_blob_from_stream(container_name, blob_name, istream, metadata).get(); + auto timer_end = std::chrono::system_clock::now(); + + if (!ret.success()) + { + std::cout << "Failed to upload blob, Error: " << ret.error().code << ", " << ret.error().code_name << std::endl; + } + else + { + double speed = static_cast(buffer.length()) / 1024 / 1024 + / std::chrono::duration_cast(timer_end - timer_start).count() + * 1000; + std::cout << "Upload speed: " << speed << "MiB/s" << std::endl; + } + + azure::storage_lite::omstream ostream(&buffer[0], buffer.size()); + timer_start = std::chrono::system_clock::now(); + ret = client.download_blob_to_stream(container_name, blob_name, 0, 0, ostream).get(); + timer_end = std::chrono::system_clock::now(); + if (!ret.success()) + { + std::cout << "Failed to download blob, Error: " << ret.error().code << ", " << ret.error().code_name << std::endl; + } + else + { + double speed = static_cast(buffer.length()) / 1024 / 1024 + / std::chrono::duration_cast(timer_end - timer_start).count() + * 1000; + std::cout << "Download speed: " << speed << "MiB/s" << std::endl; + } +} + +TEST_CASE("MultiThreadPerformance", "[performance][!hide]") +{ + int concurrency = 24; + + azure::storage_lite::blob_client client = as_test::base::test_blob_client(concurrency); + + std::string container_name = "large-scale-test"; + std::string blob_name = as_test::get_random_string(10); + + auto ret = client.create_container(container_name).get(); + if (!ret.success() && ret.error().code != "409") + { + std::cout << "Failed to create container, Error: " << ret.error().code << ", " << ret.error().code_name << std::endl; + } + + std::size_t buffer_size = 8 * 1024 * 1024 * 1024ULL; + std::string buffer; + buffer.resize(buffer_size); + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution distrib(0, std::numeric_limits::max()); + for (std::size_t i = 0; i < buffer_size; i += sizeof(uint64_t)) + *(reinterpret_cast(&buffer[0] + i)) = distrib(gen); + std::vector> metadata; + auto timer_start = std::chrono::system_clock::now(); + ret = client.upload_block_blob_from_buffer(container_name, blob_name, buffer.data(), metadata, buffer.length(), concurrency).get(); + auto timer_end = std::chrono::system_clock::now(); + + if (!ret.success()) + { + std::cout << "Failed to upload blob, Error: " << ret.error().code << ", " << ret.error().code_name << std::endl; + } + else + { + double speed = static_cast(buffer.length()) / 1024 / 1024 + / std::chrono::duration_cast(timer_end - timer_start).count() + * 1000; + std::cout << concurrency << " thread upload speed: " << speed << "MiB/s" << std::endl; + } + + timer_start = std::chrono::system_clock::now(); + ret = client.download_blob_to_buffer(container_name, blob_name, 0, buffer.size(), &buffer[0], concurrency).get(); + timer_end = std::chrono::system_clock::now(); + if (!ret.success()) + { + std::cout << "Failed to download blob, Error: " << ret.error().code << ", " << ret.error().code_name << std::endl; + } + else + { + double speed = static_cast(buffer.length()) / 1024 / 1024 + / std::chrono::duration_cast(timer_end - timer_start).count() + * 1000; + std::cout << concurrency << " thread download speed: " << speed << "MiB/s" << std::endl; + } +}