Repository navigation
Add .NET support on AWS #360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
anveba
wants to merge
1
commit into
spcl:master
Choose a base branch
from
anveba:dotnet-aws
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| { | ||
| "timeout": 120, | ||
| "memory": 128, | ||
| "languages": ["python", "nodejs", "java", "cpp"], | ||
| "languages": ["python", "nodejs", "java", "cpp", "dotnet"], | ||
| "modules": [], | ||
| "cpp_dependencies": [] | ||
| } |
20 changes: 20 additions & 0 deletions
20
benchmarks/000.microbenchmarks/010.sleep/dotnet/Function.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Copyright 2020-2025 ETH Zurich and the SeBS authors. All rights reserved. | ||
| using System; | ||
| using System.Diagnostics; | ||
| using System.Text.Json.Nodes; | ||
| using System.Threading; | ||
|
|
||
| namespace Benchmark; | ||
|
|
||
| public class Function | ||
| { | ||
| public JsonObject Handler(JsonObject input) | ||
| { | ||
| double seconds = input["sleep"]?.GetValue<double>() | ||
| ?? throw new ArgumentException("expected a number in 'sleep'"); | ||
|
|
||
| var stopwatch = Stopwatch.StartNew(); | ||
| Thread.Sleep(TimeSpan.FromSeconds(seconds)); | ||
| return new JsonObject { ["result"] = stopwatch.Elapsed.TotalSeconds }; | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
benchmarks/000.microbenchmarks/010.sleep/dotnet/function.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <!-- DOTNET_VERSION is set by the build image. --> | ||
| <TargetFramework>net$(DOTNET_VERSION).0</TargetFramework> | ||
| <!-- Part of the platform handler strings. --> | ||
| <AssemblyName>function</AssemblyName> | ||
| <Nullable>enable</Nullable> | ||
| <!-- Required by the runtime; not generated for libraries by default. --> | ||
| <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <!-- PLATFORM_DEPENDENCIES --> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| // Copyright 2020-2025 ETH Zurich and the SeBS authors. All rights reserved. | ||
|
|
||
| // The benchmark must define Benchmark.Function with JsonObject Handler(JsonObject input). | ||
|
|
||
| using System; | ||
| using System.Globalization; | ||
| using System.IO; | ||
| using System.Text; | ||
| using System.Text.Encodings.Web; | ||
| using System.Text.Json; | ||
| using System.Text.Json.Nodes; | ||
| using Amazon.Lambda.Core; | ||
|
|
||
| namespace ServerlessBench; | ||
|
|
||
| public class Handler | ||
| { | ||
| private const string ColdStartMarker = "/tmp/cold_run"; | ||
| private static readonly object ColdStartLock = new(); | ||
| // Cached so that the ID stays the same even if the marker cannot be read or written | ||
| private static string? cachedContainerId; | ||
|
|
||
| // Skip HTML-safe escaping, matching the other wrappers' output. | ||
| private static readonly JsonSerializerOptions JsonOptions = | ||
| new() { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping }; | ||
|
|
||
| public Stream HandleRequest(Stream input, ILambdaContext context) | ||
| { | ||
| // Before the benchmark, so that the first of concurrent invocations is the cold one | ||
| (bool isCold, string containerId) = CheckColdStart(); | ||
| JsonObject evt = ParseEvent(input); | ||
|
|
||
| DateTimeOffset begin = DateTimeOffset.UtcNow; | ||
| JsonObject result = new Benchmark.Function().Handler(evt); | ||
| DateTimeOffset end = DateTimeOffset.UtcNow; | ||
|
|
||
| var body = new JsonObject | ||
| { | ||
| ["begin"] = FormatTimestamp(begin), | ||
| ["end"] = FormatTimestamp(end), | ||
| ["results_time"] = 0, | ||
| ["is_cold"] = isCold, | ||
| ["result"] = result, | ||
| ["request_id"] = context.AwsRequestId, | ||
| ["cold_start_var"] = Environment.GetEnvironmentVariable("cold_start") ?? "", | ||
| ["container_id"] = containerId, | ||
| }; | ||
| var response = new JsonObject | ||
| { | ||
| ["statusCode"] = 200, | ||
| ["body"] = body.ToJsonString(JsonOptions), | ||
| }; | ||
| return new MemoryStream(Encoding.UTF8.GetBytes(response.ToJsonString(JsonOptions))); | ||
| } | ||
|
|
||
| // HTTP triggers wrap the input in a JSON string under "body". | ||
| private static JsonObject ParseEvent(Stream input) | ||
| { | ||
| JsonObject evt = JsonNode.Parse(input) as JsonObject ?? new JsonObject(); | ||
| if (evt["body"] is JsonValue body && body.TryGetValue(out string? text) | ||
| && JsonNode.Parse(text) is JsonObject parsed) | ||
| { | ||
| return parsed; | ||
| } | ||
| return evt; | ||
| } | ||
|
|
||
| // Locked because Lambda can run concurrent invocations in one process | ||
| private static (bool, string) CheckColdStart() | ||
| { | ||
| lock (ColdStartLock) | ||
| { | ||
| if (cachedContainerId != null) | ||
| { | ||
| return (false, cachedContainerId); | ||
| } | ||
| if (File.Exists(ColdStartMarker)) | ||
| { | ||
| try | ||
| { | ||
| cachedContainerId = File.ReadAllText(ColdStartMarker); | ||
| } | ||
| catch (Exception e) when (e is IOException or UnauthorizedAccessException) | ||
| { | ||
| cachedContainerId = NewContainerId(); | ||
| } | ||
| return (false, cachedContainerId); | ||
| } | ||
| cachedContainerId = NewContainerId(); | ||
| try | ||
| { | ||
| File.WriteAllText(ColdStartMarker, cachedContainerId); | ||
| } | ||
| catch (Exception e) when (e is IOException or UnauthorizedAccessException) | ||
| { | ||
| // Best effort: without the marker, a new process here also reports a cold start | ||
| } | ||
| return (true, cachedContainerId); | ||
| } | ||
| } | ||
|
|
||
| private static string NewContainerId() => Guid.NewGuid().ToString("N").Substring(0, 8); | ||
|
|
||
| // seconds.microseconds, like the other wrappers. | ||
| private static string FormatTimestamp(DateTimeOffset ts) | ||
| { | ||
| long micros = (ts.UtcTicks - DateTimeOffset.UnixEpoch.UtcTicks) / 10; | ||
| return string.Format( | ||
| CultureInfo.InvariantCulture, "{0}.{1:D6}", micros / 1_000_000, micros % 1_000_000); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| { | ||
| "experiments": { | ||
| "deployment": "aws", | ||
| "update_code": false, | ||
| "update_storage": false, | ||
| "download_results": false, | ||
| "architecture": "x64", | ||
| "system_variant": "package", | ||
| "runtime": { | ||
| "language": "dotnet", | ||
| "version": "10" | ||
| }, | ||
| "type": "invocation-overhead", | ||
| "perf-cost": { | ||
| "benchmark": "110.dynamic-html", | ||
| "experiments": ["cold", "warm", "burst", "sequential"], | ||
| "input-size": "test", | ||
| "repetitions": 50, | ||
| "concurrent-invocations": 50, | ||
| "memory-sizes": [128, 256] | ||
| }, | ||
| "network-ping-pong": { | ||
| "invocations": 50, | ||
| "repetitions": 1000, | ||
| "threads": 1 | ||
| }, | ||
| "invocation-overhead": { | ||
| "repetitions": 5, | ||
| "N": 20, | ||
| "type": "payload", | ||
| "payload_begin": 1024, | ||
| "payload_end": 6251000, | ||
| "payload_points": 20, | ||
| "code_begin": 1048576, | ||
| "code_end": 261619712, | ||
| "code_points": 20 | ||
| }, | ||
| "eviction-model": { | ||
| "invocations": 1, | ||
| "function_copy_idx": 0, | ||
| "repetitions": 5, | ||
| "sleep": 1 | ||
| } | ||
| }, | ||
| "deployment": { | ||
| "name": "aws", | ||
| "aws": { | ||
| "region": "us-east-1", | ||
| "lambda-role": "", | ||
| "resources": { | ||
| "use-function-url": true, | ||
| "function-url-auth-type": "NONE" | ||
| } | ||
| }, | ||
| "azure": { | ||
| "region": "westeurope" | ||
| }, | ||
| "gcp": { | ||
| "region": "europe-west1", | ||
| "project_name": "", | ||
| "credentials": "", | ||
| "configuration": { | ||
| "function-gen1": { | ||
| "min-instances": 0, | ||
| "max-instances": 20 | ||
| }, | ||
| "function-gen2": { | ||
| "vcpus": 1, | ||
| "gcp-concurrency": 80, | ||
| "worker-concurrency": 1, | ||
| "worker-threads": 8, | ||
| "min-instances": 0, | ||
| "max-instances": 20, | ||
| "cpu-boost": false, | ||
| "cpu-throttle": true | ||
| }, | ||
| "container": { | ||
| "environment": "gen2", | ||
| "vcpus": 1, | ||
| "gcp-concurrency": 80, | ||
| "worker-concurrency": 1, | ||
| "worker-threads": 8, | ||
| "min-instances": 0, | ||
| "max-instances": 20, | ||
| "cpu-boost": false, | ||
| "cpu-throttle": true | ||
| } | ||
| } | ||
| }, | ||
| "local": {}, | ||
| "openwhisk": { | ||
| "shutdownStorage": false, | ||
| "removeCluster": false, | ||
| "wskBypassSecurity": "true", | ||
| "wskExec": "wsk", | ||
| "experimentalManifest": false, | ||
| "removeStaleContainers": true, | ||
| "kubectlExec": "kubectl", | ||
| "kubernetesNamespace": "openwhisk", | ||
| "dockerhubRepository": null, | ||
| "docker_registry": { | ||
| "registry": "", | ||
| "username": "", | ||
| "password": "" | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| ARG BASE_IMAGE | ||
| FROM ${BASE_IMAGE} | ||
| ARG VERSION | ||
| # Read by function.csproj. Overrides the base image's informational runtime version. | ||
| ENV DOTNET_VERSION=${VERSION} | ||
|
|
||
| SHELL ["/bin/bash", "-o", "pipefail", "-c"] | ||
|
|
||
| # shadow-utils provides useradd and groupmod for the entrypoint. | ||
| RUN dnf install -y shadow-utils tar gzip && dnf clean all | ||
|
|
||
| # The base image has only the runtime. SDK releases and checksums: | ||
| # https://builds.dotnet.microsoft.com/dotnet/release-metadata/<version>.0/releases.json | ||
| RUN case "${VERSION}" in \ | ||
| 10) SDK_RELEASE=10.0.404; \ | ||
| SDK_SHA512_X64=577d0eb17fec33d029104c5c63a1ab0accc3e28776274abef2218dbac5af18d2109b5406d26b31d76f5c245215e3ba0926a94c20246c672c41847c9e1eb1dc50; \ | ||
| SDK_SHA512_ARM64=3533a3869da219cac45c567aadac3d8e96cdf1c6a04fe1c1d5fdeefea5d45af8424488f0144730d11b4a751f7ad546fb11e4c2b2725cd8401efee726711f8f11 ;; \ | ||
| *) echo "No pinned .NET SDK for version ${VERSION}" >&2; exit 1 ;; \ | ||
| esac && \ | ||
| case "$(uname -m)" in \ | ||
| x86_64) SDK_ARCH=x64; SDK_SHA512=${SDK_SHA512_X64} ;; \ | ||
| aarch64) SDK_ARCH=arm64; SDK_SHA512=${SDK_SHA512_ARM64} ;; \ | ||
| *) echo "Unsupported build architecture $(uname -m)" >&2; exit 1 ;; \ | ||
| esac && \ | ||
| curl -fsSL -o /tmp/sdk.tar.gz \ | ||
| "https://builds.dotnet.microsoft.com/dotnet/Sdk/${SDK_RELEASE}/dotnet-sdk-${SDK_RELEASE}-linux-${SDK_ARCH}.tar.gz" && \ | ||
| echo "${SDK_SHA512} /tmp/sdk.tar.gz" | sha512sum -c - && \ | ||
| mkdir -p /opt/dotnet && \ | ||
| tar -C /opt/dotnet -xzf /tmp/sdk.tar.gz && \ | ||
| rm /tmp/sdk.tar.gz | ||
| ENV DOTNET_ROOT=/opt/dotnet | ||
| ENV PATH=/opt/dotnet:$PATH | ||
| # Silences a first-run warning; benchmarks use no workloads. | ||
| ENV DOTNET_SKIP_WORKLOAD_INTEGRITY_CHECK=1 | ||
|
|
||
| ENV GOSU_VERSION=1.14 | ||
| # Architecture from uname: single-platform builds leave TARGETARCH empty. | ||
| RUN case "$(uname -m)" in \ | ||
| x86_64) GOSU_ARCH=amd64 ;; \ | ||
| aarch64) GOSU_ARCH=arm64 ;; \ | ||
| esac && \ | ||
| curl -fsSL -o /usr/local/bin/gosu \ | ||
| "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-${GOSU_ARCH}" && \ | ||
| chmod +x /usr/local/bin/gosu | ||
| RUN mkdir -p /sebs/ | ||
| COPY dockerfiles/dotnet_installer.sh /sebs/installer.sh | ||
| COPY dockerfiles/entrypoint.sh /sebs/entrypoint.sh | ||
| RUN chmod +x /sebs/entrypoint.sh /sebs/installer.sh | ||
|
|
||
| # useradd and groupmod are 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"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| ARG BASE_IMAGE | ||
| ARG BASE_IMAGE_BUILDER | ||
|
|
||
| FROM ${BASE_IMAGE_BUILDER} AS builder | ||
| ARG TARGET_ARCHITECTURE | ||
| COPY . /mnt/function | ||
| RUN TARGET_ARCHITECTURE=${TARGET_ARCHITECTURE} /bin/bash /sebs/installer.sh | ||
|
|
||
| FROM ${BASE_IMAGE} | ||
| COPY --from=builder /mnt/function/publish/ ${LAMBDA_TASK_ROOT}/ | ||
| CMD ["function::ServerlessBench.Handler::HandleRequest"] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Select an implemented .NET benchmark for
perf-cost.With valid AWS configuration,
sebs experiment invoke perf-cost --config configs/dotnet.jsonselects110.dynamic-html. That benchmark does not supportdotnet, so benchmark construction raises before the experiment starts. Set this value to010.sleep, which this change implements. (raw.githubusercontent.com)