Skip to content

Commit

Permalink
Merge pull request #86 from wasmerio/instaboot
Browse files Browse the repository at this point in the history
Document InstaBoot
  • Loading branch information
syrusakbary authored Jun 5, 2024
2 parents 0309de0 + 5e5ea44 commit 7ce2520
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Documentation for Wasmer's Products",
"scripts": {
"dev": "next dev",
"build": "next build && next export -o release",
"build": "next build --no-lint && next export -o release",
"start": "next start"
},
"repository": {
Expand Down
26 changes: 26 additions & 0 deletions pages/edge/configuration/app-configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ env:
cli_args:
- arg1
- arg2

capabilities:
# Fast startup with instaboot
instaboot:
requests:
- path: /
- path: /_bootstrap
```
## Fields
Expand Down Expand Up @@ -104,6 +111,25 @@ The `debug` field is used to enable debug mode for the application. This in turn
- Required: `false`
- Default: `false`

### `capabilities`

#### `instaboot`

Enable fast application startup with startup snapshots.

See [InstaBoot](/edge/learn/instaboot) for more details.

```
capabilities:
instaboot:
requests:
- path: /
- path: /_bootstrap
# Optionally request settings:
method: POST
body: "custom body"
```
### `health_checks`
The `health_checks` field is used to check if an application is working correctly. If the healthchecks fail, edge will restart the application. It is **optional** and its an array of healtcheck objects
Expand Down
1 change: 1 addition & 0 deletions pages/edge/learn/_meta.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"apps": "Apps",
"instaboot": "InstaBoot",
"deployment-modes": "Deployment Modes",
"remote-sessions": "Remote Sessions",
"connecting-domains-to-edge": "Connecting Custom Domains to Edge"
Expand Down
148 changes: 148 additions & 0 deletions pages/edge/learn/instaboot.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# InstaBoot - Fast Application Startup with Snapshots

Cold start times can be a significant issue for serverless
cloud platforms, especially when apps are spawned on demand all over the globe.

Wasmer Edge provides a special feature called `InstaBoot`, which can
significantly reduce cold start times of Edge applications.

## What is InstaBoot?

InstaBoot allows fast startup by creating a snapshot of your app that is fully
initialized and ready to serve requests.

Snapshots are created by starting a new application instance and warming it up
with a series of warm-up requests to the application.
These warm-up requests have to be specified in your app configuration.

Once a snapshot is created, Edge can use the snapshot to start apps almost instantly!

How impactful InstaBoot is depends on the programming language and the
how much startup logic your application has.

## How to use Edge InstaBoot

Here is a quick guide on how to making your applications start faster:

Modify your `app.yaml` configuration to include the following:

```yaml
kind: wasmer.io/App.v0
source: ...
# ...
capabilities:
# Enable InstaBoot:
instaboot:
# We provide a list of HTTP requests that will be used to pre-warm the
# application.
# These endpoints should make sure that the most important and expensive
# parts of the application are loaded, caches are pre-populated, ...
#
# NOTE: all warm-up requests will also contain the "x-edge-instaboot" request
# header, allowing you to detect warm-up requests without using a custom
# endpoint.
requests:
# Load the homepage
- path: /
# Hit a special endpoint that makes sure caches are populated ...
- path: /_bootstrap
# Optionally specify the request method and body.
method: POST
body: "{\"warm-up\": true}"
```

That's it!

Once you deploy your application again with `wasmer deploy`, Edge will
automatically prepare a snapshot of your application.

**Note**:

Specifying specific requests is optional.
You can also just specify `instaboot: {}`. Edge will then only send a single
warm-up request to `/`. You should usually specify specific requests though.

## Resetting InstaBoot Snapshots

You might find yourself in a situation where you want to reset the InstaBoot
snapshots for your application. This can be useful if some external state
has changed, and the warm-up requests are no longer valid.

You have different options available:

* Deploy a new version of your app
Each version of your application will have its own snapshot, so
deploying a new version will automatically reset all generated snapshots as well.
Just run `wasmer deploy` again to deploy a new version.

* Manual reset with the CLI:
You can also manually reset the snapshots for your application with the CLI.
Run the following command:

```sh
wasmer app cache clear --instaboot [<app-ident>]
```

Replace `<app-ident>` with the name or ID of your application.

* Resetting snapshots in the UI
You can also reset snapshots in the Edge UI. Go to the application details
page, go to settings, and click the "Reset caches" button.

## When to use InstaBoot

The effectiveness of InstaBoot depends on the programming language of the app,
and if the app has expensive startup logic.

For a basic Rust web server that just opens a socket and has no other startup
logic, InstaBoot will not make any notable difference.

For some languages like `PHP` or `Python`, which need to load and
prepare code at runtime, it can have a significant impact.

You might also have more expensive startup code, like loading translations from
a database, or populating caches. InstaBoot can help here as well.

In general, InstaBoot is likely beneficial for most interpreted languages
(PHP, Python, JavaScript, ...), and for applications that need to do expensive
pre-fetching of state.

Good use cases:

* Any PHP application
PHP uses OpCache to cache pre-compiled PHP code. This makes a *very big*
difference for performance.
For PHP you will always want to enable InstaBoot, and make sure the warm-up
requests cover most important endpoints.
* Python
Like PHP, Python will also have to load code at runtime and prepare it for
execution. While the difference is not quite as stark as with PHP, the speedup
can still be very significant.
* WinterJS (Javascript):
While WinterJS startup times are generally fast, InstaBoot can still often
cut cold start times in half.
* Expensive cache warm-up
* Loading translations or other shared state from a database
* ...

## How it works

As a user, you do not have to worry about the details of how InstaBoot works. It
will just magically speed up your application cold start times.

If you are curious, here is a brief overview:

* When Edge receives a request, it will check if there is a snapshot available
for the application.
* If no snapshot is available, a new instance of the application will be started
and the initialization requests are sent to the instance.
* After the warm-up requests succeed, a snapshot of the application will be
created.
* The snapshot is stored in a cache, and can be distributed across the whole
Edge cluster to prevent redundant re-initialization on each separate server.
* For subsequent requests, the snapshot will be used to restore the application
to the state it was in after the warm-up requests succeeded.

To avoid impacting cold start times if no snapshot is available yet,
the application will be started normally to serve the request immediately.
Snapshot will be created in a separate, dedicated instance in a background task.

0 comments on commit 7ce2520

Please sign in to comment.