From 6cd799aaa644e8dca073797dd66064558b14255f Mon Sep 17 00:00:00 2001 From: Aarti_pandey <114875857+Aartipandey01@users.noreply.github.com> Date: Fri, 7 Apr 2023 01:03:06 +0530 Subject: [PATCH 01/18] Update Dockerfile.build --- dockerfiles/aws/nodejs/Dockerfile.build | 31 +++++++++++-------------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/dockerfiles/aws/nodejs/Dockerfile.build b/dockerfiles/aws/nodejs/Dockerfile.build index ce0549e7..0593f561 100755 --- a/dockerfiles/aws/nodejs/Dockerfile.build +++ b/dockerfiles/aws/nodejs/Dockerfile.build @@ -1,20 +1,15 @@ -ARG BASE_IMAGE -FROM ${BASE_IMAGE} +ARG BASE_IMAGE=node:14-alpine -# 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 +FROM ${BASE_IMAGE} AS build +WORKDIR /app +COPY package*.json ./ +RUN npm install +COPY . . +RUN npm run build -# 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"] +FROM ${BASE_IMAGE} +WORKDIR /app +COPY --from=build /app/dist ./dist +COPY package*.json ./ +RUN npm install --production +CMD ["npm", "run", "start"] From dc69f6c729bc3470e3f337e70de8d1fcf1ef86f1 Mon Sep 17 00:00:00 2001 From: Atul Rajput <92659293+AtulRajput01@users.noreply.github.com> Date: Fri, 7 Apr 2023 01:23:34 +0530 Subject: [PATCH 02/18] Update Dockerfile.build --- dockerfiles/aws/nodejs/Dockerfile.build | 44 ++++++++++++++++--------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/dockerfiles/aws/nodejs/Dockerfile.build b/dockerfiles/aws/nodejs/Dockerfile.build index 0593f561..cc3d23fc 100755 --- a/dockerfiles/aws/nodejs/Dockerfile.build +++ b/dockerfiles/aws/nodejs/Dockerfile.build @@ -1,15 +1,29 @@ -ARG BASE_IMAGE=node:14-alpine - -FROM ${BASE_IMAGE} AS build -WORKDIR /app -COPY package*.json ./ -RUN npm install -COPY . . -RUN npm run build - -FROM ${BASE_IMAGE} -WORKDIR /app -COPY --from=build /app/dist ./dist -COPY package*.json ./ -RUN npm install --production -CMD ["npm", "run", "start"] +# Use Alpine base image +FROM alpine + +# Install useradd and groupmod shadow package +RUN apk add --no-cache shadow + +# Set environment variable +ENV GOSU_VERSION 1.14 + +# Download and install gosu +# 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 + +# Create directory for our script and copy it to +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 + +# Set the PATH environment variable to include /usr/sbin so that useradd and groupmod can be used +ENV PATH=/usr/sbin:$PATH + +# Set the SCRIPT_FILE environment variable to the location of our package +ENV SCRIPT_FILE=/mnt/function/package.sh + +# Set the command to run our installer in the box +CMD /bin/bash /sebs/installer.sh From e18fb2da06e1924965a218aa451d3034498e5a88 Mon Sep 17 00:00:00 2001 From: Atul Rajput <92659293+AtulRajput01@users.noreply.github.com> Date: Fri, 7 Apr 2023 01:38:37 +0530 Subject: [PATCH 03/18] Update Dockerfile.build Using alpine image instead of {BASE_IMAGE} to reduce image size and increase security --- dockerfiles/aws/python/Dockerfile.build | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/dockerfiles/aws/python/Dockerfile.build b/dockerfiles/aws/python/Dockerfile.build index 97e9b296..476ab42a 100755 --- a/dockerfiles/aws/python/Dockerfile.build +++ b/dockerfiles/aws/python/Dockerfile.build @@ -1,22 +1,32 @@ -ARG BASE_IMAGE -FROM ${BASE_IMAGE} +FROM alpine ARG VERSION ENV PYTHON_VERSION=${VERSION} -# useradd, groupmod -RUN yum install -y shadow-utils +# Install useradd and groupmod shadow package +RUN apk add --no-cache shadow + +# Set environment variable ENV GOSU_VERSION 1.14 + +# Download and install gosu # https://github.com/tianon/gosu/releases/tag/1.14 -# key https://keys.openpgp.org/search?q=tianon%40debian.org +# 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 + +# Create directory for our script and copy it to 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 +# Set the PATH environment variable to include /usr/sbin so that useradd and groupmod can be used ENV PATH=/usr/sbin:$PATH + +# Set the SCRIPT_FILE environment variable to the location of our package ENV SCRIPT_FILE=/mnt/function/package.sh + +# Set the command to run our installer in the box CMD /bin/bash /sebs/installer.sh + ENTRYPOINT ["/sebs/entrypoint.sh"] From 9f44a3cdf64d890df9cc768ac94d132a310da4ad Mon Sep 17 00:00:00 2001 From: Atul Rajput <92659293+AtulRajput01@users.noreply.github.com> Date: Sun, 9 Apr 2023 03:21:24 +0530 Subject: [PATCH 04/18] Create cpp_benchmarks.cpp --- benchmarks/cpp_benchmarks.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 benchmarks/cpp_benchmarks.cpp diff --git a/benchmarks/cpp_benchmarks.cpp b/benchmarks/cpp_benchmarks.cpp new file mode 100644 index 00000000..7b4d0166 --- /dev/null +++ b/benchmarks/cpp_benchmarks.cpp @@ -0,0 +1,22 @@ +## .py benchmark example + +import subprocess + +def run_python_benchmarks(): + # Run Python benchmarks using existing benchmarking script + ... + +def run_nodejs_benchmarks(): + # Run Node.js benchmarks using existing benchmarking script + ... + +def run_cpp_benchmarks(): + # Run C++ benchmarks using subprocess module + cpp_benchmarks_proc = subprocess.Popen(['./cpp_benchmarks'], stdout=subprocess.PIPE) + cpp_benchmarks_output = cpp_benchmarks_proc.stdout.read() + print(cpp_benchmarks_output) + +if __name__ == '__main__': + run_python_benchmarks() + run_nodejs_benchmarks() + run_cpp_benchmarks() From d8eb95756b14c25bc8f6dfec5d57ec9bcede60dc Mon Sep 17 00:00:00 2001 From: Atul Rajput <92659293+AtulRajput01@users.noreply.github.com> Date: Sun, 9 Apr 2023 03:26:01 +0530 Subject: [PATCH 05/18] Update cpp_benchmarks.cpp --- benchmarks/cpp_benchmarks.cpp | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/benchmarks/cpp_benchmarks.cpp b/benchmarks/cpp_benchmarks.cpp index 7b4d0166..5083c42b 100644 --- a/benchmarks/cpp_benchmarks.cpp +++ b/benchmarks/cpp_benchmarks.cpp @@ -1,22 +1,14 @@ -## .py benchmark example +#include -import subprocess +static void BM_FunctionName(benchmark::State& state) { + // Setup code here + for (auto _ : state) { + // Code to benchmark here + } + // Teardown code here +} -def run_python_benchmarks(): - # Run Python benchmarks using existing benchmarking script - ... +BENCHMARK(BM_FunctionName); -def run_nodejs_benchmarks(): - # Run Node.js benchmarks using existing benchmarking script - ... +BENCHMARK_MAIN(); -def run_cpp_benchmarks(): - # Run C++ benchmarks using subprocess module - cpp_benchmarks_proc = subprocess.Popen(['./cpp_benchmarks'], stdout=subprocess.PIPE) - cpp_benchmarks_output = cpp_benchmarks_proc.stdout.read() - print(cpp_benchmarks_output) - -if __name__ == '__main__': - run_python_benchmarks() - run_nodejs_benchmarks() - run_cpp_benchmarks() From a9a8be39786c47e4622038d2622187aec76b3728 Mon Sep 17 00:00:00 2001 From: Atul Rajput <92659293+AtulRajput01@users.noreply.github.com> Date: Sun, 9 Apr 2023 03:27:43 +0530 Subject: [PATCH 06/18] Update cpp_benchmarks.cpp --- benchmarks/cpp_benchmarks.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/benchmarks/cpp_benchmarks.cpp b/benchmarks/cpp_benchmarks.cpp index 5083c42b..a7c0ae36 100644 --- a/benchmarks/cpp_benchmarks.cpp +++ b/benchmarks/cpp_benchmarks.cpp @@ -1,6 +1,6 @@ #include -static void BM_FunctionName(benchmark::State& state) { +static void Setup(benchmark::State& state) { // Setup code here for (auto _ : state) { // Code to benchmark here @@ -8,7 +8,7 @@ static void BM_FunctionName(benchmark::State& state) { // Teardown code here } -BENCHMARK(BM_FunctionName); +BENCHMARK(Setup); BENCHMARK_MAIN(); From 33d0ae115c527ef5fb4c58f6847db4124253c38d Mon Sep 17 00:00:00 2001 From: Atul Rajput <92659293+AtulRajput01@users.noreply.github.com> Date: Sun, 9 Apr 2023 03:40:09 +0530 Subject: [PATCH 07/18] Update cpp_benchmarks.cpp --- benchmarks/cpp_benchmarks.cpp | 73 +++++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 7 deletions(-) diff --git a/benchmarks/cpp_benchmarks.cpp b/benchmarks/cpp_benchmarks.cpp index a7c0ae36..56b323b6 100644 --- a/benchmarks/cpp_benchmarks.cpp +++ b/benchmarks/cpp_benchmarks.cpp @@ -1,14 +1,73 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include -static void Setup(benchmark::State& state) { - // Setup code here - for (auto _ : state) { - // Code to benchmark here +void run_cpp_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"}; + + 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; + } + + std::ostringstream run_out; + int run_ret = benchmark::RunSpecifiedCommand(run_cmd, &run_out); + if (run_ret != 0) { + std::cerr << "Failed to run C++ benchmark:\n" << run_out.str() << std::endl; + return; + } + + std::string output = run_out.str(); + std::istringstream ss(output); + std::string line; + + while (std::getline(ss, line)) { + std::istringstream ls(line); + std::string field, value; + std::getline(ls, field, ':'); + std::getline(ls, value, ','); + + if (field == "\"name\"") { + std::string benchmark_name = value.substr(1, value.size() - 2); + double benchmark_time = 0.0; + + while (std::getline(ss, line) && line != "},") { + std::istringstream ls(line); + std::string field, value; + std::getline(ls, field, ':'); + std::getline(ls, value, ','); + + if (field == "\"real_time\"") { + benchmark_time = std::stod(value) / benchmark::kNumIterations; + } + } + + overall_results[benchmark_name]["cpp"] = benchmark_time; + } } - // Teardown code here } -BENCHMARK(Setup); +// ... -BENCHMARK_MAIN(); +int main(int argc, char** argv) { + // ... + // Run the C++ benchmark + run_cpp_benchmark(); + + // Print the overall results + // ... + + return 0; +} From c5b1f435f1bb78cfee891839a23b7f0888a9d78c Mon Sep 17 00:00:00 2001 From: Atul Rajput <92659293+AtulRajput01@users.noreply.github.com> Date: Sun, 9 Apr 2023 03:53:46 +0530 Subject: [PATCH 08/18] Update cpp_benchmarks.cpp --- benchmarks/cpp_benchmarks.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/benchmarks/cpp_benchmarks.cpp b/benchmarks/cpp_benchmarks.cpp index 56b323b6..5685f8cd 100644 --- a/benchmarks/cpp_benchmarks.cpp +++ b/benchmarks/cpp_benchmarks.cpp @@ -10,7 +10,7 @@ #include -void run_cpp_benchmark() { +void setup(benchmark::State& state) { 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"}; @@ -56,6 +56,8 @@ void run_cpp_benchmark() { overall_results[benchmark_name]["cpp"] = benchmark_time; } } + + for (auto _ : state) {} } // ... @@ -64,7 +66,10 @@ int main(int argc, char** argv) { // ... // Run the C++ benchmark - run_cpp_benchmark(); + benchmark::RegisterBenchmark("cpp", setup)->Unit(benchmark::kMillisecond); + + benchmark::Initialize(&argc, argv); + benchmark::RunSpecifiedBenchmarks(); // Print the overall results // ... From 95961eecac0199532a18e591488c99a3f381b61f Mon Sep 17 00:00:00 2001 From: Atul Rajput <92659293+AtulRajput01@users.noreply.github.com> Date: Sun, 9 Apr 2023 11:33:55 +0530 Subject: [PATCH 09/18] Update cpp_benchmarks.cpp --- benchmarks/cpp_benchmarks.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/benchmarks/cpp_benchmarks.cpp b/benchmarks/cpp_benchmarks.cpp index 5685f8cd..3ba2877a 100644 --- a/benchmarks/cpp_benchmarks.cpp +++ b/benchmarks/cpp_benchmarks.cpp @@ -1,3 +1,4 @@ + #include #include #include From 6a233ff720d8bca912b6548f364a1b04fdb55488 Mon Sep 17 00:00:00 2001 From: Atul Rajput <92659293+AtulRajput01@users.noreply.github.com> Date: Sun, 9 Apr 2023 11:39:25 +0530 Subject: [PATCH 10/18] Update cpp_benchmarks.cpp --- benchmarks/cpp_benchmarks.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/benchmarks/cpp_benchmarks.cpp b/benchmarks/cpp_benchmarks.cpp index 3ba2877a..d868f959 100644 --- a/benchmarks/cpp_benchmarks.cpp +++ b/benchmarks/cpp_benchmarks.cpp @@ -1,4 +1,3 @@ - #include #include #include @@ -12,9 +11,11 @@ #include 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) { @@ -22,6 +23,7 @@ void setup(benchmark::State& state) { return; } + // Run the C++ benchmark std::ostringstream run_out; int run_ret = benchmark::RunSpecifiedCommand(run_cmd, &run_out); if (run_ret != 0) { @@ -29,10 +31,10 @@ void setup(benchmark::State& state) { return; } + // Parse the output of the C++ benchmark and store the results std::string output = run_out.str(); std::istringstream ss(output); std::string line; - while (std::getline(ss, line)) { std::istringstream ls(line); std::string field, value; @@ -40,9 +42,11 @@ void setup(benchmark::State& state) { std::getline(ls, value, ','); if (field == "\"name\"") { + // Extract the name of the benchmark std::string benchmark_name = value.substr(1, value.size() - 2); double benchmark_time = 0.0; + // Extract the real time taken by the benchmark while (std::getline(ss, line) && line != "},") { std::istringstream ls(line); std::string field, value; @@ -54,10 +58,12 @@ void setup(benchmark::State& state) { } } + // Store the benchmark results overall_results[benchmark_name]["cpp"] = benchmark_time; } } + // Run the benchmarking loop (this loop is empty) for (auto _ : state) {} } @@ -66,9 +72,10 @@ void setup(benchmark::State& state) { int main(int argc, char** argv) { // ... - // Run the C++ benchmark + // Register the C++ benchmark and set its unit of measurement benchmark::RegisterBenchmark("cpp", setup)->Unit(benchmark::kMillisecond); + // Initialize the benchmark framework and run the benchmarks benchmark::Initialize(&argc, argv); benchmark::RunSpecifiedBenchmarks(); From 2fa38d9f3e62f79d1dadafb70d4452199330236e Mon Sep 17 00:00:00 2001 From: Atul Rajput <92659293+AtulRajput01@users.noreply.github.com> Date: Sun, 9 Apr 2023 12:37:07 +0530 Subject: [PATCH 11/18] Create CMakeLists.txt --- benchmarks/CMakeLists.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 benchmarks/CMakeLists.txt 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) From 9d063cb20c4ee5f356b50ea5f290d4239b564bd4 Mon Sep 17 00:00:00 2001 From: Atul Rajput <92659293+AtulRajput01@users.noreply.github.com> Date: Sun, 9 Apr 2023 19:11:08 +0530 Subject: [PATCH 12/18] Update cpp_benchmarks.cpp --- benchmarks/cpp_benchmarks.cpp | 99 +++++++++++++++++------------------ 1 file changed, 48 insertions(+), 51 deletions(-) diff --git a/benchmarks/cpp_benchmarks.cpp b/benchmarks/cpp_benchmarks.cpp index d868f959..776814a1 100644 --- a/benchmarks/cpp_benchmarks.cpp +++ b/benchmarks/cpp_benchmarks.cpp @@ -9,6 +9,14 @@ #include #include +#include +#include +#include +#include +#include +#include + +std::map> overall_results; void setup(benchmark::State& state) { // Set up compile and run commands for the C++ benchmark @@ -23,64 +31,53 @@ void setup(benchmark::State& state) { return; } - // Run the C++ benchmark - std::ostringstream run_out; - int run_ret = benchmark::RunSpecifiedCommand(run_cmd, &run_out); - if (run_ret != 0) { - std::cerr << "Failed to run C++ benchmark:\n" << run_out.str() << std::endl; + // 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; } - // Parse the output of the C++ benchmark and store the results - std::string output = run_out.str(); - std::istringstream ss(output); - std::string line; - while (std::getline(ss, line)) { - std::istringstream ls(line); - std::string field, value; - std::getline(ls, field, ':'); - std::getline(ls, value, ','); - - if (field == "\"name\"") { - // Extract the name of the benchmark - std::string benchmark_name = value.substr(1, value.size() - 2); - double benchmark_time = 0.0; - - // Extract the real time taken by the benchmark - while (std::getline(ss, line) && line != "},") { - std::istringstream ls(line); - std::string field, value; - std::getline(ls, field, ':'); - std::getline(ls, value, ','); - - if (field == "\"real_time\"") { - benchmark_time = std::stod(value) / benchmark::kNumIterations; - } - } + // Build the request to invoke the Lambda function + Aws::Lambda::Model::InvokeRequest invokeRequest; + invokeRequest.SetFunctionName("cpp_benchmark"); + invokeRequest.SetInvocationType(Aws::Lambda::Model::InvocationType::RequestResponse); - // Store the benchmark results - overall_results[benchmark_name]["cpp"] = benchmark_time; - } + // 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; } - // Run the benchmarking loop (this loop is empty) - for (auto _ : state) {} -} - -// ... + // 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()); -int main(int argc, char** argv) { - // ... + for (const auto& benchmark : jsonResult.GetObject()) { + std::string benchmark_name = benchmark.GetName(); + double benchmark_time = benchmark.GetValue().AsDouble() / benchmark::kNumIterations; - // Register the C++ benchmark and set its unit of measurement - benchmark::RegisterBenchmark("cpp", setup)->Unit(benchmark::kMillisecond); - - // Initialize the benchmark framework and run the benchmarks - benchmark::Initialize(&argc, argv); - benchmark::RunSpecifiedBenchmarks(); + overall_results[benchmark_name]["cpp"] = benchmark_time; + } - // Print the overall results - // ... + // Delete the Lambda function + Aws::Lambda::Model::DeleteFunctionRequest deleteRequest; + deleteRequest.SetFunctionName("cpp_benchmark"); + lambdaClient.DeleteFunction(deleteRequest); - return 0; -} + // Run the benchmark From bedd54951fb80951f503886464c3a77570ebaec3 Mon Sep 17 00:00:00 2001 From: Atul Rajput <92659293+AtulRajput01@users.noreply.github.com> Date: Sun, 9 Apr 2023 19:11:49 +0530 Subject: [PATCH 13/18] Update cpp_benchmarks.cpp --- benchmarks/cpp_benchmarks.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/benchmarks/cpp_benchmarks.cpp b/benchmarks/cpp_benchmarks.cpp index 776814a1..c4770b91 100644 --- a/benchmarks/cpp_benchmarks.cpp +++ b/benchmarks/cpp_benchmarks.cpp @@ -80,4 +80,33 @@ void setup(benchmark::State& state) { deleteRequest.SetFunctionName("cpp_benchmark"); lambdaClient.DeleteFunction(deleteRequest); - // Run the benchmark +// Run the benchmarking loop +for (auto _ : state) { + std::ostringstream benchmark_out; + int benchmark_ret = benchmark::RunSpecifiedCommand(run_cmd, &benchmark_out); + if (benchmark_ret != 0) { + std::cerr << "Failed to run C++ benchmark:\n" << benchmark_out.str() << std::endl; + return; + } + + Aws::Lambda::Model::InvokeRequest invokeRequest; + invokeRequest.SetFunctionName("cpp_benchmark"); + invokeRequest.SetInvocationType(Aws::Lambda::Model::InvocationType::RequestResponse); + invokeRequest.SetPayload(benchmark_out.str()); + + auto invokeOutcome = lambdaClient.Invoke(invokeRequest); + if (!invokeOutcome.IsSuccess()) { + std::cerr << "Failed to invoke Lambda function: " << invokeOutcome.GetError().GetMessage() << std::endl; + return; + } + + 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]["aws_lambda"] = benchmark_time; + } +} From c20837f9e88677046ffbf2cebc159c801b070ddc Mon Sep 17 00:00:00 2001 From: Atul Rajput <92659293+AtulRajput01@users.noreply.github.com> Date: Sun, 9 Apr 2023 19:14:32 +0530 Subject: [PATCH 14/18] Update cpp_benchmarks.cpp --- benchmarks/cpp_benchmarks.cpp | 34 +--------------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/benchmarks/cpp_benchmarks.cpp b/benchmarks/cpp_benchmarks.cpp index c4770b91..5e7b3271 100644 --- a/benchmarks/cpp_benchmarks.cpp +++ b/benchmarks/cpp_benchmarks.cpp @@ -77,36 +77,4 @@ void setup(benchmark::State& state) { // Delete the Lambda function Aws::Lambda::Model::DeleteFunctionRequest deleteRequest; - deleteRequest.SetFunctionName("cpp_benchmark"); - lambdaClient.DeleteFunction(deleteRequest); - -// Run the benchmarking loop -for (auto _ : state) { - std::ostringstream benchmark_out; - int benchmark_ret = benchmark::RunSpecifiedCommand(run_cmd, &benchmark_out); - if (benchmark_ret != 0) { - std::cerr << "Failed to run C++ benchmark:\n" << benchmark_out.str() << std::endl; - return; - } - - Aws::Lambda::Model::InvokeRequest invokeRequest; - invokeRequest.SetFunctionName("cpp_benchmark"); - invokeRequest.SetInvocationType(Aws::Lambda::Model::InvocationType::RequestResponse); - invokeRequest.SetPayload(benchmark_out.str()); - - auto invokeOutcome = lambdaClient.Invoke(invokeRequest); - if (!invokeOutcome.IsSuccess()) { - std::cerr << "Failed to invoke Lambda function: " << invokeOutcome.GetError().GetMessage() << std::endl; - return; - } - - 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]["aws_lambda"] = benchmark_time; - } -} + delete From b48e2fe9fcfd9d27f1bc3649528c0f26a9486517 Mon Sep 17 00:00:00 2001 From: Atul Rajput <92659293+AtulRajput01@users.noreply.github.com> Date: Sun, 9 Apr 2023 19:15:01 +0530 Subject: [PATCH 15/18] Update cpp_benchmarks.cpp --- benchmarks/cpp_benchmarks.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/benchmarks/cpp_benchmarks.cpp b/benchmarks/cpp_benchmarks.cpp index 5e7b3271..c36202b5 100644 --- a/benchmarks/cpp_benchmarks.cpp +++ b/benchmarks/cpp_benchmarks.cpp @@ -75,6 +75,22 @@ void setup(benchmark::State& state) { overall_results[benchmark_name]["cpp"] = benchmark_time; } - // Delete the Lambda function + // Delete the Lambda function Aws::Lambda::Model::DeleteFunctionRequest deleteRequest; - delete + 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); + From 27b1cf7184526f7fbe92e1872932a79ff9df9b78 Mon Sep 17 00:00:00 2001 From: Atul Rajput <92659293+AtulRajput01@users.noreply.github.com> Date: Sun, 9 Apr 2023 19:22:03 +0530 Subject: [PATCH 16/18] Update cpp_benchmarks.cpp --- benchmarks/cpp_benchmarks.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/benchmarks/cpp_benchmarks.cpp b/benchmarks/cpp_benchmarks.cpp index c36202b5..2600216e 100644 --- a/benchmarks/cpp_benchmarks.cpp +++ b/benchmarks/cpp_benchmarks.cpp @@ -8,7 +8,10 @@ #include #include +// Include the benchmark library #include + +// Include the AWS SDK #include #include #include @@ -16,8 +19,10 @@ #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"}; From eaabc5835e524cad07d1c13485160e15766ca11c Mon Sep 17 00:00:00 2001 From: Atul Rajput <92659293+AtulRajput01@users.noreply.github.com> Date: Sun, 9 Apr 2023 23:05:54 +0530 Subject: [PATCH 17/18] Delete Dockerfile.build --- dockerfiles/aws/nodejs/Dockerfile.build | 29 ------------------------- 1 file changed, 29 deletions(-) delete mode 100755 dockerfiles/aws/nodejs/Dockerfile.build diff --git a/dockerfiles/aws/nodejs/Dockerfile.build b/dockerfiles/aws/nodejs/Dockerfile.build deleted file mode 100755 index cc3d23fc..00000000 --- a/dockerfiles/aws/nodejs/Dockerfile.build +++ /dev/null @@ -1,29 +0,0 @@ -# Use Alpine base image -FROM alpine - -# Install useradd and groupmod shadow package -RUN apk add --no-cache shadow - -# Set environment variable -ENV GOSU_VERSION 1.14 - -# Download and install gosu -# 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 - -# Create directory for our script and copy it to -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 - -# Set the PATH environment variable to include /usr/sbin so that useradd and groupmod can be used -ENV PATH=/usr/sbin:$PATH - -# Set the SCRIPT_FILE environment variable to the location of our package -ENV SCRIPT_FILE=/mnt/function/package.sh - -# Set the command to run our installer in the box -CMD /bin/bash /sebs/installer.sh From 32bdec1e6504920365c37ab0fcbcc9bb270866f1 Mon Sep 17 00:00:00 2001 From: Atul Rajput <92659293+AtulRajput01@users.noreply.github.com> Date: Sun, 9 Apr 2023 23:12:32 +0530 Subject: [PATCH 18/18] Delete Dockerfile.build --- dockerfiles/aws/python/Dockerfile.build | 32 ------------------------- 1 file changed, 32 deletions(-) delete mode 100755 dockerfiles/aws/python/Dockerfile.build diff --git a/dockerfiles/aws/python/Dockerfile.build b/dockerfiles/aws/python/Dockerfile.build deleted file mode 100755 index 476ab42a..00000000 --- a/dockerfiles/aws/python/Dockerfile.build +++ /dev/null @@ -1,32 +0,0 @@ -FROM alpine -ARG VERSION -ENV PYTHON_VERSION=${VERSION} - -# Install useradd and groupmod shadow package -RUN apk add --no-cache shadow - -# Set environment variable -ENV GOSU_VERSION 1.14 - -# Download and install gosu -# 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 - -# Create directory for our script and copy it to -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 - -# Set the PATH environment variable to include /usr/sbin so that useradd and groupmod can be used -ENV PATH=/usr/sbin:$PATH - -# Set the SCRIPT_FILE environment variable to the location of our package -ENV SCRIPT_FILE=/mnt/function/package.sh - -# Set the command to run our installer in the box -CMD /bin/bash /sebs/installer.sh - -ENTRYPOINT ["/sebs/entrypoint.sh"]