Zudoku
Features

Snapshots

Unikraft Cloud (UKC) supports the ability to deploy stateful apps, that is, apps that can retain state across different scale to 0 incarnations. This mechanism has also the added benefit of significantly reducing app init time, for those heavy-weight apps that take a while to get started when cold started (e.g., Spring Boot, Ruby on Rails, etc.). This is achieved by taking a snapshot of the application memory and restoring it when the application is started again.

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:

TerminalCode
kraft cloud deploy --metro fra0 --scale-to-zero-stateful .

Alternatively, you can add a label to your example's Kraftfile as follows:

YAMLCode
labels: cloud.unikraft.v1.instances/scale_to_zero.stateful: "true"

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:

TerminalCode
stateful: enabled

How it works

With stateful enabled, when you first deploy your app UKC 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). UKC will wait until the app's port is up, and then start the scale to zero process (assuming no traffic is coming to that port). At this point, UKC will save the state of your app, and set the app to standby (consuming no resources).

Next, when traffic arrives, UKC 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

Last modified on