sebs.local package
Submodules
sebs.local.config module
Configuration classes for the local execution platform.
This module provides configuration classes for the SeBS local execution platform, including credentials, resources, and overall configuration management. The local platform requires minimal configuration since it runs functions locally using Docker containers.
- Classes:
LocalCredentials: Empty credentials class for local execution LocalResources: Resource management for local deployments LocalConfig: Main configuration class for local platform
- class sebs.local.config.LocalConfig[source]
Bases:
ConfigConfiguration class for local execution platform.
No extra configuration - just implementation of the required interfaces.
- _credentials
Local credentials instance (empty)
- _resources
Local resources instance for port management
- property credentials: LocalCredentials
Get the local credentials.
- Returns:
The credentials instance
- Return type:
LocalCredentials
- static deserialize(config: dict, cache: Cache, handlers: LoggingHandlers) Config[source]
Deserialize configuration from dictionary.
- Parameters:
config – Configuration dictionary
cache – Cache client for loading cached configuration
handlers – Logging handlers for configuration logging
- Returns:
Initialized local configuration instance
- Return type:
LocalConfig
- static initialize(cfg: Config, dct: dict) None[source]
Initialize configuration from dictionary.
- Parameters:
cfg – Configuration instance to initialize
dct – Dictionary containing configuration data
Note
No initialization needed for local platform
- property resources: LocalResources
Get the local resources.
- Returns:
The resources instance
- Return type:
LocalResources
- serialize() dict[source]
Serialize configuration to dictionary.
- Returns:
Dictionary containing configuration data
- Return type:
dict
- static typename() str[source]
Get the type name for this configuration.
- Returns:
Type name “Local.Config”
- Return type:
str
- update_cache(cache: Cache) None[source]
Update cache with current configuration.
- Parameters:
cache – Cache client to update
- class sebs.local.config.LocalCredentials[source]
Bases:
CredentialsCredentials class for local execution platform.
The local platform doesn’t require any authentication credentials since functions run locally using Docker containers. This class provides the required interface with empty implementations.
- static deserialize(config: dict, cache: Cache, handlers: LoggingHandlers) Credentials[source]
Deserialize credentials from configuration.
- Parameters:
config – Configuration dictionary (unused for local)
cache – Cache client (unused for local)
handlers – Logging handlers (unused for local)
- Returns:
New instance of local credentials
- Return type:
LocalCredentials
- serialize() dict[source]
Serialize credentials to dictionary.
- Returns:
Empty dictionary as no credentials are required for local execution
- Return type:
dict
- class sebs.local.config.LocalResources(storage_cfg: PersistentStorageConfig | None = None, nosql_storage_cfg: NoSQLStorageConfig | None = None)[source]
Bases:
SelfHostedResourcesResource management for local execution platform.
Manages resources for local function execution, including port allocation for Docker containers and storage configurations. Tracks allocated ports to avoid conflicts when running multiple functions.
In local deployments, caching and storing resource details is minimal.
- _path
Path for local resource storage
- _allocated_ports
Set of ports currently allocated to containers
- property allocated_ports: set
Get the set of allocated ports.
- Returns:
Set of port numbers currently allocated to containers
- Return type:
set
- static deserialize(config: dict, cache: Cache, handlers: LoggingHandlers) Resources[source]
Deserialize resources from configuration.
- Parameters:
config – Configuration dictionary
cache – Cache client for loading cached resources
handlers – Logging handlers for resource logging
- Returns:
Initialized local resources instance
- Return type:
LocalResources
- static initialize(res: Resources, config: dict) None[source]
Initialize resources from configuration.
- Parameters:
res – Resources instance to initialize
config – Configuration dictionary containing resource settings
- serialize() dict[source]
Serialize resources to dictionary.
- Returns:
Dictionary containing resource configuration including allocated ports
- Return type:
dict
- update_cache(cache: Cache) None[source]
Update cache with current resource state.
- Parameters:
cache – Cache client to update
sebs.local.deployment module
Deployment management for local execution platform.
This module provides the Deployment class for managing local function deployments, including memory measurement collection, function lifecycle management, and resource cleanup.
- Classes:
Deployment: Main deployment management class for local functions
- class sebs.local.deployment.Deployment[source]
Bases:
LoggingBaseManages local function deployments and memory measurements.
- _functions
List of deployed local functions
- _storage
Optional Minio storage instance
- _inputs
List of function input configurations
- _memory_measurement_pids
PIDs of memory measurement processes
- _measurement_file
Path to memory measurement output file
- add_function(func: LocalFunction) None[source]
Add a function to the deployment.
If the function has a memory measurement PID, it’s also recorded.
- Parameters:
func – Local function to add to the deployment
- add_input(func_input: dict) None[source]
Add function input configuration to the deployment.
- Parameters:
func_input – Dictionary containing function input configuration
- static deserialize(path: str, cache_client: Cache) Deployment[source]
Deserialize deployment configuration from file.
- Parameters:
path – File path to read serialized deployment configuration
cache_client – Cache client for loading cached resources
- Returns:
Deserialized deployment instance
- Return type:
Deployment
Note
This method may be deprecated - check if still in use
- property measurement_file: str | None
Get the path to the memory measurement file.
- Returns:
Path to measurement file, or None if not set
- Return type:
Optional[str]
- serialize(path: str) None[source]
Serialize deployment configuration to file.
Includes details about functions, storage, inputs, and memory measurements.
- Parameters:
path – File path to write serialized deployment configuration
- set_storage(storage: Minio) None[source]
Set the storage instance for the deployment.
- Parameters:
storage – Minio storage instance to use
- shutdown(output_json: str) None[source]
Shutdown the deployment and collect memory measurements.
Terminates all memory measurement processes, processes measurement data, and stops all function containers. Memory measurements are aggregated and written to the specified output file.
- Parameters:
output_json – Path to write memory measurement results
sebs.local.function module
Function and trigger implementations for local execution platform.
Functions run as Docker containers with HTTP triggers for invocation.
- Classes:
HTTPTrigger: HTTP-based trigger for local function invocation LocalFunction: Represents a function deployed locally in a Docker container
- class sebs.local.function.HTTPTrigger(url: str)[source]
Bases:
TriggerHTTP trigger for local function invocation.
Provides HTTP-based triggering for functions running in local Docker containers. Supports both synchronous and asynchronous invocation patterns.
- url
HTTP URL endpoint for function invocation
- async_invoke(payload: dict) Future[source]
Asynchronously invoke the function via HTTP.
- Parameters:
payload – Function input payload as dictionary
- Returns:
Future object for the execution result
- Return type:
concurrent.futures.Future
- static deserialize(obj: dict) Trigger[source]
Deserialize trigger from dictionary.
- Parameters:
obj – Dictionary containing trigger configuration
- Returns:
Deserialized HTTP trigger instance
- Return type:
HTTPTrigger
- serialize() dict[source]
Serialize trigger configuration to dictionary.
- Returns:
Dictionary containing trigger type and URL
- Return type:
dict
- sync_invoke(payload: dict) ExecutionResult[source]
Synchronously invoke the function via HTTP.
- Parameters:
payload – Function input payload as dictionary
- Returns:
Result of the function execution
- Return type:
ExecutionResult
- static trigger_type() TriggerType[source]
Get the trigger type.
- Returns:
HTTP trigger type
- Return type:
Trigger.TriggerType
- static typename() str[source]
Get the type name for this trigger.
- Returns:
Type name “Local.HTTPTrigger”
- Return type:
str
- class sebs.local.function.LocalFunction(docker_container, port: int, name: str, benchmark: str, code_package_hash: str, config: FunctionConfig, measurement_pid: int | None = None)[source]
Bases:
FunctionFunction implementation for local execution platform.
Represents a serverless function running locally in a Docker container. Handles container management and URL resolution.
- _instance
Docker container running the function
- _instance_id
Container ID for the function
- _port
Port number the function is listening on
- _url
Complete URL for function invocation
- _measurement_pid
Optional PID of memory measurement process
- property container: Container
Get the Docker container running this function.
- Returns:
The Docker container instance
- Return type:
docker.models.containers.Container
- static deserialize(cached_config: dict) LocalFunction[source]
Deserialize function from cached configuration.
- Parameters:
cached_config – Dictionary containing cached function configuration
- Returns:
Deserialized function instance
- Return type:
LocalFunction
- Raises:
RuntimeError – If cached container is no longer available
- property memory_measurement_pid: int | None
Get the PID of the memory measurement process.
- Returns:
PID of memory measurement process, or None if not measuring
- Return type:
Optional[int]
- serialize() dict[source]
Serialize function configuration to dictionary.
- Returns:
Dictionary containing function configuration including container details
- Return type:
dict
- stop() None[source]
Stop the function container.
Stops the Docker container running this function with immediate timeout.
- static typename() str[source]
Get the type name for this function.
- Returns:
Type name “Local.LocalFunction”
- Return type:
str
- property url: str
Get the URL for function invocation.
- Returns:
HTTP URL for invoking the function
- Return type:
str
sebs.local.local module
Local execution platform for SeBS.
It runs serverless functions locally using Docker containers, providing a development and testing environment that mimics serverless execution without requiring cloud platform deployment.
The local platform provides: - Docker-based function execution - HTTP triggers for function invocation - Memory profiling and measurement capabilities - Port management for multiple concurrent functions - Cross-platform support (Linux, macOS, Windows)
- Key Classes:
Local: Main system class implementing the local execution platform
- class sebs.local.local.Local(sebs_config: SeBSConfig, config: LocalConfig, cache_client: Cache, docker_client: DockerClient, logger_handlers: LoggingHandlers)[source]
Bases:
SystemLocal execution platform implementation.
- DEFAULT_PORT
Default port number for function containers (9000)
- _config
Local platform configuration
- _remove_containers
Whether to automatically remove containers after use
- _memory_measurement_path
Path to memory measurement file
- _measure_interval
Interval for memory measurements (-1 disables)
- DEFAULT_PORT = 9000
- cached_function(function: Function) None[source]
Handle cached function setup.
For local functions, no special handling is needed for cached functions.
- Parameters:
function – Cached function instance
- property config: LocalConfig
Get the local platform configuration.
- Returns:
The platform configuration
- Return type:
LocalConfig
- create_function(code_package: Benchmark, func_name: str, container_deployment: bool, container_uri: str | None) LocalFunction[source]
Create a new function deployment. In practice, it starts a new Docker container.
- Parameters:
code_package – Benchmark code package to deploy
func_name – Name for the function
container_deployment – Whether to use container deployment (unsupported)
container_uri – Container URI (unused for local)
- Returns:
Created function instance
- Return type:
LocalFunction
- Raises:
NotImplementedError – If container deployment is requested
- create_trigger(func: Function, trigger_type: TriggerType) Trigger[source]
Create a trigger for function invocation.
For local functions, only HTTP triggers are supported.
- Parameters:
func – Function to create trigger for
trigger_type – Type of trigger to create
- Returns:
Created trigger instance
- Return type:
Trigger
- Raises:
RuntimeError – If trigger type is not HTTP
- static default_function_name(code_package: Benchmark, resources: Resources | None = None) str[source]
Generate default function name.
Creates a standardized function name based on the code package and resources.
- Parameters:
code_package – Benchmark code package
resources – Optional resources instance for ID inclusion
- Returns:
Generated function name
- Return type:
str
- download_metrics(function_name: str, start_time: int, end_time: int, requests: Dict[str, ExecutionResult], metrics: dict) None[source]
Download execution metrics.
For local execution, metrics are not available from the platform.
- Parameters:
function_name – Name of the function
start_time – Start time for metrics collection
end_time – End time for metrics collection
requests – Execution requests to collect metrics for
metrics – Dictionary to store collected metrics
- enforce_cold_start(functions: List[Function], code_package: Benchmark) None[source]
Enforce cold start for functions.
- Parameters:
functions – List of functions to enforce cold start on
code_package – Benchmark code package
- Raises:
NotImplementedError – Cold start enforcement is not implemented for local
- static format_function_name(func_name: str) str[source]
Format function name for platform requirements.
For local execution, no formatting is needed.
- Parameters:
func_name – Function name to format
- Returns:
Formatted function name (unchanged for local)
- Return type:
str
- static function_type() Type[Function][source]
Get the function type for this platform.
- Returns:
LocalFunction class
- Return type:
Type[Function]
- property measure_interval: int
Get the memory measurement interval.
- Returns:
Measurement interval in milliseconds, -1 if disabled
- Return type:
int
- property measurement_path: str | None
Get the path to the memory measurement file.
- Returns:
Path to measurement file, or None if not set
- Return type:
Optional[str]
- property measurements_enabled: bool
Check if memory measurements are enabled.
- Returns:
True if measurements are enabled
- Return type:
bool
- static name() str[source]
Get the platform name.
- Returns:
Platform name “local”
- Return type:
str
- package_code(directory: str, language: Language, language_version: str, architecture: str, benchmark: str, is_cached: bool) Tuple[str, int][source]
Package function code for local execution.
Creates a compatible code package structure for local execution that maintains compatibility across cloud providers. Reorganizes files into a module structure to handle relative imports properly.
The packaging creates this structure: - function/
function.py
storage.py
resources/
handler.py
- Parameters:
directory – Directory containing the function code
language – Programming language (e.g., “python”, “nodejs”)
language_version – Language version (e.g., “3.8”, “14”)
architecture – Target architecture (unused for local)
benchmark – Benchmark name
is_cached – Whether the package is from cache
- Returns:
(package_path, size_bytes)
- Return type:
Tuple[str, int]
- property remove_containers: bool
Get whether containers are automatically removed.
- Returns:
True if containers are removed after use
- Return type:
bool
- shutdown() None[source]
Shut down the local platform.
Performs cleanup operations including shutting down any storage instances.
- start_measurements(measure_interval: int) str | None[source]
Start memory measurements for function containers.
Creates a temporary file for storing memory measurements and enables measurement collection at the specified interval.
- Parameters:
measure_interval – Measurement interval in milliseconds
- Returns:
Path to measurement file, or None if measurements disabled
- Return type:
Optional[str]
- static typename() str[source]
Get the platform type name.
- Returns:
Type name “Local”
- Return type:
str
- update_function(function: Function, code_package: Benchmark, container_deployment: bool, container_uri: str | None) None[source]
Update an existing function with new code.
Stops the existing container and starts a new one with updated code.
- Parameters:
function – Existing function to update
code_package – New benchmark code package
container_deployment – Whether to use container deployment (unused)
container_uri – Container URI (unused)
- update_function_configuration(function: Function, code_package: Benchmark) None[source]
Update function configuration.
- Parameters:
function – Function to update
code_package – Benchmark code package
- Raises:
RuntimeError – Always raised as configuration updates are not supported
sebs.local.measureMem module
Memory measurement utility for Docker containers.
This script periodically reads the memory.current file from the container’s cgroup to record its memory usage. The measurements are appended to a specified output file.
The measurement process: 1. Reads memory.current from the container’s cgroup 2. Records the measurement with container ID and timestamp 3. Tracks precision errors when measurement intervals are exceeded 4. Continues until the container stops or process is terminated
- Functions:
measure: Main measurement function that continuously monitors container memory
- Usage:
python measureMem.py –container-id <id> –measure-interval <ms> –measurement-file <path>
- sebs.local.measureMem.measure(container_id: str, measure_interval: int, measurement_file: str) None[source]
Continuously measure memory consumption of a Docker container.
Reads memory usage from the container’s cgroup filesystem at regular intervals and writes measurements to the specified file. Handles different cgroup paths for compatibility with various Docker configurations.
- Parameters:
container_id – Docker container ID to monitor
measure_interval – Measurement interval in milliseconds
measurement_file – Path to file for writing measurements
Note
This function runs indefinitely until the process is terminated. It attempts two different cgroup paths to accommodate different Docker/systemd configurations.
Module contents
SeBS local execution platform module.
This module provides the local execution platform by running serverless functions locally using Docker containers, providing a development and testing environment that mimics serverless execution without requiring cloud platform deployment.
Key components: - Local: Main system class for local function execution - LocalFunction: Represents a function deployed locally in a Docker container - Deployment: Manages deployments and memory measurements for local functions
The local platform supports HTTP triggers and provides memory profiling capabilities for performance analysis. It can also be integrated with local object and NoSQL storage.