Skip to content

Commit d56133c

Browse files
committed
batching benchmark and initial API for #18: error handling and observability of the async API
1 parent 295fbae commit d56133c

18 files changed

+1282
-54
lines changed

CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,10 @@ if(TARGET OpenSSL::SSL AND USE_CONAN)
236236

237237
# Add the include directory directly to our target
238238
# This is critical because Boost's ASIO SSL tries to include openssl headers directly
239+
# Use PRIVATE since OpenSSL is only needed for the library's implementation, not its public API
239240
if(_OPENSSL_INCLUDE_DIR AND EXISTS "${_OPENSSL_INCLUDE_DIR}")
240241
target_include_directories(influxdb-cpp-rest PRIVATE "${_OPENSSL_INCLUDE_DIR}")
241-
message(STATUS "Added OpenSSL include directory to influxdb-cpp-rest: ${_OPENSSL_INCLUDE_DIR}")
242+
message(STATUS "Added OpenSSL include directory to influxdb-cpp-rest (PRIVATE): ${_OPENSSL_INCLUDE_DIR}")
242243
else()
243244
message(WARNING "Could not find OpenSSL include directory - compilation may fail")
244245
message(WARNING "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
@@ -265,6 +266,7 @@ if(USE_CONAN)
265266
${CONAN_LIBS}
266267
)
267268
endif()
269+
# OpenSSL includes are inherited from influxdb-cpp-rest via INTERFACE, so no need to add again
268270
target_compile_definitions(influx-c-rest PRIVATE BUILDING_INFLUX_C_REST)
269271

270272
# Put DLL in bin directory (matching test executable location) so tests can find it
@@ -453,19 +455,19 @@ if(BUILD_BENCHMARK)
453455
# Benchmark output directory - match test executables location
454456
if(CMAKE_CONFIGURATION_TYPES)
455457
# Multi-config generator (Visual Studio, Xcode)
456-
set_target_properties(format_benchmark db_insert_benchmark
458+
set_target_properties(format_benchmark db_insert_benchmark db_batch_benchmark
457459
PROPERTIES
458460
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/$<CONFIG>"
459461
)
460462
else()
461463
# Single-config generator
462464
if(CMAKE_BUILD_TYPE)
463-
set_target_properties(format_benchmark db_insert_benchmark
465+
set_target_properties(format_benchmark db_insert_benchmark db_batch_benchmark
464466
PROPERTIES
465467
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}"
466468
)
467469
else()
468-
set_target_properties(format_benchmark db_insert_benchmark
470+
set_target_properties(format_benchmark db_insert_benchmark db_batch_benchmark
469471
PROPERTIES
470472
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
471473
)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ See [the demo source](src/demo/main.cpp) for the current api example.
2020

2121
The unbatched approach (and without connection reuse) may not be sufficient in some situations, as without batching, about 200 lines/sec can be inserted.
2222

23-
A batching api leans towards thousands inserts per second. Behind the scenes, the API uses [RxCpp](https://github.com/Reactive-Extensions/RxCpp) and [cppformat](https://github.com/fmtlib/fmt).
23+
An async batching api targets thousands inserts per second. Behind the scenes, the API uses [RxCpp](https://github.com/Reactive-Extensions/RxCpp) and [cppformat](https://github.com/fmtlib/fmt).
2424

2525
## Status
2626

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
# Download and extract InfluxDB binary
3+
# Usage: download-influxdb.sh <version> <architecture>
4+
# Example: download-influxdb.sh 1.8.10 darwin_amd64
5+
6+
set -euo pipefail
7+
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
10+
11+
cd "${PROJECT_ROOT}"
12+
13+
CMAKE_ARGS="-DBUILD_BENCHMARK=ON" ./scripts/build.sh
14+
15+
./build/bin/Release/db_batch_benchmark
16+

scripts/stop-influxdb-native.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env bash
2+
# Stop native InfluxDB and optionally clean up storage
3+
# Usage: stop-influxdb-native.sh [--clean]
4+
5+
set -euo pipefail
6+
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
9+
10+
cd "${PROJECT_ROOT}"
11+
12+
CLEAN_STORAGE=false
13+
if [ "${1:-}" = "--clean" ]; then
14+
CLEAN_STORAGE=true
15+
fi
16+
17+
# Find InfluxDB process
18+
INFLUXDB_PID=$(pgrep -f "influxd.*-config.*influxdb.conf" || echo "")
19+
20+
if [ -z "${INFLUXDB_PID}" ]; then
21+
echo "No InfluxDB process found running with influxdb.conf"
22+
# Still try to clean if requested
23+
if [ "$CLEAN_STORAGE" = true ]; then
24+
if [ -d ".influxdb" ]; then
25+
echo "Cleaning up InfluxDB storage..."
26+
rm -rf .influxdb
27+
echo "✓ InfluxDB storage cleaned"
28+
else
29+
echo "No .influxdb directory found"
30+
fi
31+
fi
32+
exit 0
33+
fi
34+
35+
echo "Stopping InfluxDB (PID: ${INFLUXDB_PID})..."
36+
37+
# Try graceful shutdown first
38+
kill "${INFLUXDB_PID}" 2>/dev/null || true
39+
40+
# Wait for process to exit
41+
timeout=10
42+
elapsed=0
43+
while [ $elapsed -lt $timeout ]; do
44+
if ! kill -0 "${INFLUXDB_PID}" 2>/dev/null; then
45+
echo "✓ InfluxDB stopped gracefully"
46+
break
47+
fi
48+
sleep 1
49+
elapsed=$((elapsed + 1))
50+
done
51+
52+
# Force kill if still running
53+
if kill -0 "${INFLUXDB_PID}" 2>/dev/null; then
54+
echo "Force killing InfluxDB..."
55+
kill -9 "${INFLUXDB_PID}" 2>/dev/null || true
56+
sleep 1
57+
echo "✓ InfluxDB force stopped"
58+
fi
59+
60+
# Clean up storage if requested
61+
if [ "$CLEAN_STORAGE" = true ]; then
62+
if [ -d ".influxdb" ]; then
63+
echo "Cleaning up InfluxDB storage..."
64+
rm -rf .influxdb
65+
echo "✓ InfluxDB storage cleaned (removed .influxdb directory)"
66+
else
67+
echo "No .influxdb directory found"
68+
fi
69+
else
70+
echo "Storage preserved at .influxdb/"
71+
echo "To clean storage, run: $0 --clean"
72+
fi
73+

scripts/test.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,31 @@ set -euo pipefail
44
BUILD_DIR="${BUILD_DIR:-build}"
55
BUILD_TYPE="${BUILD_TYPE:-Release}"
66

7+
# Build before testing to ensure we're using the latest code
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
10+
cd "${PROJECT_ROOT}"
11+
12+
echo "Building project (${BUILD_TYPE})..."
13+
# First configure (if needed)
14+
"${SCRIPT_DIR}/build.sh" >/dev/null 2>&1 || true
15+
16+
# Then build the test targets - this will show compilation errors
17+
echo "Compiling test targets..."
18+
cd "${BUILD_DIR}"
19+
if ! make test-influxdb-cpp-rest test-influx-c-rest test-influxdb-cpp-auth -j4 2>&1; then
20+
echo "" >&2
21+
echo "Build failed! Fix compilation errors above before running tests." >&2
22+
exit 1
23+
fi
24+
cd "${PROJECT_ROOT}"
25+
726
# Determine possible binary directories
27+
# Prefer BUILD_TYPE-specific directories first (they contain the most recent builds)
828
BIN_DIRS=(
9-
"${BUILD_DIR}/bin"
1029
"${BUILD_DIR}/bin/${BUILD_TYPE}"
1130
"${BUILD_DIR}/${BUILD_TYPE}/bin"
31+
"${BUILD_DIR}/bin"
1232
"${BUILD_DIR}"
1333
)
1434

src/benchmark/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,14 @@ if(USE_CONAN)
3131
target_link_libraries(db_insert_benchmark PRIVATE ${CONAN_LIBS})
3232
endif()
3333

34+
# Database batch strategy benchmark (requires InfluxDB)
35+
add_executable(db_batch_benchmark db_batch_benchmark.cpp)
36+
target_compile_features(db_batch_benchmark PRIVATE cxx_std_20)
37+
target_link_libraries(db_batch_benchmark PRIVATE
38+
benchmark::benchmark
39+
influxdb-cpp-rest
40+
)
41+
if(USE_CONAN)
42+
target_link_libraries(db_batch_benchmark PRIVATE ${CONAN_LIBS})
43+
endif()
44+

0 commit comments

Comments
 (0)