Skip to content

Commit 8b4adba

Browse files
committed
address issues from PR comments
1 parent a4a7ff9 commit 8b4adba

File tree

6 files changed

+151
-145
lines changed

6 files changed

+151
-145
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
6+
#pragma once
7+
8+
namespace PerformanceTest {
9+
10+
/**
11+
* Base class for all performance tests.
12+
*/
13+
class PerformanceTestBase {
14+
public:
15+
virtual ~PerformanceTestBase() = default;
16+
17+
/**
18+
* Initialize resources for the test.
19+
*/
20+
virtual void Setup() = 0;
21+
22+
/**
23+
* Run the performance test operations.
24+
*/
25+
virtual void Run() = 0;
26+
27+
/**
28+
* Clean up resources created during setup.
29+
*/
30+
virtual void TearDown() = 0;
31+
};
32+
33+
} // namespace PerformanceTest

tests/performance-tests/include/performance-tests/Utils.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@
55

66
#pragma once
77

8-
#include <aws/core/Aws.h>
98
#include <aws/core/utils/StringUtils.h>
109
#include <aws/core/utils/UUID.h>
1110
#include <aws/core/utils/memory/stl/AWSString.h>
1211

1312
#include <algorithm>
1413
#include <cstddef>
1514
#include <cstdlib>
16-
#include <iostream>
17-
#include <random>
18-
#include <string>
1915

2016
namespace PerformanceTest {
2117
namespace Utils {
@@ -37,16 +33,6 @@ static inline Aws::String RandomString(size_t length) {
3733
return str;
3834
}
3935

40-
/**
41-
* Log error messages to stderr.
42-
* @param service The name of the AWS service
43-
* @param operation The name of the operation that failed
44-
* @param message The error message to log
45-
*/
46-
static inline void LogError(const Aws::String& service, const Aws::String& operation, const Aws::String& message) {
47-
std::cerr << "[ERROR] " << service << ":" << operation << " failed: " << message << '\n';
48-
}
49-
5036
/**
5137
* Generate a unique identifier using UUID.
5238
* @return A 10-character lowercase UUID substring
@@ -56,16 +42,5 @@ static inline Aws::String GenerateUniqueId() {
5642
return Aws::Utils::StringUtils::ToLower(rawUUID.c_str()).substr(0, 10);
5743
}
5844

59-
/**
60-
* Get the current SDK version as a formatted string.
61-
* @return SDK version in the format "major.minor.patch" (e.g., "1.11.0")
62-
*/
63-
static inline Aws::String GetSDKVersionString() {
64-
Aws::SDKOptions::SDKVersion const version;
65-
return Aws::Utils::StringUtils::to_string(static_cast<int>(version.major)) + "." +
66-
Aws::Utils::StringUtils::to_string(static_cast<int>(version.minor)) + "." +
67-
Aws::Utils::StringUtils::to_string(static_cast<int>(version.patch));
68-
}
69-
7045
} // namespace Utils
7146
} // namespace PerformanceTest

tests/performance-tests/include/performance-tests/services/s3/S3PerformanceTest.h

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
#pragma once
77

8+
#include <aws/core/utils/memory/AWSMemory.h>
89
#include <aws/core/utils/memory/stl/AWSString.h>
910
#include <aws/s3/S3Client.h>
11+
#include <performance-tests/PerformanceTestBase.h>
1012

1113
#include <cstddef>
1214

@@ -17,46 +19,32 @@ namespace S3 {
1719
* Configuration for S3 performance test cases.
1820
*/
1921
struct TestCase {
20-
Aws::String sizeLabel;
22+
const char* sizeLabel;
2123
size_t sizeBytes;
22-
Aws::String bucketTypeLabel;
24+
const char* bucketTypeLabel;
2325
};
2426

2527
/**
26-
* Runs S3 performance test by creating a bucket, performing PutObject and GetObject operations,
27-
* then cleaning up resources.
28-
* @param s3 S3 client instance to use for operations
29-
* @param config Test configuration containing object size and bucket type parameters
30-
* @param availabilityZoneId Availability zone ID for S3 Express buckets
31-
* @param iterations Number of put/get operations to perform
28+
* S3 performance test implementation.
29+
* Tests PutObject and GetObject operations with different payload sizes and bucket types.
3230
*/
33-
void RunTest(Aws::S3::S3Client& s3, const TestCase& config, const Aws::String& availabilityZoneId, int iterations = 3);
34-
35-
/**
36-
* Create S3 bucket for testing.
37-
* @param s3 S3 client instance
38-
* @param config Test configuration
39-
* @param availabilityZoneId Availability zone ID for S3 Express buckets
40-
* @return Bucket name if successful, empty string if failed
41-
*/
42-
Aws::String SetupBucket(Aws::S3::S3Client& s3, const TestCase& config, const Aws::String& availabilityZoneId);
43-
44-
/**
45-
* Run PutObject and GetObject operations.
46-
* @param s3 S3 client instance
47-
* @param bucketName Name of the bucket to use
48-
* @param config Test configuration
49-
* @param iterations Number of operations to perform
50-
*/
51-
void RunOperations(Aws::S3::S3Client& s3, const Aws::String& bucketName, const TestCase& config, int iterations);
31+
class S3PerformanceTest : public PerformanceTestBase {
32+
public:
33+
S3PerformanceTest(const Aws::String& region, const TestCase& config, const Aws::String& availabilityZoneId, int iterations = 3);
34+
35+
void Setup() override;
36+
void TearDown() override;
37+
void Run() override;
38+
39+
private:
40+
const TestCase& m_config;
41+
const Aws::String m_region;
42+
const Aws::String m_availabilityZoneId;
43+
const int m_iterations;
44+
Aws::UniquePtr<Aws::S3::S3Client> m_s3;
45+
Aws::String m_bucketName;
46+
};
5247

53-
/**
54-
* Clean up S3 resources (objects and bucket).
55-
* @param s3 S3 client instance
56-
* @param bucketName Name of the bucket to clean up
57-
* @param iterations Number of objects to delete
58-
*/
59-
void CleanupResources(Aws::S3::S3Client& s3, const Aws::String& bucketName, int iterations);
6048
} // namespace S3
6149
} // namespace Services
6250
} // namespace PerformanceTest

tests/performance-tests/include/performance-tests/services/s3/S3TestConfig.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,25 @@
55

66
#pragma once
77

8-
#include <aws/core/utils/memory/stl/AWSSet.h>
9-
#include <aws/core/utils/memory/stl/AWSString.h>
10-
#include <aws/core/utils/memory/stl/AWSVector.h>
8+
#include <performance-tests/services/s3/S3PerformanceTest.h>
9+
10+
#include <array>
11+
#include <set>
1112

1213
namespace PerformanceTest {
1314
namespace Services {
1415
namespace S3 {
1516
namespace TestConfig {
16-
const Aws::Set<Aws::String> TestOperations = {"PutObject", "GetObject"};
17+
const std::set<const char*> TestOperations = {"PutObject", "GetObject"};
1718

18-
const Aws::Vector<TestCase> TestMatrix = {{"8KB", 8 * 1024, "s3-standard"}, {"64KB", 64 * 1024, "s3-standard"},
19-
{"1MB", 1024 * 1024, "s3-standard"}, {"8KB", 8 * 1024, "s3-express"},
20-
{"64KB", 64 * 1024, "s3-express"}, {"1MB", 1024 * 1024, "s3-express"}};
19+
const std::array<TestCase, 6> TestMatrix = {{{"8KB", 8 * 1024, "s3-standard"},
20+
{"64KB", 64 * 1024, "s3-standard"},
21+
{"1MB", 1024 * 1024, "s3-standard"},
22+
{"8KB", 8 * 1024, "s3-express"},
23+
{"64KB", 64 * 1024, "s3-express"},
24+
{"1MB", 1024 * 1024, "s3-express"}}};
2125

22-
const Aws::String OutputFilename = "s3-performance-test-results.json";
26+
const char* OutputFilename = "s3-performance-test-results.json";
2327
} // namespace TestConfig
2428
} // namespace S3
2529
} // namespace Services

tests/performance-tests/src/services/s3/S3PerformanceTest.cpp

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
* SPDX-License-Identifier: Apache-2.0.
44
*/
55

6+
#include <aws/core/client/ClientConfiguration.h>
67
#include <aws/core/utils/StringUtils.h>
8+
#include <aws/core/utils/logging/LogMacros.h>
9+
#include <aws/core/utils/memory/AWSMemory.h>
710
#include <aws/core/utils/memory/stl/AWSAllocator.h>
811
#include <aws/core/utils/memory/stl/AWSString.h>
912
#include <aws/core/utils/memory/stl/AWSStringStream.h>
@@ -21,92 +24,96 @@
2124
#include <performance-tests/Utils.h>
2225
#include <performance-tests/services/s3/S3PerformanceTest.h>
2326

24-
void PerformanceTest::Services::S3::RunTest(Aws::S3::S3Client& s3, const TestCase& config, const Aws::String& availabilityZoneId,
25-
int iterations) {
26-
auto bucketName = SetupBucket(s3, config, availabilityZoneId);
27-
if (bucketName.empty()) {
28-
return;
29-
}
27+
#include <cstring>
3028

31-
RunOperations(s3, bucketName, config, iterations);
32-
CleanupResources(s3, bucketName, iterations);
33-
}
29+
PerformanceTest::Services::S3::S3PerformanceTest::S3PerformanceTest(const Aws::String& region, const TestCase& config,
30+
const Aws::String& availabilityZoneId, int iterations)
31+
: m_config(config), m_region(region), m_availabilityZoneId(availabilityZoneId), m_iterations(iterations) {}
32+
33+
void PerformanceTest::Services::S3::S3PerformanceTest::Setup() {
34+
Aws::Client::ClientConfiguration cfg;
35+
cfg.region = m_region;
36+
m_s3 = Aws::MakeUnique<Aws::S3::S3Client>("S3PerformanceTest", cfg);
3437

35-
Aws::String PerformanceTest::Services::S3::SetupBucket(Aws::S3::S3Client& s3, const TestCase& config,
36-
const Aws::String& availabilityZoneId) {
37-
Aws::String bucketName;
3838
Aws::S3::Model::CreateBucketRequest cbr;
3939
Aws::String const bucketId = PerformanceTest::Utils::GenerateUniqueId();
4040

41-
if (config.bucketTypeLabel == "s3-express") {
42-
bucketName = "perf-express-" + bucketId + "--" + availabilityZoneId + "--x-s3";
43-
cbr.SetBucket(bucketName);
41+
if (strcmp(m_config.bucketTypeLabel, "s3-express") == 0) {
42+
m_bucketName = "perf-express-" + bucketId + "--" + m_availabilityZoneId + "--x-s3";
43+
cbr.SetBucket(m_bucketName);
4444
Aws::S3::Model::CreateBucketConfiguration bucketConfig;
4545
bucketConfig.SetLocation(
46-
Aws::S3::Model::LocationInfo().WithType(Aws::S3::Model::LocationType::AvailabilityZone).WithName(availabilityZoneId));
46+
Aws::S3::Model::LocationInfo().WithType(Aws::S3::Model::LocationType::AvailabilityZone).WithName(m_availabilityZoneId));
4747

4848
bucketConfig.SetBucket(Aws::S3::Model::BucketInfo()
4949
.WithType(Aws::S3::Model::BucketType::Directory)
5050
.WithDataRedundancy(Aws::S3::Model::DataRedundancy::SingleAvailabilityZone));
5151

5252
cbr.SetCreateBucketConfiguration(bucketConfig);
5353
} else {
54-
bucketName = "perf-standard-" + bucketId;
55-
cbr.SetBucket(bucketName);
54+
m_bucketName = "perf-standard-" + bucketId;
55+
cbr.SetBucket(m_bucketName);
5656
}
5757

58-
auto createOutcome = s3.CreateBucket(cbr);
58+
auto createOutcome = m_s3->CreateBucket(cbr);
5959
if (!createOutcome.IsSuccess()) {
60-
PerformanceTest::Utils::LogError("S3", "CreateBucket", createOutcome.GetError().GetMessage());
61-
return "";
60+
AWS_LOG_ERROR("PerformanceTest", ("S3:CreateBucket failed: " + createOutcome.GetError().GetMessage()).c_str());
61+
m_bucketName.clear();
6262
}
63-
64-
return bucketName;
6563
}
6664

67-
void PerformanceTest::Services::S3::RunOperations(Aws::S3::S3Client& s3, const Aws::String& bucketName, const TestCase& config,
68-
int iterations) {
69-
const auto randomPayload = PerformanceTest::Utils::RandomString(config.sizeBytes);
65+
void PerformanceTest::Services::S3::S3PerformanceTest::Run() {
66+
if (m_bucketName.empty()) {
67+
AWS_LOG_ERROR("PerformanceTest", "S3:Run - Bucket setup failed, skipping test");
68+
return;
69+
}
70+
71+
const auto randomPayload = PerformanceTest::Utils::RandomString(m_config.sizeBytes);
7072

7173
// Run PutObject multiple times
72-
for (int i = 0; i < iterations; i++) {
74+
for (int i = 0; i < m_iterations; i++) {
7375
auto stream = Aws::MakeShared<Aws::StringStream>("PerfStream");
7476
*stream << randomPayload;
7577

7678
Aws::S3::Model::PutObjectRequest por;
77-
por.WithBucket(bucketName).WithKey("test-object-" + Aws::Utils::StringUtils::to_string(i)).SetBody(stream);
78-
por.SetAdditionalCustomHeaderValue("test-dimension-size", config.sizeLabel);
79-
por.SetAdditionalCustomHeaderValue("test-dimension-bucket-type", config.bucketTypeLabel);
80-
auto putOutcome = s3.PutObject(por);
79+
por.WithBucket(m_bucketName).WithKey("test-object-" + Aws::Utils::StringUtils::to_string(i)).SetBody(stream);
80+
por.SetAdditionalCustomHeaderValue("test-dimension-size", m_config.sizeLabel);
81+
por.SetAdditionalCustomHeaderValue("test-dimension-bucket-type", m_config.bucketTypeLabel);
82+
auto putOutcome = m_s3->PutObject(por);
8183
if (!putOutcome.IsSuccess()) {
82-
PerformanceTest::Utils::LogError("S3", "PutObject", putOutcome.GetError().GetMessage());
84+
AWS_LOG_ERROR("PerformanceTest", ("S3:PutObject failed: " + putOutcome.GetError().GetMessage()).c_str());
8385
}
8486
}
8587

8688
// Run GetObject multiple times
87-
for (int i = 0; i < iterations; i++) {
89+
for (int i = 0; i < m_iterations; i++) {
8890
Aws::S3::Model::GetObjectRequest gor;
89-
gor.WithBucket(bucketName).WithKey("test-object-" + Aws::Utils::StringUtils::to_string(i));
90-
gor.SetAdditionalCustomHeaderValue("test-dimension-size", config.sizeLabel);
91-
gor.SetAdditionalCustomHeaderValue("test-dimension-bucket-type", config.bucketTypeLabel);
92-
auto getOutcome = s3.GetObject(gor);
91+
gor.WithBucket(m_bucketName).WithKey("test-object-" + Aws::Utils::StringUtils::to_string(i));
92+
gor.SetAdditionalCustomHeaderValue("test-dimension-size", m_config.sizeLabel);
93+
gor.SetAdditionalCustomHeaderValue("test-dimension-bucket-type", m_config.bucketTypeLabel);
94+
auto getOutcome = m_s3->GetObject(gor);
9395
if (!getOutcome.IsSuccess()) {
94-
PerformanceTest::Utils::LogError("S3", "GetObject", getOutcome.GetError().GetMessage());
96+
AWS_LOG_ERROR("PerformanceTest", ("S3:GetObject failed: " + getOutcome.GetError().GetMessage()).c_str());
9597
}
9698
}
9799
}
98100

99-
void PerformanceTest::Services::S3::CleanupResources(Aws::S3::S3Client& s3, const Aws::String& bucketName, int iterations) {
100-
for (int i = 0; i < iterations; i++) {
101-
auto deleteObjectOutcome = s3.DeleteObject(
102-
Aws::S3::Model::DeleteObjectRequest().WithBucket(bucketName).WithKey("test-object-" + Aws::Utils::StringUtils::to_string(i)));
101+
void PerformanceTest::Services::S3::S3PerformanceTest::TearDown() {
102+
if (m_bucketName.empty()) {
103+
AWS_LOG_ERROR("PerformanceTest", "S3:TearDown - No bucket to clean up, setup likely failed");
104+
return;
105+
}
106+
107+
for (int i = 0; i < m_iterations; i++) {
108+
auto deleteObjectOutcome = m_s3->DeleteObject(
109+
Aws::S3::Model::DeleteObjectRequest().WithBucket(m_bucketName).WithKey("test-object-" + Aws::Utils::StringUtils::to_string(i)));
103110
if (!deleteObjectOutcome.IsSuccess()) {
104-
PerformanceTest::Utils::LogError("S3", "DeleteObject", deleteObjectOutcome.GetError().GetMessage());
111+
AWS_LOG_ERROR("PerformanceTest", ("S3:DeleteObject failed: " + deleteObjectOutcome.GetError().GetMessage()).c_str());
105112
}
106113
}
107114

108-
auto deleteBucketOutcome = s3.DeleteBucket(Aws::S3::Model::DeleteBucketRequest().WithBucket(bucketName));
115+
auto deleteBucketOutcome = m_s3->DeleteBucket(Aws::S3::Model::DeleteBucketRequest().WithBucket(m_bucketName));
109116
if (!deleteBucketOutcome.IsSuccess()) {
110-
PerformanceTest::Utils::LogError("S3", "DeleteBucket", deleteBucketOutcome.GetError().GetMessage());
117+
AWS_LOG_ERROR("PerformanceTest", ("S3:DeleteBucket failed: " + deleteBucketOutcome.GetError().GetMessage()).c_str());
111118
}
112119
}

0 commit comments

Comments
 (0)