Skip to main content

RuntimeOptions

Overview

The RuntimeOptions class defines how your containerized application is executed, including the executor type, scaling, networking, and specialized execution modes.

Constructor

RuntimeOptions(
    executor='docker',
    replicas=0,
    ports=[],
    public=False,
    shardSpec=None,
    jobSpec=None
)

Parameters

executor
str
default:"'docker'"
The container executor/orchestrator to use for running the application.Options: 'docker', 'kubernetes'
replicas
int
default:"0"
Number of replicas to run. Use for scaling your application across multiple instances.Example: 3 (runs 3 instances of the container)
ports
list
default:"[]"
List of ports to expose from the container.Example: [8080], [80, 443]
public
bool
default:"False"
Whether to expose the service publicly (create a public load balancer).Set to True for public access. Primarily used with Kubernetes executor.
shardSpec
ShardSpec
default:"None"
Specification for sharded execution. See ShardSpec below.
jobSpec
JobSpec
default:"None"
Specification for job-based execution. See JobSpec below.

Usage

Basic Runtime

from metaparticle_pkg.containerize import Containerize

@Containerize(
    runtime={
        'executor': 'docker',
        'ports': [8080]
    }
)
def main():
    pass

Scaled Deployment

@Containerize(
    runtime={
        'executor': 'kubernetes',
        'replicas': 3,
        'ports': [8080],
        'public': True
    }
)
def serve():
    pass

Sharded Execution

@Containerize(
    runtime={
        'executor': 'kubernetes',
        'shardSpec': {
            'shards': 4,
            'shardExpression': r'^shard-(\d+)$'
        }
    }
)
def process_sharded_data():
    pass

Job Execution

@Containerize(
    runtime={
        'executor': 'kubernetes',
        'jobSpec': {
            'iterations': 10
        }
    }
)
def batch_job():
    pass

ShardSpec

Overview

The ShardSpec class configures sharded execution, allowing you to distribute work across multiple container instances with shard-specific data.

Constructor

ShardSpec(
    shards=0,
    shardExpression='.*'
)

Parameters

shards
int
default:"0"
Number of shards to create. Each shard runs as a separate container instance.Example: 4 (creates 4 sharded instances)
shardExpression
str
default:"'.*'"
Regular expression pattern for identifying and extracting shard numbers.Example: r'^shard-(\d+)$'

Usage

from metaparticle_pkg.option import ShardSpec

shard_config = ShardSpec(
    shards=8,
    shardExpression=r'data-shard-(\d+)\.txt'
)

@Containerize(
    runtime={
        'executor': 'kubernetes',
        'shardSpec': shard_config
    }
)
def process_data():
    # Process shard-specific data
    pass

JobSpec

Overview

The JobSpec class configures job-based execution for batch processing workloads.

Constructor

JobSpec(iterations=0)

Parameters

iterations
int
required
Number of times to run the job. This parameter is required when using JobSpec.Example: 10 (runs the job 10 times)

Usage

from metaparticle_pkg.option import JobSpec

job_config = JobSpec(iterations=5)

@Containerize(
    runtime={
        'executor': 'kubernetes',
        'jobSpec': job_config
    }
)
def batch_process():
    # Runs 5 times as separate job executions
    pass

Required vs Optional

RuntimeOptions:
  • All parameters are optional with sensible defaults
ShardSpec:
  • All parameters are optional with defaults
JobSpec:
  • iterations is required

Build docs developers (and LLMs) love