Snapshots
Unikraft Cloud supports the ability to deploy stateful apps. These apps can keep state across different scale-to-zero incarnations. This mechanism also reduces app init time. Heavy-weight apps take a while to get started when cold started (for example, Spring Boot, Ruby on Rails, etc.). You can reduce this initialization time by taking a snapshot of the app memory and restoring it when the app starts again.
Setting it up
The quickest way to set this up is via the legacy CLI --scale-to-zero-stateful flag:
As an alternative, you can add a label to your example's Kraftfile as follows:
You can see an example of such a Kraftfile and label in the Spring Boot example.
Once deployed, you can check whether this mechanism works for your app via the CLI:
Code
How it works
When you enable stateful mode and first deploy your app, Unikraft Cloud brings it up normally and lets it fully initialize. This may be fast or take seconds or minutes, depending on your app's init time. Unikraft Cloud waits until the app's exposed port becomes available, and then starts the scale-to-zero process. This assumes no traffic is coming to that port. At this point, Unikraft Cloud saves the state of your app and sets the app to standby (consuming no resources).
Next, when traffic arrives, Unikraft Cloud brings up the app including its saved state. This ensures statefulness across scale-to-zero and scale-to-one cycles. It also eliminates long initialization times from heavyweight apps.
Learn more
- The CLI reference and the legacy CLI reference.
- Unikraft Cloud's REST API reference, and in particular the scale-to-zero schema.