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.). Taking a snapshot of the app memory and restoring it when the app starts again does this.
Setting it up
The quickest way to set this up is via the --scale-to-zero-stateful flag of
the kraft cloud deploy or kraft cloud instance create commands, for example:
Code(bash)
As an alternative, you can add a label to your example's Kraftfile as follows:
Code(yaml)
You can see an example of such a Kraftfile and label in the Spring Boot
example.
Once deployed, you can check that this mechanism is actually enabled for your
app via the kraft cloud instance get <instance name> command:
Code(ansi)
How it works
With stateful enabled, when you first deploy your app Unikraft Cloud will bring it up normally and let it fully initialize (which may be fast, or take seconds or minutes, depending on your app's init time). Unikraft Cloud will wait until the app's port gets up, and then start the scale-to-zero process (assuming no traffic is coming to that port). At this point, Unikraft Cloud will save the state of your app, and set the app to standby (consuming no resources).
Next, when traffic arrives, Unikraft Cloud will bring up the app including its saved state, ensuring statefulness across different scale-to-zero and scale to one cycles, but also eliminating any long initialization times from heavyweight apps.
Learn More
- The
kraft cloudcommand-line tool reference, and in particular thedeployandinstancesubcommands. - Unikraft Cloud's REST API reference, and in particular the section on stateful scale-to-zero.