Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### Features

* Object storage for Java on AWS: `Storage.java` implements the interface of the Python wrapper's `storage` class and is added, with the AWS SDK, only to benchmarks using the `storage` module.

* Cold start enforcement for the local deployment: SeBS replaces the function container, and the local function servers report the first invocation of a container as cold. Requires the updated local run images.

* [RustFS](https://github.com/rustfs/rustfs) is the new default S3-compatible object storage for local and OpenWhisk deployments. Minio is deprecated and kept for reproducibility (`configs/storage-minio.json`). The self-hosted object storage implementation is now shared between backends.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// Copyright 2020-2025 ETH Zurich and the SeBS authors. All rights reserved.
package org.serverlessbench;

import software.amazon.awssdk.core.ResponseBytes;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
import software.amazon.awssdk.services.s3.model.GetObjectResponse;
import software.amazon.awssdk.services.s3.model.ListObjectsV2Request;
import software.amazon.awssdk.services.s3.model.ListObjectsV2Response;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
import software.amazon.awssdk.services.s3.model.S3Object;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.UUID;

/** S3 storage with the interface of the Python wrapper's {@code storage} class. */
public final class Storage {

private static Storage instance = null;

private final S3Client client;

private Storage() {
// Smaller than the SDK's default HTTP clients, which systems.json excludes
this.client = S3Client.builder().httpClient(UrlConnectionHttpClient.create()).build();
}

/** Returns the shared instance, created on first use. */
public static synchronized Storage getInstance() {
if (instance == null) {
instance = new Storage();
}
return instance;
}

/** Inserts a random suffix before the extension, e.g. {@code archive.1a2b3c4d.zip}. */
public static String uniqueName(String name) {
int separator = name.lastIndexOf('/');
int dot = name.lastIndexOf('.');
String base = name;
String extension = "";
if (dot > separator) {
base = name.substring(0, dot);
extension = name.substring(dot);
}
String random = UUID.randomUUID().toString().split("-")[0];
return base + "." + random + extension;
}

/** Uploads a local file under {@code uniqueName(file)} and returns that key. */
public String upload(String bucket, String file, String filepath) {
String keyName = uniqueName(file);
this.client.putObject(
PutObjectRequest.builder().bucket(bucket).key(keyName).build(),
RequestBody.fromFile(Paths.get(filepath)));
return keyName;
}

/** Downloads an object to a local file, creating its parent directories. */
public void download(String bucket, String file, String filepath) throws IOException {
Path destination = Paths.get(filepath);
Path parent = destination.getParent();
if (parent != null) {
Files.createDirectories(parent);
}
// The SDK refuses to overwrite an existing file
Files.deleteIfExists(destination);
this.client.getObject(
GetObjectRequest.builder().bucket(bucket).key(file).build(), destination);
}

/** Downloads every object under a prefix into {@code path}, keeping the key structure. */
public void downloadDirectory(String bucket, String prefix, String path) throws IOException {
ListObjectsV2Request.Builder request =
ListObjectsV2Request.builder().bucket(bucket).prefix(prefix);
String continuationToken = null;
boolean found = false;
do {
ListObjectsV2Response objects =
this.client.listObjectsV2(request.continuationToken(continuationToken).build());
for (S3Object object : objects.contents()) {
found = true;
download(bucket, object.key(), Paths.get(path, object.key()).toString());
}
continuationToken = objects.nextContinuationToken();
} while (continuationToken != null);

if (!found) {
throw new IOException(
String.format(
"No objects found in bucket '%s' with prefix '%s'", bucket, prefix));
}
}

/** Uploads bytes under {@code uniqueName(file)} and returns that key. */
public String uploadStream(String bucket, String file, byte[] data) {
String keyName = uniqueName(file);
this.client.putObject(
PutObjectRequest.builder().bucket(bucket).key(keyName).build(),
RequestBody.fromBytes(data));
return keyName;
}

/** Downloads an object into memory. */
public byte[] downloadStream(String bucket, String file) {
ResponseBytes<GetObjectResponse> response =
this.client.getObjectAsBytes(
GetObjectRequest.builder().bucket(bucket).key(file).build());
return response.asByteArray();
}
}
19 changes: 18 additions & 1 deletion configs/systems.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,24 @@
"com.amazonaws:aws-lambda-java-core": "1.2.3",
"com.fasterxml.jackson.core:jackson-databind": "2.17.1"
},
"module_packages": {}
"module_packages": {
"storage": {
"software.amazon.awssdk:s3": {
"version": "2.46.7",
"exclusions": [
"software.amazon.awssdk:netty-nio-client",
"software.amazon.awssdk:apache-client",
"software.amazon.awssdk:apache5-client"
]
},
"software.amazon.awssdk:url-connection-client": "2.46.7"
}
},
"module_files": {
"storage": [
"modules/storage/src"
]
}
}
},
"cpp": {
Expand Down
19 changes: 19 additions & 0 deletions docs/modularity.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,25 @@ and `storage` which hides the cloud API of persistent storage.

For example, examine the existing implementations in [`benchmarks/wrappers/`](/benchmarks/wrappers/).

Wrappers in `deployment.files` are added to every benchmark. A wrapper with a large SDK, such as
Java's storage, goes in `deployment.module_files` instead and is added only to benchmarks declaring
that module in their `config.json`, together with its `deployment.module_packages`. For Java, a
package's version can be an object that also lists transitive dependencies to exclude:

```json
"module_packages": {
"storage": {
"software.amazon.awssdk:s3": {
"version": "2.46.7",
"exclusions": ["software.amazon.awssdk:netty-nio-client"]
}
}
},
"module_files": {
"storage": ["modules/storage/src"]
}
```

### Adapt Platform Mode

The final step is adjusting the SeBS code whenever we make a language-specific decision.
Expand Down
72 changes: 65 additions & 7 deletions sebs/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,10 +687,11 @@ def hash_directory(
Language.JAVA: ["*.java", "pom.xml"],
Language.CPP: ["*.cpp", "*.hpp", "dependencies.json"],
}
# Java's "modules" is hashed for every benchmark, so changing it rebuilds all of them
WRAPPERS = {
Language.PYTHON: ["*.py"],
Language.NODEJS: ["*.js"],
Language.JAVA: ["src"],
Language.JAVA: ["src", "modules"],
Language.CPP: ["*.cpp", "*.hpp"],
}
NON_LANG_FILES = ["*.sh", "*.json"]
Expand Down Expand Up @@ -910,6 +911,16 @@ def add_deployment_files(self, output_dir: str) -> None:
)
]

# Only for benchmarks using the module, since module SDKs make the package larger
module_files = self._system_config.deployment_module_files(
self._deployment_name, self.language_name
)
for bench_module in self._benchmark_config.modules:
handlers.extend(
os.path.join(handlers_dir, file)
for file in module_files.get(bench_module.value, [])
)

for file in handlers:
destination = os.path.join(output_dir, os.path.basename(file))
if os.path.isdir(file):
Expand Down Expand Up @@ -977,24 +988,68 @@ def add_deployment_package_nodejs(self, output_dir: str) -> None:
with open(package_config, "w") as package_file:
json.dump(package_json, package_file, indent=2)

def format_maven_dependency(self, group_artifact: str, version: str) -> str:
def _module_packages(self) -> Dict[str, Any]:
"""Collect the packages of the modules this benchmark uses.

Returns:
Dict[str, Any]: Package names mapped to their version or specification.
"""
module_packages = self._system_config.deployment_module_packages(
self._deployment_name, self.language_name
)
packages: Dict[str, Any] = {}
for bench_module in self._benchmark_config.modules:
packages.update(module_packages.get(bench_module.value, {}))
return packages

@staticmethod
def parse_package_spec(spec: Any) -> Tuple[str, List[str]]:
"""Split a package specification from systems.json into its version and exclusions.

Args:
spec: version string, or a dict with "version" and optional "exclusions"

Returns:
Tuple[str, List[str]]: the version, and the excluded "group:artifact" names
"""
if isinstance(spec, dict):
return spec["version"], spec.get("exclusions", [])
return spec, []

def format_maven_dependency(
self, group_artifact: str, version: str, exclusions: Optional[List[str]] = None
) -> str:
"""Helper method to format Java system dependencies.
Dependencies in system.json are in "group:artifact": version format;
this function converts them to proper Maven <dependency> blocks.

Args:
group_artifact: name of library to add to benchmark
version: library version
exclusions: transitive dependencies to drop, as "group:artifact" names

Returns:
XML-formatted block inserted into pom.xml
"""
group_id, artifact_id = group_artifact.split(":")
exclusion_block = ""
if exclusions:
excluded = "".join(
f"""
<exclusion>
<groupId>{excluded_artifact.split(":")[0]}</groupId>
<artifactId>{excluded_artifact.split(":")[1]}</artifactId>
</exclusion>"""
for excluded_artifact in exclusions
)
exclusion_block = f"""
<exclusions>{excluded}
</exclusions>"""
return f"""
<dependency>
<groupId>{group_id}</groupId>
<artifactId>{artifact_id}</artifactId>
<version>{version}</version>
<version>{version}</version>{exclusion_block}
</dependency>"""

def add_deployment_package_java(self, output_dir: str):
Expand All @@ -1011,17 +1066,20 @@ def add_deployment_package_java(self, output_dir: str):
with open(pom_path, "r") as f:
pom_content = f.read()

packages = self._system_config.deployment_packages(
self._deployment_name, self.language_name
packages: Dict[str, Any] = dict(
self._system_config.deployment_packages(self._deployment_name, self.language_name)
)
packages.update(self._module_packages())

dependency_blocks = ""
if len(packages):
for key, val in packages.items():
dependency_name = key.strip('"').strip("'")
dependency_version = val.strip('"').strip("'")
version, exclusions = Benchmark.parse_package_spec(val)
dependency_version = version.strip('"').strip("'")
dependency_blocks += (
self.format_maven_dependency(dependency_name, dependency_version) + "\n"
self.format_maven_dependency(dependency_name, dependency_version, exclusions)
+ "\n"
)

if "<!-- PLATFORM_DEPENDENCIES -->" not in pom_content:
Expand Down
26 changes: 22 additions & 4 deletions sebs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"""

import json
from typing import Dict, List, Optional
from typing import Any, Dict, List, Optional

from sebs.utils import get_resource_path

Expand Down Expand Up @@ -86,7 +86,7 @@ def deployment_packages(self, deployment_name: str, language_name: str) -> Dict[

def deployment_module_packages(
self, deployment_name: str, language_name: str
) -> Dict[str, List[str]]:
) -> Dict[str, Any]:
"""Get deployment module packages for a specific deployment and language, e.g.,
packages specific to object or NoSQL storage.

Expand All @@ -95,8 +95,9 @@ def deployment_module_packages(
language_name (str): Programming language name (e.g., 'python', 'nodejs').

Returns:
Dict[str, List[str]]: Dictionary mapping benchmark modules to the package
specifications installed for them, e.g., "boto3==1.28.3".
Dict[str, Any]: Dictionary mapping benchmark modules to the packages installed
for them, e.g., ["boto3==1.28.3"] for Python, or {"group:artifact": version}
for Java.
"""
return self._system_config[deployment_name]["languages"][language_name]["deployment"][
"module_packages"
Expand All @@ -116,6 +117,23 @@ def deployment_files(self, deployment_name: str, language_name: str) -> List[str
"files"
]

def deployment_module_files(
self, deployment_name: str, language_name: str
) -> Dict[str, List[str]]:
"""Get wrapper files added only to benchmarks using a given module.

Args:
deployment_name (str): Name of the deployment platform (e.g., 'aws', 'azure').
language_name (str): Programming language name (e.g., 'java').

Returns:
Dict[str, List[str]]: Dictionary mapping benchmark modules to the wrapper files
added for them, relative to the language's wrapper directory.
"""
return self._system_config[deployment_name]["languages"][language_name]["deployment"].get(
"module_files", {}
)

def docker_image_types(self, deployment_name: str, language_name: str) -> List[str]:
"""Get available Docker image types for a deployment and language.

Expand Down