Setting up Scale to 0
With conventional cloud platforms you need to keep at least one instance running at all times to be able to respond to incoming requests: performing a just-in-time cold boot is simply too time-consuming and would create a response latency of multiple seconds or worse.
This is not the case with KraftCloud. Based on extremely lightweight unikernel technology, instances on KraftCloud are able to cold boot within milliseconds, while providing the same strong, hardware-level isolation afforded by virtual machines.
Millisecond cold boots allow us to perform low-latency scale-to-zero: that is, as long as no traffic is flowing through your instance, it consumes no resources and so you’re not charged for it. On KraftCloud you’re only charged for when your instances do useful work for you. When the next connection arrives, KraftCloud takes care of transparently cold booting (can it be called cold booting if it’s milliseconds?) your instance and replying — all of that within a negligible amount with respect to Internet RTTs and so unbeknownst to your end users and clients.
Setting it Up
Enabling scale to 0 on KraftCloud is simple: just add the -0
flag to kraft cloud deploy
when
creating your instance. Let’s start an NGINX instance and set it to scale to 0:
This command will create the NGINX instance with scale to 0 enabled:
Note that at first the status is listed as running
in the output of the kraft cloud deploy
command.
Let’s check the instance’s status:
You should see output similar to:
Notice the state is now set to standby
? At first kraft cloud deploy
sets the state
to running
, but since we specified scale to 0 via the -0
flag, KraftCloud put the
instance immediately to sleep (more accurately, it stopped it, but it keeps state to
start it again when needed).
You can also check that scale to 0 is enabled through the kraft cloud scale
command:
which outputs:
Note the min size
(0) and max size
(1) fields — these mean that the service group
can scale from max 1 instance to min 0 instances, meaning that scale to 0 is enabled.
Testing Scale to 0
Now let’s take this out for a spin. Try using curl
or your browser to see scale to 0
(well, scale to 1 in this case!) in action:
You should get an NGINX response with no noticeable delay. For fun, try to use the
following command to see if you can catch the instance’s STATE
field changing
from standby
to running
If you curl enough, you should see the STATE
turn to a green running
from time to time.
Learn More
- The
kraft cloud
CLI reference, and in particular the services and scale sub-commands. - KraftCloud’s REST API reference, and in particular the section on service groups and autoscale.