Capacity limiting

Note:

  • The deployment service is in beta and may have breaking changes before stabilizing. For more information on maturity stages see Maturity stages.

  • If you use the GDK for Unreal version 0.10 or later, the features and procedures on this page are not compatible with the Standard Runtime variant. If you want to use these features and procedures, you must use the Compatibility Mode Runtime variant.

Introduction

You can configure worker connection rate and capacity limit at launch, or while a deployment is running using the Deployment APIs. This functionality requires that clients connect using the alpha version of the Worker.Locator class (C#/C++).

This scenario demonstrates how to configure capacity limits for a running deployment. (It doesn't cover rate limit configuration, as this is very similar.) If you're looking for how to configure capacity and rate limits on launch, refer to the documentation on worker connection limits.

Find out how to download the Platform SDK from the setup guide.

You can find the full code example for this scenario on GitHub.

Example: applying a dynamic capacity limit to a running cloud deployment

1. Instantiate clients

Instantiate clients of the DeploymentServiceClient types.

Use the Create method of the DeploymentServiceClient.

private readonly DeploymentServiceClient _deploymentServiceClient = DeploymentServiceClient.Create();

By default, this uses your refresh token saved locally by the SpatialOS CLI. You can find your token at:

  • Windows: C:\Users\<username>\AppData\Local\.improbable\oauth2\oauth2_refresh_token\
  • Mac: ~/.improbable/oauth2/oauth2_refresh_token

If you want to provide a refresh token, you can instantiate a PlatformRefreshTokenCredential object and supply it to create:

var credentialsWithProvidedToken = new PlatformRefreshTokenCredential("my_refresh_token");
private readonly DeploymentServiceClient _deploymentServiceClient = DeploymentServiceClient.Create(credentials: credentialsWithProvidedToken);

Since this use case is intended as part of your deployment management server, we recommend using the refresh token of a service account. To create a service account, see Service account maintenance. You need to create one with at least read and write permissions on your project. See Permissions for details.

2. Get the deployment to apply the capacity limit to

You can dynamically change rate and capacity limits only for running deployments. Get the running deployment:

var suitableDeployment = _deploymentServiceClient.GetRunningDeploymentByName(new GetRunningDeploymentByNameRequest
{
    ProjectName = ProjectName,
    DeploymentName = DeploymentName
});

3. Set the capacity limit for the worker type "my_worker_type" to 2

You apply capacity limits per worker type, so you must specify a valid worker type when setting the capacity limit.

var setWorkerCapacitiesRequest = new SetDeploymentWorkerCapacitiesRequest
{
    DeploymentId = suitableDeployment.Deployment.Id,
};
setWorkerCapacitiesRequest.WorkerConnectionCapacities.Add(new WorkerCapacity
{
    WorkerType = "my_worker_type",
    MaxCapacity = 2
});
_deploymentServiceClient.SetDeploymentWorkerCapacities(setWorkerCapacitiesRequest);

4. Clear all existing capacity limits for a deployment

To clear all capacity limits, pass in an empty array for the capacity field.

var setWorkerCapacitiesRequest = new SetDeploymentWorkerCapacitiesRequest
{
    DeploymentId = suitableDeployment.Deployment.Id,
};
_deploymentServiceClient.SetDeploymentWorkerCapacities(setWorkerCapacitiesRequest);

Updated 11 months ago


Capacity limiting


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.