Skip to content

Commit bcf59dc

Browse files
committed
Benchmarking init client and create bucket
1 parent dcf42ee commit bcf59dc

6 files changed

Lines changed: 165 additions & 35 deletions

File tree

‎benchmark/Makefile‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ AWS_SDK_CPP_PREFIX := $(shell brew --prefix aws-sdk-cpp)
3030
AWS_SDK_CPP_DEPS := aws-sdk-cpp $(shell brew deps aws-sdk-cpp)
3131
AWS_SDK_CPP_INCLUDES := $(foreach dep,$(AWS_SDK_CPP_DEPS),-I$(shell brew --prefix $(dep))/include)
3232

33+
GOOGLE_BENCHMARK_PREFIX := $(shell brew --prefix google-benchmark)
34+
3335
$(CPP_LIB): | $(BUILD_DIR)
3436
c++ -std=c++26 -shared -fPIC \
3537
$(AWS_SDK_CPP_INCLUDES) \
@@ -51,10 +53,15 @@ $(IMPLEMENTATIONS_INC): $(GO_LIB) $(CPP_LIB) $(RUST_LIB) $(S3CPP_LIB) | $(BUILD_
5153
printf '"./%s",\n' $(GO_LIB) $(CPP_LIB) $(RUST_LIB) $(S3CPP_LIB) > $@
5254

5355
bench: $(IMPLEMENTATIONS_INC) $(GO_LIB) $(CPP_LIB) $(RUST_LIB) $(S3CPP_LIB) | $(BUILD_DIR)
54-
c++ -std=c++26 main.cpp -o $(BUILD_DIR)/bench
56+
c++ -std=c++26 -I../src benchmark.cpp -o $(BUILD_DIR)/bench \
57+
-I$(GOOGLE_BENCHMARK_PREFIX)/include -L$(GOOGLE_BENCHMARK_PREFIX)/lib \
58+
../build/lib/libs3cpp.a -lbenchmark $(shell pkg-config --libs libcurl libcrypto)
59+
./$(BUILD_DIR)/bench
60+
5561

5662
test: $(IMPLEMENTATIONS_INC) $(GO_LIB) $(S3CPP_LIB) $(RUST_LIB) | $(BUILD_DIR)
5763
c++ -std=c++26 -I../src test.cpp -o $(BUILD_DIR)/test ../build/lib/libs3cpp.a $(shell pkg-config --libs libcurl libcrypto)
64+
./$(BUILD_DIR)/test
5865

5966

6067
.PHONY: all clean aws-sdk-cpp

‎benchmark/README.md‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ This directory benchmarks multiple AWS S3 SDKs by lowering implementations to a
66

77
## Prerequisite
88

9+
```bash
10+
brew install aws-sdk-cpp google-benchmark
11+
```
12+
913
A local MinIO instance is expected to be running already. The current `test.cpp` uses `s3cpp` itself as a preamble to create basic scaffolding for the tests before calling each shared library implementation
1014

1115
```bash
@@ -22,15 +26,17 @@ $ docker run -d -p 9000:9000 -p 9001:9001 \
2226
Build all currently enabled shared libraries:
2327

2428
```bash
25-
$ make
29+
make
2630
```
2731

2832
Tests that shared libraries are built:
2933
```bash
30-
$ make test
31-
$ ./build/test
32-
...
33-
Good to go!
34+
make test
35+
```
36+
37+
Run full benchmark against all supported SDKs:
38+
```bash
39+
make bench
3440
```
3541

3642
## Notes

‎benchmark/benchmark.cpp‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include "implementations.h"
2+
#include <benchmark/benchmark.h>
3+
#include <filesystem>
4+
#include <print>
5+
#include <string>
6+
7+
namespace s3b {
8+
9+
static void benchmark_init_client(::benchmark::State &state, s3b::implementation impl) {
10+
const std::string access_ = "minio_access";
11+
const std::string secret_ = "minio_secret";
12+
const std::string endpoint_ = "127.0.0.1:9000";
13+
for (auto _ : state) {
14+
::benchmark::DoNotOptimize(impl.init_client("minio_access", "minio_secret", "127.0.0.1:9000"));
15+
}
16+
}
17+
18+
static void benchmark_create_bucket(::benchmark::State &state, s3b::implementation impl) {
19+
// TODO(cristian): Client handler should be stored on the implementation
20+
// struct so that we only have one client at a time initialized, shouldn't
21+
// affect the benches but who knows
22+
bench::ClientHandle handle = impl.init_client("minio_access", "minio_secret", "127.0.0.1:9000");
23+
24+
// Ugly way of avoiding BucketAlreadyOwnedByYou error
25+
static std::atomic<int> run_id{0};
26+
int run = run_id++;
27+
int i = 0;
28+
29+
for (auto _ : state) {
30+
state.PauseTiming();
31+
auto bucket = std::format("bench-{}-{}-{}", s3b::bucket_name_for(impl.name), run, i++);
32+
state.ResumeTiming();
33+
impl.create_bucket(handle, bucket.c_str());
34+
}
35+
}
36+
37+
static std::string get_benchmark_name(const std::string &aws_operation, const implementation &impl) {
38+
const std::string so_name = std::filesystem::path(impl.name).stem();
39+
const std::string bench_name = std::format("BENCHMARK_{}_{}", so_name, aws_operation);
40+
return bench_name;
41+
}
42+
43+
} // namespace s3b
44+
45+
int main(int argc, char *argv[]) {