Skip to content

Commit a93f486

Browse files
scaling tutorial
1 parent 473b2af commit a93f486

File tree

7 files changed

+95
-18
lines changed

7 files changed

+95
-18
lines changed

docs/concepts/deployment-modes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Defang provides three deployment modes: development, staging, and production. Th
1919
| Build Resources | Builds will be run with 2x vCPUs | Builds will be run with 2x vCPUs | Builds will be run with 4x vCPUs |
2020
| Databases | Defang will provision resources optimized for burstable memory | | Defang will provision resources optimized for production |
2121
| Static Resources | | | Defang will provision a CDN |
22-
| Deployment | Previous deployments will be spun down before new deployments are spun up. | | Rolling updates will be used to deploy new versions. Defang will gradually replace services while maintaining at least the original number of replicas. |
22+
| Deployment | Previous deployments will be spun down before new deployments are spun up. | | Rolling updates will be used to deploy new versions. Defang will gradually replace services while maintaining at least [the original number of replicas](/docs/tutorials/scaling-your-services). |
2323
| Logging | Logs retained for 1 day to save costs. | | Logs retained for 30 days for compliance. |
2424
| Networking | | | Defang will provision a NAT gateway. |
2525
| DNS | Defang will provision shorter TTLs | | Defang will provision longer TTLs |

docs/concepts/resources.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ description: Customize the resources your Defang services use.
44
sidebar_position: 350
55
---
66

7-
# Resources
7+
# Run-time Resources
88

9-
You can configure the resources available to your Defang services as required. You can configure the CPU, memory, and disk space allocated to your services as well as the number of replicas and whether or not your services requires access to GPUs.
9+
You can configure the resources available to your Defang services as required. You can configure the CPU, and memory allocated to your services as well as the number of replicas and whether or not your services requires access to GPUs.
1010

1111
## Examples
1212

@@ -46,3 +46,29 @@ const service = new defang.DefangService("gpu-service", {
4646
If you require access to GPUs, you can specify this in the `deploy.resources.reservations.devices[0].capabilities` section of your service as in the examples above. You can learn more about this in the [Docker-Compose documentation](https://docs.docker.com/compose/gpu-support/). This is the only supported value in the `deploy.resources.reservations.devices` section.
4747
:::
4848

49+
# Build-time Resources
50+
51+
You can configure the memory requirements and disk space requirements for your image builds by using the `shm_size` property of your service's [`build` specification](https://github.com/compose-spec/compose-spec/blob/main/build.md).
52+
53+
For example,
54+
55+
```yaml
56+
services:
57+
my_service:
58+
build:
59+
context: .
60+
dockerfile: Dockerfile
61+
shm_size: 2G
62+
```
63+
64+
:::info
65+
Defang uses `shm_size` to configure both the memory and disk space available to your build process.
66+
:::
67+
68+
The default `shm_size` values for each platform are as follows. More or less may be specified.
69+
70+
| Platform | `shm_size` Minimum |
71+
|---------------|--------------------|
72+
| AWS | 16G |
73+
| Digital Ocean | 8G |
74+
| GCP | 16G |

docs/faq/questions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ import {Button, ButtonGroup, FormGroup, FormLabel} from "@mui/material"
4545

4646
### Does Defang support auto-scaling?
4747

48-
- No. Defang does not currently support auto-scaling. However, you can manually scale your services by changing the number of replicas in your `compose.yaml` file and running `defang compose up`.
48+
- No. Defang does not currently support auto-scaling. However, you can check out the [Scaling Your Services](/docs/tutorials/scaling-your-services) tutorial, to see how you can scale your services manually with Defang.
4949

5050
### Can I cancel a deployment once it has started?
5151

5252
- No. Once a deployment has started, it cannot be canceled. However, you can always deploy a new version of your app which will replace the current deployment.
5353

5454
### Will deploying a new version of my app cause downtime?
5555

56-
- If you have deployed your application with the `--mode=production` flag, Defang will use the _production_ deployment mode. This mode will provision your app with multiple replicas and will perform a rolling update to ensure zero downtime. If you use another deployment mode, you may experience downtime during the deployment, as Defang will not provision multiple replicas to save cost. See the [Deployment Modes](/docs/concepts/deployment-modes) documentation for more information.
56+
- If you have deployed your application with the `--mode=production` flag, Defang will use the _production_ deployment mode. This mode will perform a rolling update to ensure zero downtime. If you use another deployment mode, you may experience downtime during the deployment, as Defang will not provision multiple replicas to save cost. See the [Deployment Modes](/docs/concepts/deployment-modes) documentation for more information.
5757

5858
### Can I deploy multiple services at once?
5959

docs/faq/warnings-errors.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Common Error Messages
44
description: Common warnings and error messages, and their meanings.
55
---
66

7-
Here are the meanings of common [warning](#warnings) and [error](#errors) messages you may encounter in the Defang CLI.
7+
Here are the meanings of common [warning](#warnings) and [error](#errors) messages you may encounter in the Defang CLI.
88

99
## Warnings
1010

@@ -122,12 +122,4 @@ services:
122122

123123
The image build might fail if the build process uses too much memory. The first thing to try is to limit the size of your project by excluding unnecessary files: the easiest way is to create a `.dockerignore` file that excludes irrelevatn files. Note that Defang will use a default `.dockerignore` file if you don't have one, but that default might not work for some projects and it's always better to make a `.dockerignore` file specific to your project.
124124

125-
If that doesn't work, you can try to increase the memory available to the build process by adding a field `shm_size` to the `build` section in your `compose.yaml` file:
126-
127-
```yaml
128-
services:
129-
service1:
130-
build:
131-
context: .
132-
shm_size: 16g
133-
```
125+
If that doesn't work, see our [Resources](/docs/concepts/resources#build-time-resources) documentation for more information on how to configure the memory requirements and disk space requirements for your image builds.

docs/tutorials/monitoring-your-services.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: How to monitor services deployed with Defang
66

77
# Monitoring Your Services
88

9-
This page will show you how to monitor your service status and logs in Defang.
9+
This tutorial will show you how to monitor your service status and logs in Defang.
1010

1111
## Status
1212

@@ -18,7 +18,7 @@ When deploying to your own cloud, the primary way to monitor your services is th
1818

1919
When deploying to Playground, your service's logs may be viewed in the [Defang Portal](https://portal.defang.dev).
2020

21-
By default when deploying, including to your own cloud, all output (stdout and stderr) from your app is logged and accessible via the [Defang CLI](/docs/getting-started#install-the-defang-cli). You can view these logs in real-time or for a time in the past. You can view logs for all your services, one service, or even one specific deployment of a service.
21+
By default when deploying, including to your own cloud, all output (stdout and stderr) from your app is logged and accessible via the [Defang CLI](/docs/getting-started#install-the-defang-cli). You can view these logs in real-time or for a time in the past. You can view logs for all your services, one service, or even one specific deployment of a service.
2222

2323
### Tailing Live Logs For All Services
2424

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
sidebar_position: 550
3+
title: Scaling Your Services
4+
description: How to scale services deployed with Defang
5+
---
6+
7+
# Scaling Your Services
8+
9+
This tutorial will show you how to scale your services with Defang.
10+
11+
There are two primary ways to scale a service. The first way is to increase the resources allocated to a service. For example, giving a service more CPUs or memory. The second way is to deploy multiple instances of a service. This is called scaling with replicas. Defang makes it easy to do both.
12+
13+
The _Compose Specification_, which is used by defang, includes a [`deploy` section](https://github.com/compose-spec/compose-spec/blob/main/deploy.md) which allows you to configure the deployment configuration for a service. This includes your service's resource requirements and the number of replicas of a service should be deployed.
14+
15+
## Scaling Resource Reservations
16+
17+
In order to scale a service's resource reservations, you will need to update the `deploy` section associated with your service in your application's `compose.yaml` file.
18+
19+
Use the [`resources`](https://github.com/compose-spec/compose-spec/blob/main/deploy.md#resources) section to specify the resource reservation requirements. These are the minimum resources which must be available for the platform to provision your service. You may end up with more resources than you requested, but you will never be allocated less.
20+
21+
For example, if my app needs 2 CPUs and 512MB of memory, I would update the `compose.yaml` file like this:
22+
23+
```yaml
24+
services:
25+
my_service:
26+
image: my_app:latest
27+
deploy:
28+
resources:
29+
reservations:
30+
cpus: '2'
31+
memory: '512M'
32+
```
33+
34+
The minimum resources which can be reserved:
35+
36+
| Resource | Minimum |
37+
|----------|---------|
38+
| CPUs | 0.5 |
39+
| Memory | 512M |
40+
41+
:::info
42+
Note that the `memory` field must be specified as a ["byte value string"](https://github.com/compose-spec/compose-spec/blob/main/11-extension.md#specifying-byte-values) using the `{amount}{byte unit}` format. The supported units are `b` (bytes), `k` or `kb` (kilo bytes), `m` or `mb` (mega bytes) and `g` or `gb` (giga bytes).
43+
:::
44+
45+
## Scaling with Replicas
46+
47+
In order to scale a service's replica count, you will need to update the `deploy` section associated with your service in your application's `compose.yaml` file.
48+
49+
Use the [`replicas`](https://github.com/compose-spec/compose-spec/blob/main/deploy.md#replicas) section to specify the number of containers which should be running at any given time.
50+
51+
For example, if I want to run 3 instances of my app, I would update the `compose.yaml` file like this:
52+
53+
```yaml
54+
services:
55+
my_service:
56+
image: my_app:latest
57+
deploy:
58+
replicas: 3
59+
```

docs/tutorials/updating-your-services.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: How to update services deployed with Defang
66

77
# Updating Your Services
88

9-
This page will show you how to update your services in Defang.
9+
This tutorial will show you how to update your services in Defang.
1010

1111
## Updating a Service
1212

0 commit comments

Comments
 (0)