Function Containers
Function containers are containers utilizing the function deployment strategy. Unlike other containers on Cycle, once a function container is stopped, it isn't automatically restarted. Function containers lend themselves to ephemeral tasks, batch-processing, or event-driven tasks such as converting files, processing images, or training LLMs.
Function containers are often used for workloads that would otherwise be put onto "serverless architecture".
How Function Containers Work
Function containers are configured with a pre-defined number of hot instances, that have everything pre-defined and configured so that they can be started nearly instantaneously (sub-100ms start time). The only real cost to these "hot instances" are a small storage overhead, but it tends to be negligible. The image, network routes, and other configuration are set up ahead of time. Function containers can have hundreds or thousands of prebuilt instances ready to start at a moment's notice.
With such high throughput and speeds, function containers can scale to the most demanding tasks.
Integration with the Scheduler Service
Function containers are heavily integrated with the scheduler service. The scheduler service is responsible for balancing tasks between different instances of a function container.
Caution
The scheduler service must be started for function containers to work.
Handling Web Requests with Function Containers
A LINKED Record can be pointed to a function container to create an automatic passthrough, where each request to the specified domain starts an instance of the function container which handles the request before shutting down.
Cycle will automatically configure the environment's load balancer service and scheduler service to route requests to the appropriate function container, simply by creating a LINKED Record for it. The function container will receive the HTTP, TCP, or UDP request just as it would normally.
Function Container Lifecycle
A function container goes through three stages, though these details are generally only necessary when utilizing the scheduler service API . When connected directly to a LINKED Record, these stages are automated by the platform.
- Claim: During the claim stage, a function container instance is reserved by the caller. It will be released back into the pool of available instances if it isn't spawned within 10 seconds.
- Spawn: During the spawn stage, the function container instance is actually started using a claim token from the claim stage.
- Release: During the release stage, the instance is returned to the available pool.
Claim Tokens
Throughout the lifecycle, a claim token will be required to refer back to a specific request. This is a simple alphanumeric string generated by the user and provided to the lifecyle API endpoints.
Advantages of Function Containers on Cycle
Utilizing function containers on Cycle provide several benefits especially when compared to serverless architectures such as AWS Lambda or other platforms.
- Integrate with existing applications on the same network
- Run anything as a function
- Very fast startup times due to pre-provisioning
- Reduces cost and complexity by co-locating task based workloads onto Cycle, on owned infrastructure.