> ## Documentation Index
> Fetch the complete documentation index at: https://developer.upsun.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Resource configuration

> Configure CPU, RAM, and disk storage on a per-environment basis so your apps and services can run smoothly.

export const DynamicCodeBlock = ({language = 'yaml', filename, icon, lines, wrap, expandable, highlight, focus, children}) => {
  const STORAGE_KEY = 'upsun_versions_cache';
  const COMPOSABLE_STORAGE_KEY = 'upsun_composable_cache';
  const CACHE_TTL = 5 * 60 * 1000;
  const API_URL = 'https://meta.upsun.com/images';
  const COMPOSABLE_API_URL = 'https://meta.upsun.com/composable';
  const DEBUG_PREFIX = '[DynamicCodeBlock cache]';
  const [versionData, setVersionData] = useState(null);
  const [versionError, setVersionError] = useState(false);
  const [composableData, setComposableData] = useState(null);
  const [composableError, setComposableError] = useState(false);
  useEffect(() => {
    const fetchData = async () => {
      let cachedData = null;
      let cachedEtag = null;
      if (typeof localStorage !== 'undefined') {
        try {
          const cached = localStorage.getItem(STORAGE_KEY);
          if (cached) {
            const parsed = JSON.parse(cached);
            cachedData = parsed?.data || null;
            cachedEtag = parsed?.etag || null;
            if (cachedData && Date.now() - parsed.timestamp < CACHE_TTL) {
              return cachedData;
            }
          }
        } catch (err) {
          console.error('Failed to load from cache:', err);
        }
      }
      const requestHeaders = cachedEtag ? {
        'If-None-Match': cachedEtag
      } : {};
      console.debug(`${DEBUG_PREFIX} revalidating`, {
        storageKey: STORAGE_KEY,
        hasCachedData: Boolean(cachedData),
        hasCachedEtag: Boolean(cachedEtag)
      });
      const response = await fetch(API_URL, {
        headers: requestHeaders
      });
      if (response.status === 304 && cachedData) {
        console.debug(`${DEBUG_PREFIX} revalidated (304)`, {
          storageKey: STORAGE_KEY
        });
        if (typeof localStorage !== 'undefined') {
          try {
            const etag = response.headers.get('etag') || cachedEtag;
            localStorage.setItem(STORAGE_KEY, JSON.stringify({
              data: cachedData,
              etag,
              timestamp: Date.now()
            }));
          } catch (err) {
            console.error('Failed to refresh cache metadata:', err);
          }
        }
        return cachedData;
      }
      if (!response.ok) throw new Error(`API request failed: ${response.statusText}`);
      const data = await response.json();
      const etag = response.headers.get('etag');
      console.debug(`${DEBUG_PREFIX} refreshed (200)`, {
        storageKey: STORAGE_KEY,
        etag
      });
      if (typeof localStorage !== 'undefined') {
        try {
          localStorage.setItem(STORAGE_KEY, JSON.stringify({
            data,
            etag,
            timestamp: Date.now()
          }));
        } catch (err) {
          console.error('Failed to cache data:', err);
        }
      }
      return data;
    };
    fetchData().then(data => setVersionData(data)).catch(err => console.error('Failed to fetch version data:', err));
  }, []);
  const findHighestVersion = versionsMap => {
    if (!versionsMap || Object.keys(versionsMap).length === 0) return null;
    const entries = Object.entries(versionsMap);
    const active = entries.filter(([, v]) => v.upsun && v.upsun.status === 'supported' || v.upsun && v.upsun.status === 'deprecated');
    const candidates = active.length > 0 ? active : entries;
    let [highestName] = candidates[0];
    for (let i = 1; i < candidates.length; i++) {
      const [currentName] = candidates[i];
      const cp = currentName.split('.').map(Number);
      const hp = highestName.split('.').map(Number);
      for (let j = 0; j < Math.max(cp.length, hp.length); j++) {
        if ((cp[j] || 0) > (hp[j] || 0)) {
          highestName = currentName;
          break;
        } else if ((cp[j] || 0) < (hp[j] || 0)) {
          break;
        }
      }
    }
    return highestName;
  };
  const getVersion = (lang, requestedVersion = 'latest') => {
    if (lang === 'composable') {
      if (!composableData || !composableData.versions || Object.keys(composableData.versions).length === 0) return null;
      if (requestedVersion && requestedVersion !== 'latest') {
        return (requestedVersion in composableData.versions) ? requestedVersion : null;
      }
      return findHighestVersion(composableData.versions);
    }
    if (!versionData) return null;
    const imageData = versionData[lang];
    if (!imageData || !imageData.versions || Object.keys(imageData.versions).length === 0) {
      return null;
    }
    if (requestedVersion && requestedVersion !== 'latest') {
      return (requestedVersion in imageData.versions) ? requestedVersion : null;
    }
    return findHighestVersion(imageData.versions);
  };
  let code = typeof children === 'string' ? children : String(children || '');
  const codeLines = code.split('\n');
  while (codeLines.length > 0 && codeLines[0].trim() === '') codeLines.shift();
  while (codeLines.length > 0 && codeLines[codeLines.length - 1].trim() === '') codeLines.pop();
  if (codeLines.length > 0) {
    const indents = codeLines.filter(line => line.trim().length > 0).map(line => line.match(/^[ \t]*/)[0].length);
    const minIndent = Math.min(...indents);
    code = codeLines.map(line => line.slice(minIndent)).join('\n');
  }
  code = code.replace(/\{\{version:(.*?)\}\}/g, (match, params) => {
    const parts = params.split(':');
    const lang = parts[0];
    const ver = parts[1] || 'latest';
    const isComposable = lang === 'composable';
    const hasError = isComposable ? composableError : versionError;
    const dataReady = isComposable ? composableData !== null : versionData !== null;
    if (hasError) return '(unavailable)';
    if (dataReady) {
      const resolvedVersion = getVersion(lang, ver);
      return resolvedVersion || match;
    }
    return '...';
  });
  const codeBlockProps = {
    language,
    ...filename && ({
      filename
    }),
    ...icon && ({
      icon
    }),
    ...lines !== undefined && ({
      lines
    }),
    ...wrap !== undefined && ({
      wrap
    }),
    ...expandable !== undefined && ({
      expandable
    }),
    ...highlight && ({
      highlight
    }),
    ...focus && ({
      focus
    })
  };
  return <CodeBlock {...codeBlockProps}>{code}</CodeBlock>;
};

export const VariableBlock = ({name}) => {
  return <var spellCheck={false} title={`Replace '${name}' with your own data`}>{name}</var>;
};

When you first deploy your project, or add a new app or service to it,
Upsun allocates [default resources](/docs/manage-resources/resource-init#default-resources) to each of your containers.
If you don't want to use those default resources, define a different [resource initialization strategy](/docs/manage-resources/resource-init#specify-a-resource-initialization-strategy).

After the initial deployment, or if you opt for the `Manual` [resource initialization strategy](/docs/manage-resources/resource-init#specify-a-resource-initialization-strategy),
you can adjust container resources manually.
To do so, follow the instructions on this page.

Upsun allows you to configure resources (CPU, RAM, and disk) per environment for each app and service.
You can also add instances for each app depending on your needs.

For example, you can scale vertically and allocate more resources to your production and staging environments
than to your development environments.
This flexibility allows you to optimize performance and costs.

You can also scale horizontally if your apps are struggling with high load, or if you're expecting a traffic spike,
by adding more instances for your apps and workers.

<Note>
  For information on costs related to resource usage, see the [Upsun pricing page](https://upsun.com/pricing/).
  You can [monitor these costs](/docs/administration/billing/monitor-billing) in the Console.
</Note>

## Vertical scaling

To define how much CPU, RAM, and disk storage you want to allocate to each individual container,
follow these steps:

<Tabs>
  <Tab title="Using the CLI">
    To set resources for each of your apps and services,
    you can use the Upsun CLI interactive prompts, or run commands manually.

    * **Interactive prompts:**

    Run the `upsun resources:set` command, and follow the prompts to set resources for each app and service.

    <Note>
      For further guidance on how to set resources using the CLI, run the `upsun resources:set --help` command.
      Note that if the deployment fails after you've run `upsun resources:set`,
      you may need to set the resources again.
    </Note>

    After you've set resources, your environment is redeployed,
    which causes a short downtime.

    * **Manual commands:**

    Run the `resources:set` command using the following CLI options:

    | CLI option | Description                                                                                                                                                                                                           |
    | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
    | `size`     | Allows you to define how much CPU you want to allocate to each app or service.<br />The amount of CPU then determines how much RAM is also allocated, based on the [container profile](#advanced-container-profiles). |
    | `disk`     | Allows you to define how much disk/storage you want to allocate to each app or service. Disk space and inode limits scale together.                                                                                   |

    *Example 1:*

    The following command allocates `0.1` CPU to the `frontend` app, `0.25` CPU to the `backend` app, and `1` CPU to the `database` service.
    The amount of RAM these settings translate into depends on each [container profile](#advanced-container-profiles).

    ```bash Terminal theme={null}
    upsun resources:set --size frontend:0.1,backend:0.25,database:1
    ```

    *Example 2:*

    The following command allocates `640 MB` of disk to the `backend` app, and `2048 MB` to the `database` service:

    ```bash Terminal theme={null}
    upsun resources:set --disk backend:640,database:2048
    ```

    *Example 3:*

    You can also use wildcards. For example, if you have two apps named `frontend` and `backend`,
    you could allocate the same CPU and RAM combination to both by using the following command:

    ```bash Terminal theme={null}
    upsun resources:set --size '*end:0.1'
    ```
  </Tab>

  <Tab title="Using the Console">
    1. Open your project.
    2. Click the **Configure resources** button in the project card or the **App & Services** panel:
           <img src="https://mintcdn.com/upsun-c9761871/7cK3KMJBgO7MXm_y/images/flexible-resources/configure-button-project-card.png?fit=max&auto=format&n=7cK3KMJBgO7MXm_y&q=85&s=197a9eee0f2c50cdf9d817090984510f" alt="Project card" width="460" height="283" data-path="images/flexible-resources/configure-button-project-card.png" />
    3. For each app and service, select a CPU & RAM combination, and enter the amount of disk/storage you want to allocate.
           <img src="https://mintcdn.com/upsun-c9761871/7cK3KMJBgO7MXm_y/images/flexible-resources/configure-flexible-resources.png?fit=max&auto=format&n=7cK3KMJBgO7MXm_y&q=85&s=032188d99bff1e81e2ff34d1d4f2ceed" alt="Configure your resources on the current environment window" width="2880" height="1600" data-path="images/flexible-resources/configure-flexible-resources.png" />
           <Note>
             The values from the **CPU & RAM** menu depend on the [container profile](#advanced-container-profiles) of each instance.<br />
             If you deploy several instances of your app, the selected CPU & RAM combination isn't divided between those instances.
             Each instance benefits from the full, selected CPU & RAM.
           </Note>
    4. Click **Save**.<br />
       You environment is redeployed, which causes a short downtime.
  </Tab>
</Tabs>

## Horizontal scaling

For apps and workers, you can also define how many instances you want to deploy.
To do so, follow these steps:

<Note>
  When you have several instances of an app, the Upsun router randomly distributes requests to available instances.
</Note>

<Tabs>
  <Tab title="Using the CLI">
    To define how many instances of an app or worker you want to deploy,
    you can use the Upsun CLI interactive prompts,
    or run commands manually.

    * **Interactive prompts:**

      Run the `upsun resources:set` command, and follow the prompts to set resources for each app and service.

          <Note>
            For further guidance on how to set resources using the CLI, run the `upsun resources:set --help` command.

            Note that if the deployment fails after you've run `upsun resources:set`,
            you may need to set the resources again.
          </Note>

    * **Manual commands:**

      To scale an app or worker, run the following command:

      ```bash Terminal theme={null}
      upsun resources:set --count <APP_NAME>:<NUMBER_OF_INSTANCES>
      ```

      For example, to scale your `myapp` app to 3 instances, run the following command:

      ```bash Terminal theme={null}
      upsun resources:set --count myapp:3
      ```

      You can also set the same instance count for all your apps using a wildcard.
      To do so, run the following command:

      ```bash Terminal theme={null}
      upsun resources:set --count '*:<NUMBER_OF_INSTANCES>'
      ```

      For example, to scale all your apps to 3 instances, run the following command:

      ```bash Terminal theme={null}
      upsun resources:set --count '*:3'
      ```

          <Note>
            For further guidance on how to set resources using the CLI, run the `upsun resources:set --help` command.

            After you've set the number of instances for your apps and workers, your environment is redeployed.
            If you've made no other changes, this redeployment causes no downtime.

            If the redeployment fails after you've run `upsun resources:set`,
            you may need to set the resources again.
          </Note>
  </Tab>

  <Tab title="Using the Console">
    1. Open your project.
    2. Click the **Configure resources** button in the project card or the **App & Services** panel:
           <img src="https://mintcdn.com/upsun-c9761871/7cK3KMJBgO7MXm_y/images/flexible-resources/configure-button-project-card.png?fit=max&auto=format&n=7cK3KMJBgO7MXm_y&q=85&s=197a9eee0f2c50cdf9d817090984510f" alt="Project card" width="460" height="283" data-path="images/flexible-resources/configure-button-project-card.png" />
    3. For each of your apps and workers, select the number of instances you want to deploy.
           <img src="https://mintcdn.com/upsun-c9761871/7cK3KMJBgO7MXm_y/images/flexible-resources/configure-flexible-resources.png?fit=max&auto=format&n=7cK3KMJBgO7MXm_y&q=85&s=032188d99bff1e81e2ff34d1d4f2ceed" alt="Configure your resources on the current environment window" width="2880" height="1600" data-path="images/flexible-resources/configure-flexible-resources.png" />
           <Note>
             If you deploy several instances of your app, the [selected CPU & RAM combination](#vertical-scaling) isn't divided between those instances.
             Each instance benefits from the full, selected CPU & RAM.
           </Note>
    4. Click **Save**.<br />
       Your environment is redeployed.
       If you've only made changes to the number of instances for your apps and workers,
       this redeployment causes no downtime.
  </Tab>
</Tabs>

<Info>
  <h4>Autoscaling</h4>
  Upsun provides [**native autoscaling** support](/docs/manage-resources/autoscaling). You can configure thresholds for metrics such as CPU, RAM, and request latency. Resources will automatically adjust horizontally to meet demand.
</Info>

## View application instance details

Upsun maintains a real-time indexed list of an application's instances and their IP addresses in the project's `/run/peers.json` file. You might view this read-only file to gain insight into how your application instances are distributed. Upsun maintains this file whether you scale instances manually or have autoscaling enabled.

Distributed applications (for example, those running on Elixir and Erlang) and applications that can scale horizontally must be aware of all its instances in order to coordinate activities such as setting up clusters and handling application failures.

The number of instances in this file at any time matches the number of application instances shown on the Configure Resources page of the Console.

To view the contents of the file, run this command from the root of your project directory:

```sh theme={null}
cat /run/peers.json | jq
```

The output is similar to this:

```json theme={null}
{
  "hello_distributed.1": "123.456.789.10",
  "hello_distributed.3": "123.456.789.20",
  "hello_distributed.2": "123.456.789.30",
  "hello_distributed.0": "123.456.789.40"
}
```

## Advanced: Container profiles

### Shared CPU container sizes

By default, Upsun allocates a container profile to each app and service depending on the range of resources it's expected to need.

Each container profile gives you access to a specific list of CPU and RAM combinations.
Using the Upsun CLI or Console, you can then pick a CPU and RAM combination for each of your apps and services.

There are four container profiles available: `HIGH_CPU`, `BALANCED`, `HIGH_MEMORY`, and `HIGHER_MEMORY`.
The following table displays the different CPU and RAM combinations each container profile provides:

| CPU  | `HIGH_CPU` | `BALANCED` | `HIGH_MEMORY` | `HIGHER_MEMORY` |
| ---- | ---------- | ---------- | ------------- | --------------- |
| 0.1  | 64 MB      | 352 MB     | 448 MB        | 864 MB          |
| 0.25 | 128 MB     | 640 MB     | 832 MB        | 1472 MB         |
| 0.5  | 224 MB     | 1088 MB    | 1408 MB       | 2368 MB         |
| 1    | 384 MB     | 1920 MB    | 2432 MB       | 3840 MB         |
| 2    | 704 MB     | 2800 MB    | 4032 MB       | 6336 MB         |
| 4    | 1216 MB    | 4800 MB    | 6720 MB       | 10496 MB        |
| 6    | 1728 MB    | 6080 MB    | 9024 MB       | 14080 MB        |
| 8    | 2240 MB    | 7296 MB    | 11200 MB      | 17408 MB        |

You can check which container profile is set for an app or service in your project from the Console.
To do so, navigate to your environment and select the app or service in the tree on the left-hand side:

<img src="https://mintcdn.com/upsun-c9761871/7cK3KMJBgO7MXm_y/images/flexible-resources/check-container-profile.png?fit=max&auto=format&n=7cK3KMJBgO7MXm_y&q=85&s=e37987aa5a6381068fb1b22b57f5f1be" alt="Apps and services tree" width="476" height="511" data-path="images/flexible-resources/check-container-profile.png" />

For information on resource-related costs, see the [Upsun pricing page](https://upsun.com/pricing/).

### Guaranteed CPU container sizes

When selecting a container profile for [Guaranteed CPU](/docs/manage-resources/guaranteed-resources), use the table below to identify available CPU and memory combinations. These predefined sizes help you match resource profiles to your application’s workload requirements.

| CPU | HIGH\_CPU | BALANCED | HIGH\_MEMORY | HIGHER\_MEMORY |
| --- | --------- | -------- | ------------ | -------------- |
| 2   | 4 GB      | 8 GB     | 16 GB        | not supported  |
| 4   | 8 GB      | 16 GB    | 32 GB        | not supported  |
| 8   | 16 GB     | 32 GB    | 64 GB        | not supported  |
| 16  | 32 GB     | 64 GB    | 128 GB       | not supported  |
| 32  | 64 GB     | 128 GB   | 256 GB       | not supported  |
| 48  | 96 GB     | 192 GB   | 384 GB       | not supported  |
| 64  | 128 GB    | 256 GB   | 512 GB       | not supported  |

<Note>
  Guaranteed CPU is not currently available on [OVHcloud regions](/docs/development/regions) and some CPU sizes may not be available in all regions.

  For more information about the available configurations and sizes, visit the Upsun [pricing calculator](https://upsun.com/pricing/calculator/).
</Note>

### Default container profiles

The following table shows the default container profiles Upsun applies when first deploying your project.

| Container                                             | Default profile |
| ----------------------------------------------------- | --------------- |
| [C#/.Net Core](/docs/languages/dotnet)                | HIGH\_CPU       |
| [ClickHouse](/docs/add-services/clickhouse)           | HIGH\_MEMORY    |
| [Elasticsearch](/docs/add-services/elasticsearch)     | HIGH\_MEMORY    |
| [Elixir](/docs/languages/elixir)                      | HIGH\_CPU       |
| [Go](/docs/languages/go)                              | HIGH\_CPU       |
| [Gotenberg](/docs/add-services/gotenberg)             | HIGH\_MEMORY    |
| [Headless Chrome](/docs/add-services/headless-chrome) | HIGH\_CPU       |
| [InfluxDB](/docs/add-services/influxdb)               | HIGH\_MEMORY    |
| [Java](/docs/languages/java)                          | HIGH\_MEMORY    |
| [JavaScript/Node.js](/docs/languages/nodejs)          | HIGH\_CPU       |
| [Kafka](/docs/add-services/kafka)                     | HIGH\_MEMORY    |
| [MariaDB/MySQL](/docs/add-services/mysql)             | HIGH\_MEMORY    |
| [Memcached](/docs/add-services/memcached)             | BALANCED        |
| [MongoDB](/docs/add-services/mongodb)                 | HIGH\_MEMORY    |
| [Network Storage](/docs/add-services/network-storage) | HIGH\_MEMORY    |
| [OpenSearch](/docs/add-services/opensearch)           | HIGH\_MEMORY    |
| [Oracle MySQL](/docs/add-services/mysql)              | HIGH\_MEMORY    |
| [PHP](/docs/languages/php)                            | HIGH\_CPU       |
| [PostgreSQL](/docs/add-services/postgresql)           | HIGH\_MEMORY    |
| [Python](/docs/languages/python)                      | HIGH\_CPU       |
| [RabbitMQ](/docs/add-services/rabbitmq)               | HIGH\_MEMORY    |
| [Redis](/docs/add-services/redis)                     | BALANCED        |
| [Ruby](/docs/languages/ruby)                          | HIGH\_CPU       |
| [Rust](/docs/languages/rust)                          | HIGH\_CPU       |
| [Solr](/docs/add-services/solr)                       | HIGH\_MEMORY    |
| [Valkey](/docs/add-services/valkey)                   | BALANCED        |
| [Varnish](/docs/add-services/varnish)                 | HIGH\_MEMORY    |
| [Vault KMS](/docs/add-services/vault)                 | HIGH\_MEMORY    |

### Adjust a container profile

In most cases, it's best not to adjust container profiles.
As a best practice, Upsun recommends adjusting the profile of a container **only if the CPU/RAM ratio doesn’t match how the container scales**,
taking into account both production and preview (staging and development) environments.

To adjust a container profile, amend the value of the `container_profile` key in your configuration:

<DynamicCodeBlock language="yaml" filename=".upsun/config.yaml">
  {`
      applications:
        <APP_NAME>:
          container_profile: HIGH_MEMORY

      services:
        <SERVICE_NAME>:
          type: <SERVICE_TYPE>:<VERSION>
          container_profile: HIGHER_MEMORY`
  }
</DynamicCodeBlock>
