

# Scaling game hosting capacity with Amazon GameLift Servers
Scaling

Hosting capacity, measured in instances, represents the number of game sessions that Amazon GameLift Servers can host concurrently and the number of concurrent players that those game sessions can accommodate. One of the most challenging tasks with game hosting is scaling capacity to meet player demand without wasting money on resources that you don't need. 

Capacity is adjusted at the fleet location level. All fleets have at least one location: the fleet's home AWS Region. When viewing or scaling capacity, the information is listed by location, including the fleet's home Region and any additional remote locations.

You can manually set the number of instances to maintain, or you can set up auto scaling to dynamically adjust capacity as player demand changes. We recommend that you start by turning on the target-based auto scaling option. The goal of target-based auto scaling is to maintain enough hosting resources to accommodate current players plus a little extra to handle unexpected spikes in player demand. For most games, target-based auto scaling offers a highly effective scaling solution.

You can do most fleet scaling activities using the Amazon GameLift Servers console. You can also use an AWS SDK or the AWS Command Line Interface (AWS CLI) with the [service API for Amazon GameLift Servers](https://docs.aws.amazon.com/gameliftservers/latest/apireference/Welcome.html).

**Topics**
+ [

## To manage fleet capacity in the console
](#fleet-manage-capacity-howto)
+ [

# Set Amazon GameLift Servers capacity limits
](fleets-capacity-limits.md)
+ [

# Manually set capacity for an Amazon GameLift Servers fleet
](fleets-updating-capacity.md)
+ [

# Auto-scale fleet capacity with Amazon GameLift Servers
](fleets-autoscaling.md)
+ [

# Manage Scaling an Amazon GameLift Servers Fleet To/From Zero
](fleets_scale-to-from-zero.md)
+ [

# Scale Amazon GameLift Servers container fleets
](containers-scaling.md)

## To manage fleet capacity in the console


1. Open the [Amazon GameLift Servers console](https://console.aws.amazon.com/gamelift/).

1. In the navigation pane, choose **Hosting**, **Fleets**.

1. On the **Fleets** page, choose the name of an active fleet to open the fleet's detail page.

1. Choose the **Scaling** tab. On this tab, you can:
   + View historical scaling metrics for the entire fleet.
   + View and update capacity settings for each fleet location, including scaling limits and current capacity settings.
   + Update target-based auto scaling, view rule-based auto scaling policies applied to the entire fleet, and suspend auto scaling activity for each location.

# Set Amazon GameLift Servers capacity limits
Set hosting capacity limits

When scaling hosting capacity for an Amazon GameLift Servers fleet location, either manually or by auto scaling, consider the location's scaling limits. All fleet locations have a minimum and maximum limit that define the allowed range for the location's capacity. By default, limits on fleet locations have a minimum of 0 instances and a maximum of 1 instance. Before you can scale a fleet location, adjust the limits.

If you're using auto scaling, the maximum limit allows Amazon GameLift Servers to scale up a fleet location to meet player demand but prevents runaway hosting costs, such as during a DDOS attack. Set up an [Amazon CloudWatch alarm](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html) to notify you when capacity approaches the maximum limit, so you can evaluate the situation and manually adjust as needed. (You can also [create a billing alarm](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/monitor_estimated_charges_with_cloudwatch.html) to monitor AWS costs.) The minimum limit is useful to maintain hosting availability, even when player demand is low.

You can set capacity limits for a fleet's locations in the [Amazon GameLift Servers console](https://console.aws.amazon.com/gamelift/) or by using the AWS Command Line Interface (AWS CLI).

## To set capacity limits


------
#### [ Console ]

1. Open the [Amazon GameLift Servers console](https://console.aws.amazon.com/gamelift/).

1. In the navigation pane, choose **Hosting**, **Fleets**.

1. On the **Fleets** page, choose the name of an active fleet to open the fleet's detail page.

1. On the **Scaling** tab, under **Scaling capacity**, select a fleet location, and then choose **Edit**.

1. In the **Edit scaling capacity** dialog box, set instance counts for **Min size**, **Desired instances**, and **Max size**.

1. Choose **Confirm**.

------
#### [ AWS CLI ]

1. **Check current capacity settings.** In a command line window, use the [describe-fleet-location-capacity](https://docs.aws.amazon.com/cli/latest/reference/gamelift/describe-fleet-location-capacity.html) command with the fleet ID and location that you want to change capacity for. This command returns a [FleetCapacity](https://docs.aws.amazon.com/gameliftservers/latest/apireference/API_FleetCapacity.html) object that includes the location's current capacity settings. Determine whether the new instance limits can accommodate the current desired instances setting.

   ```
   aws gamelift describe-fleet-location-capacity \
       --fleet-id <fleet identifier> \
       --location <location name>
   ```

1. **Update limit settings.** In a command line window, use the [update-fleet-capacity](https://docs.aws.amazon.com/cli/latest/reference/gamelift/update-fleet-capacity.html) command with the following parameters. You can adjust both instance limits and desired instance count with the same command.

   ```
   --fleet-id <fleet identifier>
   --location <location name>
   --max-size <maximum capacity for scaling>
   --min-size <minimum capacity for scaling>
   --desired-instances <fleet capacity goal>
   ```

   Example:

   ```
   aws gamelift update-fleet-capacity \
       --fleet-id fleet-2222bbbb-33cc-44dd-55ee-6666ffff77aa \
       --location us-west-2 \
       --max-size 10 \
       --min-size 1 \
       --desired-instances 10
   ```

If your request is successful, Amazon GameLift Servers returns the fleet ID. If the new `max-size` or `min-size` value conflicts with the current `desired-instances` setting, Amazon GameLift Servers returns an error.

------

# Manually set capacity for an Amazon GameLift Servers fleet
Manually set fleet capacity

When you create a new fleet, Amazon GameLift Servers automatically sets the desired instances to one instance in each fleet location. Then, Amazon GameLift Servers deploys one new instance in each location. To change fleet capacity, you can add a target-based auto scaling policy, or you can manually set the number of instances that you want for a location. 

Setting a fleet's capacity manually can be useful when you don't need auto scaling or when you need to hold capacity at a specified level. Manually setting capacity works only if you aren't using a target-based auto scaling policy. If you have a target-based auto scaling policy, it immediately resets the desired capacity based on its own scaling rules.

You can manually set capacity in the Amazon GameLift Servers console or by using the AWS Command Line Interface (AWS CLI). The fleet's status must be active.

## Suspend auto scaling


You can suspend all auto scaling activity for each fleet location. With auto scaling suspended, the desired number of instances in the fleet location remains the same unless manually changed. When you suspend auto scaling for a location, it affects the fleet's current policies and any policies that you may define in the future.

## To manually set fleet capacity


------
#### [ Console ]

1. Open the [Amazon GameLift Servers console](https://console.aws.amazon.com/gamelift/).

1. In the navigation pane, choose **Hosting**, **Fleets**.

1. On the **Fleets** page, choose the name of an active fleet to open the fleet's detail page.

1. On the **Scaling** tab, under **Suspended auto scaling locations**, select each location that you want to suspend auto scaling for, and then choose **Suspend**.

1. Under **Scaling capacity**, select a location that you want to set manually, and then choose **Edit**.

1. In the **Edit scaling capacity** dialog box, set your preferred value for **Desired instances**, and then choose **Confirm**. This tells Amazon GameLift Servers the number of instances to maintain in an active state, ready to host game sessions.

Amazon GameLift Servers responds to the changes by deploying additional instances or shutting down unneeded ones. As Amazon GameLift Servers completes this process, the number of active instances in the location changes to match the updated desired instances value. This process may take a little time.

------
#### [ AWS CLI ]

1. **Check current capacity settings.** In a command line window, use the [describe-fleet-location-capacity](https://docs.aws.amazon.com/cli/latest/reference/gamelift/describe-fleet-location-capacity.html) command with the fleet ID and location that you want to change capacity for. This command returns a [FleetCapacity](https://docs.aws.amazon.com/gameliftservers/latest/apireference/API_FleetCapacity.html) object that includes the location's current capacity settings. Determine whether the instance limits can accommodate the new desired instances setting.

   ```
   aws gamelift describe-fleet-location-capacity \
       --fleet-id <fleet identifier> \
       --location <location name>
   ```

1. **Update desired capacity.** Use the [update-fleet-capacity](https://docs.aws.amazon.com/cli/latest/reference/gamelift/update-fleet-capacity.html) command with the fleet ID, location, and a new value for desired instances. If this value falls outside the current limit range, you can adjust limit values in the same command.

   ```
   --fleet-id <fleet identifier>
   --location <location name>
   --desired-instances <fleet capacity as an integer>
   --max-size <maximum capacity>    [Optional]
   --min-size <minimum capacity>    [Optional]
   ```

   Example:

   ```
   aws gamelift update-fleet-capacity \
       --fleet-id fleet-2222bbbb-33cc-44dd-55ee-6666ffff77aa \
       --location us-west-2 \
       --desired-instances 5 \
       --max-size 10 \
       --min-size 1
   ```

If your request is successful, Amazon GameLift Servers returns the fleet ID. If the new desired instances setting is outside the minimum and maximum limits, Amazon GameLift Servers returns an error.

------

# Auto-scale fleet capacity with Amazon GameLift Servers
Auto scale fleet capacity

Use auto scaling in Amazon GameLift Servers to dynamically scale your fleet capacity in response to game server activity. As players arrive and start game sessions, auto scaling can add more instances; as player demand wanes, auto scaling can terminate unneeded instances. Auto scaling is an effective way to minimize your hosting resources and costs, while still providing a smooth, fast player experience.

To use auto scaling, you create scaling policies that tell Amazon GameLift Servers when to scale up or down. There are two types of scaling policies: target-based and rule-based. The target-based approach—target tracking—is a complete solution. We recommend it as the simplest and most effective option. Rule-based scaling policies require you to define each aspect of the auto scaling decision-making process, which is useful for addressing specific issues. This solution works best as a supplement to target-based auto scaling.

You can manage target-based auto scaling using the Amazon GameLift Servers console, the AWS Command Line Interface (AWS CLI), or an AWS SDK. You can manage rule-based auto scaling using the AWS CLI or an AWS SDK only, although you can view rule-based scaling policies in the console.

**Topics**
+ [

# Target-based auto scaling
](fleets-autoscaling-target.md)
+ [

# Auto scale with rule-based policies
](fleets-autoscaling-rule.md)

# Target-based auto scaling


Target-based auto scaling for Amazon GameLift Servers adjusts capacity levels based on the fleet metric `PercentAvailableGameSessions`. This metric represents the fleet's available buffer for sudden increases in player demand.

The primary reason for maintaining a capacity buffer is player wait time. When game session slots are ready and waiting, it takes seconds to get new players into game sessions. If no resources are available, players must wait for existing game sessions to end or for new resources to become available. It can take minutes to start up new instances and server processes.

When setting up target-based auto scaling, specify the size of the buffer that you want the fleet to maintain. Because `PercentAvailableGameSessions` measures the percentage of available resources, the actual buffer size is a percentage of the total fleet capacity. Amazon GameLift Servers adds or removes instances to maintain the target buffer size. With a large buffer, you minimize wait time, but you also pay for extra resources that you may not use. If your players are more tolerant of wait times, you can lower costs by setting a small buffer.

## To set target-based auto scaling


------
#### [ Console ]

1. Open the [Amazon GameLift Servers console](https://console.aws.amazon.com/gamelift/).

1. In the navigation pane, choose **Hosting**, **Fleets**.

1. On the **Fleets** page, choose the name of an active fleet to open the fleet's detail page.

1. Choose the **Scaling** tab. This tab displays the fleet's historical scaling metrics and contains controls for adjusting current scaling settings. 

1. Under **Scaling capacity**, check that the **Min size** and **Max size** limits are appropriate for the fleet. With auto scaling enabled, capacity adjusts between these two limits.

1. In **Target-based auto scaling policy**, choose **Edit**.

1. In the **Edit target-based auto scaling policy** dialog box, for **Percent available game sessions**, set the percentage that you want to maintain, and then choose **Confirm**. After you've confirmed the settings, Amazon GameLift Servers adds a new target-based policy under **Target-based auto scaling policy**.

------
#### [ AWS CLI ]

1. **Set capacity limits.** Set the limit values using the [update-fleet-capacity](https://docs.aws.amazon.com/cli/latest/reference/gamelift/update-fleet-capacity.html) command. For more information, see [Set Amazon GameLift Servers capacity limits](fleets-capacity-limits.md).

1. **Create a new policy.** Open a command-line window and use the [put-scaling-policy](https://docs.aws.amazon.com/cli/latest/reference/gamelift/put-scaling-policy.html) command with your policy's parameter settings. To update an existing policy, specify the policy's name and provide a complete version of the updated policy.

   ```
   --fleet-id <unique fleet identifier>
   --name "<unique policy name>"
   --policy-type <target- or rule-based policy>
   --metric-name <name of metric>
   --target-configuration <buffer size>
   ```

   Example:

   ```
   aws gamelift put-scaling-policy \
       --fleet-id "fleet-2222bbbb-33cc-44dd-55ee-6666ffff77aa" \
       --name "My_Target_Policy_1" \
       --policy-type "TargetBased" \
       --metric-name "PercentAvailableGameSessions" \
       --target-configuration "TargetValue=5"
   ```

------

# Auto scale with rule-based policies
Rule-based auto scaling

Rule-based scaling policies in Amazon GameLift Servers provide fine-grained control when auto scaling a fleet's capacity in response to player activity. For each policy, you can link scaling to one of several fleet metrics, identify a trigger point, and customize the responding scale-up or scale-down event. Rule-based policies are useful for supplementing [target-based scaling](fleets-autoscaling-target.md) to handle special circumstances. 

A rule-based policy states the following: "If a fleet metric meets or crosses a threshold value for a certain length of time, then change the fleet's capacity by a specified amount." This topic describes the syntax used to construct a policy statement and provides help with creating and managing your rule-based policies.

## Manage rule-based policies


Create, update, or delete rule-based policies using an AWS SDK or the AWS Command Line Interface (AWS CLI) with the [Service API for Amazon GameLift Servers](https://docs.aws.amazon.com/gameliftservers/latest/apireference/Welcome.html). You can view all active policies in the Amazon GameLift Servers console.

To temporarily stop all scaling policies for a fleet, use the AWS CLI command [stop-fleet-actions](https://docs.aws.amazon.com/cli/latest/reference/gamelift/stop-fleet-actions.html).

**To create or update a rule-based scaling policy (AWS CLI):**

1. **Set capacity limits.** Set either or both limit values using the [update-fleet-capacity](https://docs.aws.amazon.com/cli/latest/reference/gamelift/update-fleet-capacity.html) command. For more information, see [Set Amazon GameLift Servers capacity limits](fleets-capacity-limits.md).

1. **Create a new policy.** Open a command line window and use the [put-scaling-policy](https://docs.aws.amazon.com/cli/latest/reference/gamelift/put-scaling-policy.html) command with your policy's parameter settings. To update an existing policy, specify the policy's name and provide a complete version of the updated policy.

   ```
   --fleet-id <unique fleet identifier>
   --name "<unique policy name>"
   --policy-type <target- or rule-based policy>
   --metric-name <name of metric>
   --comparison-operator <comparison operator>
   --threshold <threshold integer value>
   --evaluation-periods <number of minutes>
   --scaling-adjustment-type <adjustment type>
   --scaling-adjustment <adjustment amount>
   ```

   Example:

   ```
   aws gamelift put-scaling-policy \
       --fleet-id fleet-2222bbbb-33cc-44dd-55ee-6666ffff77aa \
       --name "Scale up when AGS<50" \
       --policy-type RuleBased \
       --metric-name AvailableGameSessions \
       --comparison-operator LessThanThreshold \
       --threshold 50 \
       --evaluation-periods 10 \
       --scaling-adjustment-type ChangeInCapacity \
       --scaling-adjustment 1
   ```

**To delete a rule-based scaling policy using the AWS CLI:**
+ Open a command line window and use the [delete-scaling-policy](https://docs.aws.amazon.com/cli/latest/reference/gamelift/delete-scaling-policy.html) command with the fleet ID and policy name.

  Example:

  ```
  aws gamelift delete-scaling-policy \
      --fleet-id fleet-2222bbbb-33cc-44dd-55ee-6666ffff77aa \
      --name "Scale up when AGS<50"
  ```

## Syntax for auto scaling rules


To construct a rule-based scaling policy statement, specify six variables:

If *<metric name>* remains *<comparison operator>* *<threshold value>* for *<evaluation period>*, then change fleet capacity using *<adjustment type>* to/by *<adjustment value>*.

For example, this policy statement starts a scale-up event whenever a fleet's extra capacity is less than what's needed to handle 50 new game sessions:

If `AvailableGameSessions` remains at `less than 50` for `10 minutes`, then change fleet capacity using `ChangeInCapacity` by `1 instances`.

**Metric name**  
To start a scaling event, link an auto scaling policy to one of the following fleet-specific metrics. For complete metric descriptions, see [Amazon GameLift Servers metrics for fleets](monitoring-cloudwatch.md#gamelift-metrics-fleet).  
+ Activating game sessions
+ Active game sessions
+ Available game sessions
+ Percent available game sessions
+ Active instances
+ Available player sessions
+ Current player sessions
+ Idle instances
+ Percent idle instances
If the fleet is in a game session queue, you can use the following metrics:  
+ Queue depth – The number of pending game session requests this fleet is the best available hosting location for.
+ Wait time – Fleet-specific wait time. The length of time that the oldest pending game session request has been waiting to be fulfilled. A fleet's wait time is equal to the oldest current request's time in queue.

**Comparison operator**  
Tells Amazon GameLift Servers how to compare the metric data to the threshold value. Valid comparison operators include greater than (>), less than (<), greater than or equal (>=), and less than or equal (<=).

**Threshold value**  
When the specified metric value meets or crosses the threshold value, it starts a scaling event. This value is always a positive integer.

**Evaluation period**  
The metric must meet or cross the threshold value for the full length of the evaluation period before starting a scaling event. The evaluation period length is consecutive; if the metric retreats from the threshold, the evaluation period starts over again.

**Adjustment type and value**  
This set of variables works together to specify how Amazon GameLift Servers should adjust the fleet's capacity when a scaling event starts. Choose from three possible adjustment types:  
+ **Change in capacity** – Increase or decrease the current capacity by a specified number of instances. Set the adjustment value to the number of instances to add or remove from the fleet. Positive values add instances, while negative values remove instances. For example, a value of "-10" scales down the fleet by 10 instances, regardless of the fleet's total size.
+ **Percent change in capacity** – Increase or decrease the current capacity by a specified percentage. Set the adjustment value to the percentage that you want to increase or decrease the fleet capacity by. Positive values add instances, while negative values remove instances. For example, for a fleet with 50 instances, a percentage change of "20" adds 10 instances to the fleet.
+ **Exact capacity** – Increase or decrease the current capacity to a specific value. Set the adjustment value to the exact number of instances that you want to maintain in the fleet.

## Tips for rule-based auto scaling


The following suggestions can help you get the most out of auto scaling with rule-based policies.

### Use multiple policies


You can have multiple auto scaling policies for a fleet at the same time. The most common scenario is to have a target-based policy manage most scaling needs and use rule-based policies to handle edge cases. There are no limits on using multiple policies.

With multiple policies, each policy behaves independently. There is no way to control the sequence of scaling events. For example, if you have multiple policies driving scaling up, it's possible that player activity could start multiple scaling events simultaneously. Avoid policies that start each other. For example, you could create an infinite loop if you create scale-up and scale-down policies that set capacity beyond the threshold of each other.

### Set maximum and minimum capacity


Each fleet has a maximum and minimum capacity limit. This feature is important when using auto scaling. Auto scaling never sets capacity to a value outside of this range. By default, newly created fleets have a minimum of 0 and a maximum of 1. For your auto scaling policy to affect capacity as intended, increase the maximum value.

Fleet capacity is also constrained by limits on the fleet's instance type and by service quotas in your AWS account. You can't set a minimum and maximum outside these limits and account quotas.

### Track metrics after a change in capacity


After changing capacity in response to an auto scaling policy, Amazon GameLift Servers waits 10 minutes before responding to triggers from the same policy. This wait gives Amazon GameLift Servers time to add the new instances, launch the game servers, connect players, and start collecting data from the new instances. During this time, Amazon GameLift Servers evaluates the policy against the metric and tracks the policy's evaluation period, which restarts after a scaling event occurs. This means that a scaling policy could start another scaling event immediately after the wait time is over.

There is no wait time between scaling events that different auto scaling policies start.

# Manage Scaling an Amazon GameLift Servers Fleet To/From Zero
Manage Scaling a Fleet To/From Zero

Amazon GameLift Servers supports automatic scaling to and from zero instances based on game session activity. This managed capacity option allows your Fleet locations to scale-in to zero instances following a defined period of no game session activity and automatically scale-out when game sessions are requested.

Scaling to and from zero instances provides several advantages:
+ **Cost optimization** – Eliminate compute costs during periods of inactivity by running zero instances when there is no game session activity.
+ **Automatic reactive scale-out** – Fleets locations automatically scale-out to one instance when a game session is requested, eliminating the need for manual intervention.
+ **Simplified management** – No need to manually adjust Fleet capacity to/from zero based on anticipated player demand or development needs.

When you enable Scale To/From Zero on a fleet, Amazon GameLift Servers monitors game session activity and automatically adjusts Fleet capacity:
+ **Scale-in to zero** – After a configured period with no game sessions activity, Amazon GameLift Servers scales-in the Fleet location to zero instances.
+ **Scale-out from zero** – When a game session creation request is received, Amazon GameLift Servers scales-out the Fleet location to one instance, allowing auto scaling to resume.
+ **Continued scaling** – Following scale-out the fleet resumes using configured auto scaling policies to manage capacity.

## Scale-in behavior


Amazon GameLift Servers begins the scale-in process for a Fleet location after the configured inactivity period has elapsed with no game session activity. This is defined as a period where::
+ There are no active game sessions in the Fleet location.
+ No requests have been made to create new game sessions in the Fleet location.

During scale-in, Amazon GameLift Servers will set minimum and desired capacity for the Fleet location to zero, rapidly scaling-in for cost savings.

## Scale-out behavior


When a game session creation request is received while the Fleet location is at zero instances:
+ Amazon GameLift Servers immediately initiates scale-out of one instance.
+ Attempted placement of the game session may continue with other Fleets or Fleet locations, depending on configuration of Queues (if used).

**Note**  
Scale-out from zero takes time to provision and initialize instances. Players may experience longer wait times for the first game session after a period of inactivity. For this reason this feature is best paired with multi-location Fleets and/or Queues.

## Configuring Scale To/From Zero


Scaling To/From Zero is configured by updating an existing fleet.

------
#### [ Console ]

1. Open the [Amazon GameLift Servers console](https://console.aws.amazon.com/gamelift/).

1. In the navigation pane, choose **Hosting**, **Fleets**.

1. On the **Fleets** page, choose the name of an active fleet to open the fleet's detail page.

1. Under **Scaling**, select each location for which you want to configure scale to/from zero, and then choose **Edit**.

1. In the **Edit scaling capacity** dialog box, select "Automatic" for **Minimum capacity strategy**, set your preferred value in minutes for **Set minimum capacity to 0 after** and then choose **Confirm**. 

Amazon GameLift Servers will then scale-in the selected fleet locations to 0 instances once there has been no game session activity for the configured duration. Following this, when a request for a game session is made in this location, Amazon GameLift Servers will scale-out one instance as quickly as possible. This process will take a little time.

------
#### [ AWS CLI ]
+ **Configure scale to/from zero.** In a command line window, use the [update-fleet-capacity](https://docs.aws.amazon.com/cli/latest/reference/gamelift/update-fleet-capacity.html) command with the fleet ID, location and managed capacity configuration to configure scale to/from zero. 

  ```
  aws gamelift update-fleet-capacity \
                                  --fleet-id <fleet identifier> \
                                  --location <location name> \
                                  --managed-capacity-configuration ScaleInAfterInactivityMinutes=60,ZeroCapacityStrategy=SCALE_TO_AND_FROM_ZERO
  ```

  Example:

  ```
  aws gamelift update-fleet-capacity \
                                  --fleet-id fleet-2222bbbb-33cc-44dd-55ee-6666ffff77aa \
                                  --location us-west-2 \
                                  --desired-instances 5 \
                                  --max-size 10 \
                                  --managed-capacity-configuration ScaleInAfterInactivityMinutes=60,ZeroCapacityStrategy=SCALE_TO_AND_FROM_ZERO
  ```

If your request is successful, Amazon GameLift Servers returns the updated capacity configuration. Amazon GameLift Servers will then scale-in the selected fleet locations to 0 instances once there has been no game session activity for the configured duration. Following this, when a request for a game session is made in this location, Amazon GameLift Servers will scale-out one instance as quickly as possible. This process will take a little time. 

------

## Best practices


Consider the following recommendations when using Scale To/From Zero:
+ **Set appropriate inactivity periods** – Balance cost savings against the frequency of scale-in/scale-out cycles. Shorter wait time to scale to zero may maximize savings, but would result in more frequent cold starts.
+ **Use with predictable workloads** – Scale To/From Zero works best for games with clear periods of inactivity, such as development/test environments or games with distinct off-peak hours.
+ **Monitor CloudWatch metrics** – Track fleet scaling events and game session placement times to optimize your configuration.
+ **Combine with scaling policies** – Use Scale To/From Zero alongside target-based or rule-based auto scaling for comprehensive capacity management.

# Scale Amazon GameLift Servers container fleets
Scale container fleets

One of the most challenging tasks with game hosting is scaling capacity to meet player demand without wasting money on resources that you don't need. In a managed container fleet, you scale your fleet capacity by adding or removing fleet instances.

When you create a new fleet, Amazon GameLift Servers sets the fleet's desired capacity to one instance and deploys one instance in the fleet's home region. For a multi-location fleet, Amazon GameLift Servers deploys one instance to the home region and to each remote location. After the fleet status reaches `ACTIVE`, you can raise the desired capacity to raise or lower the desired capacity to scale down. 

You can use Amazon GameLift Servers scaling features to change capacity manually or set up automatic scaling based on player demand: 
+ Set up automatic scaling with target tracking. See [Target-based auto scaling](fleets-autoscaling-target.md).
+ Manually change the capacity of your fleet. See [Manually set capacity for an Amazon GameLift Servers fleet](fleets-updating-capacity.md).

When scaling a container fleet, consider how adding or removing instances impacts the fleet's capacity to host game sessions and players. 
+ Game sessions per instance
  + Each game server process running on an instance represents the capacity to host one game session.
  + Use this formula to calculate the number of game sessions that run concurrently on a container fleet instance: 

    ```
    [Game sessions per instance] = [# of game server processes per game server container] * [# of game server container groups per instance]
    ```

    If your container architecture runs one game server process concurrently in the game server container, then game sessions per instance equal the number of game server container groups per instance.
    + For game server container groups per instance, call [DescribeContainerFleet](https://docs.aws.amazon.com/gameliftservers/latest/apireference/API_DescribeContainerFleet.html) to get the `GameServerContainerGroupsPerInstance` or `MaximumGameServerContainerGroupsPerInstance` value.
    + The number of game server container groups that fit on an instance depends on how much memory is available after Amazon GameLift Servers reserves a portion for the operating system and supporting services. For details on how available memory is calculated and a reference table of common instance types, see [Understand container fleet memory allocation](containers-design-fleet.md#containers-design-fleet-memory-allocation).
+ Players per instance
  + You decide the number of player slots to allow in each game session. Depending on how your hosting solution handles game session placement, you might define players per game session in your matchmaking configuration or in your calls to start a game session placement. 
  + Use this formula to calculate the number of players that can play your game concurrently on a container fleet instance:

    ```
    [Players per instance] = [# of game sessions per instance] * [# of player slots per game session]
    ```

To get the current total capacity of a container fleet, call [DescribeFleetCapacity](https://docs.aws.amazon.com/gameliftservers/latest/apireference/API_DescribeFleetCapacity.html) or [DescribeFleetLocation Capacity](https://docs.aws.amazon.com/gameliftservers/latest/apireference/API_DescribeFleetLocationCapacity.html) to get the number of game server container groups in the fleet. Active groups are those that are currently hosting game sessions. Idle groups are ready to host a new game session. Multiply these values by the number of server processes per game server container group.