diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt new file mode 100644 index 00000000..4ab570d9 --- /dev/null +++ b/benchmarks/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.5) + +project(serverless-benchmarks) + +# Set up the C++ compiler options +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +# Add the benchmark library +add_subdirectory(benchmark) + +# Add your project executable +add_executable(cpp_benchmark cpp_benchmark.cpp) + +# Link your executable with the benchmark library +target_link_libraries(cpp_benchmark benchmark) diff --git a/benchmarks/cpp_benchmarks.cpp b/benchmarks/cpp_benchmarks.cpp new file mode 100644 index 00000000..2600216e --- /dev/null +++ b/benchmarks/cpp_benchmarks.cpp @@ -0,0 +1,101 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Include the benchmark library +#include + +// Include the AWS SDK +#include +#include +#include +#include +#include +#include + +// Define a map to store the benchmark results +std::map> overall_results; + +// Define the setup function for the benchmark +void setup(benchmark::State& state) { + // Set up compile and run commands for the C++ benchmark + std::vector compile_cmd = {"g++", "-std=c++11", "-O3", "-DNDEBUG", "-I./benchmark/include", "cpp_benchmark.cpp", "-o", "cpp_benchmark"}; + std::vector run_cmd = {"./cpp_benchmark", "--benchmark_format=json"}; + + // Compile the C++ benchmark + std::ostringstream compile_out; + int compile_ret = benchmark::RunSpecifiedCommand(compile_cmd, &compile_out); + if (compile_ret != 0) { + std::cerr << "Failed to compile C++ benchmark:\n" << compile_out.str() << std::endl; + return; + } + + // Set up the Lambda client + Aws::SDKOptions options; + Aws::InitAPI(options); + Aws::Client::ClientConfiguration clientConfig; + Aws::Lambda::LambdaClient lambdaClient(clientConfig); + + // Build the request to create the Lambda function + Aws::Lambda::Model::CreateFunctionRequest createRequest; + createRequest.SetFunctionName("cpp_benchmark"); + createRequest.SetRuntime("provided"); + createRequest.SetRole("arn:aws:iam::123456789012:role/lambda-role"); + createRequest.SetHandler("cpp_benchmark.handler"); + createRequest.SetCode(Aws::Lambda::Model::FunctionCode().WithZipFile("path/to/cpp_benchmark.zip")); + + // Create the Lambda function + auto createOutcome = lambdaClient.CreateFunction(createRequest); + if (!createOutcome.IsSuccess()) { + std::cerr << "Failed to create Lambda function: " << createOutcome.GetError().GetMessage() << std::endl; + return; + } + + // Build the request to invoke the Lambda function + Aws::Lambda::Model::InvokeRequest invokeRequest; + invokeRequest.SetFunctionName("cpp_benchmark"); + invokeRequest.SetInvocationType(Aws::Lambda::Model::InvocationType::RequestResponse); + + // Invoke the Lambda function and store the results + auto invokeOutcome = lambdaClient.Invoke(invokeRequest); + if (!invokeOutcome.IsSuccess()) { + std::cerr << "Failed to invoke Lambda function: " << invokeOutcome.GetError().GetMessage() << std::endl; + return; + } + + // Parse the output of the Lambda function and store the results + Aws::String result = invokeOutcome.GetResult().GetPayload().AsString(); + Aws::Utils::Json::JsonValue jsonResult(result.c_str()); + + for (const auto& benchmark : jsonResult.GetObject()) { + std::string benchmark_name = benchmark.GetName(); + double benchmark_time = benchmark.GetValue().AsDouble() / benchmark::kNumIterations; + + overall_results[benchmark_name]["cpp"] = benchmark_time; + } + + // Delete the Lambda function + Aws::Lambda::Model::DeleteFunctionRequest deleteRequest; + deleteRequest.SetFunctionName("cpp_benchmark"); + lambdaClient.DeleteFunction(deleteRequest); + + // Print the benchmark results + std::cout << "Benchmark Results:\n"; + std::cout << std::setw(20) << std::left << "Benchmark Name" << std::setw(15) << std::right << "Local (ms)" << std::setw(15) << std::right << "AWS Lambda (ms)" << std::endl; + std::cout << "------------------------------------------------------\n"; + for (const auto& benchmark : overall_results) { + std::cout << std::setw(20) << std::left << benchmark.first << std::fixed << std::setprecision(2) << std::setw(15) << std::right << benchmark.second["cpp"] << std::setw(15) << std::right << benchmark.second["aws_lambda"] << std::endl; + } + + // Shut down the AWS SDK + Aws::ShutdownAPI(options); +} + +BENCHMARK(setup); + diff --git a/dockerfiles/aws/nodejs/Dockerfile.build b/dockerfiles/aws/nodejs/Dockerfile.build deleted file mode 100755 index ce0549e7..00000000 --- a/dockerfiles/aws/nodejs/Dockerfile.build +++ /dev/null @@ -1,20 +0,0 @@ -ARG BASE_IMAGE -FROM ${BASE_IMAGE} - -# useradd, groupmod -RUN yum install -y shadow-utils -ENV GOSU_VERSION 1.14 -# https://github.com/tianon/gosu/releases/tag/1.14 -# key https://keys.openpgp.org/search?q=tianon%40debian.org -RUN curl -o /usr/local/bin/gosu -SL "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-amd64" \ - && chmod +x /usr/local/bin/gosu -RUN mkdir -p /sebs/ -COPY dockerfiles/nodejs_installer.sh /sebs/installer.sh -COPY dockerfiles/entrypoint.sh /sebs/entrypoint.sh -RUN chmod +x /sebs/entrypoint.sh - -# useradd and groupmod is installed in /usr/sbin which is not in PATH -ENV PATH=/usr/sbin:$PATH -ENV SCRIPT_FILE=/mnt/function/package.sh -CMD /bin/bash /sebs/installer.sh -ENTRYPOINT ["/sebs/entrypoint.sh"] diff --git a/dockerfiles/aws/python/Dockerfile.build b/dockerfiles/aws/python/Dockerfile.build deleted file mode 100755 index 97e9b296..00000000 --- a/dockerfiles/aws/python/Dockerfile.build +++ /dev/null @@ -1,22 +0,0 @@ -ARG BASE_IMAGE -FROM ${BASE_IMAGE} -ARG VERSION -ENV PYTHON_VERSION=${VERSION} - -# useradd, groupmod -RUN yum install -y shadow-utils -ENV GOSU_VERSION 1.14 -# https://github.com/tianon/gosu/releases/tag/1.14 -# key https://keys.openpgp.org/search?q=tianon%40debian.org -RUN curl -o /usr/local/bin/gosu -SL "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-amd64" \ - && chmod +x /usr/local/bin/gosu -RUN mkdir -p /sebs/ -COPY dockerfiles/python_installer.sh /sebs/installer.sh -COPY dockerfiles/entrypoint.sh /sebs/entrypoint.sh -RUN chmod +x /sebs/entrypoint.sh - -# useradd and groupmod is installed in /usr/sbin which is not in PATH -ENV PATH=/usr/sbin:$PATH -ENV SCRIPT_FILE=/mnt/function/package.sh -CMD /bin/bash /sebs/installer.sh -ENTRYPOINT ["/sebs/entrypoint.sh"]