Fleet Service Tasks #

Through the Fleet service configuration options and the Fleet Plugin, Pragma Engine supports configuring capacity limits, scaling down servers to preserve resources, and maintaining a buffer of available capacity to keep servers ready to host game instances. This page describes common Fleet service operations.

To manage your game server fleet outside of Pragma (such as when using a third-party host’s capabilities), see Bypass the Pragma Fleet service.

General configuration

Server pools

Game instances

Store Pragma-provided HTTP client in your plugin #

When the platform starts, the Fleet service calls the Fleet Plugin init method, which provides an HTTP client that you can use for communication with external resources for capacity. Implement the init function to store the passed in TimedHttpClient value on your plugin.

fun init(
  client: TimedHttpClient
)  
Consider inheriting DefaultFleetPlugin for an implementation of this.

Start capacity polling #

All game servers must regularly report their available capacity to the Fleet service. To begin this process, call the MatchApi.StartReportCapacityPolling SDK method as soon as the game server is spun up so that the game server can report its capacity to the Fleet service as soon as possible.

The StartReportCapacityPolling method accepts the following parameters:

  • ServerId - ID for the server that should start reporting its capacity. This value will be provided by the Fleet Plugin add function, and should be passed to the game server provider as it spins up the server. If you provide an unrecognized server ID, Pragma will start tracking the server and log an unrecognized server message.
  • ServerPoolId - Server Pool ID for the server that should start reporting its capacity. This value will be provided by the Fleet Plugin add function, and should be passed to the game server provider as it spins up the server.
  • Timeout - Defines how long to wait for the first game allocation to the game server. If you do not want to use the timeout, provide a value of 0 for the timeout parameter.
  • MaxGameInstanceCount - Number of game instances that can run on this server. Default is 1.

You can specify the expected poll frequency using serverHeartbeatPeriodMillis in the ServerPoolManagementPolicyConfig configuration block.

Consider what timeout value is appropriate for your environment in case the server fails to start.
Server->MatchApi()->StartReportCapacityPolling(
  FString ServerId,
  FString ServerPoolId, 
  float Timeout, 
  int32 MaxGameInstanceCount = 1
);
Server.MatchApi.StartReportCapacityPolling(
  string serverId, 
  string serverPoolId,
  float timeout, 
  int maxGameInstanceCount = 1
);

When a game server reports its available capacity to the Fleet service, the Fleet service reviews the allocation request queue for allocation requests that contain game instances assigned to the server pool the reporting game server belongs to. Depending on the reported available capacity, the Fleet service will send the game server a list of game instance IDs for the server to host.

At this point, the game server will receive the OnGameStart event with information about the game instances it is hosting. See Game Instance Tasks for more information on sending game instance data to game servers.

If an error occurs while attempting to start a game instance, you will receive an OnGameStartFailed event and the game server will not continue reporting capacity or receiving new game instances until StartReportCapacityPolling is called again.

Related events:

Configure server pool management policies #

Using the Fleet service section of your YAML configuration file, you can define how much capacity the service should maintain. Additionally, you can configure how many game instances a server can run, how long your game servers have to allocate a game, how often they should report their capacity to the Fleet service, and how long the service should wait for a report to arrive before considering a game server timed out.

You set the server pool management policies values in the configuration file ServerPoolManagementPolicyConfig block. For a description of each field, see the Fleet Service Components topic’s Server Pool Management Policy Configuration table.

For example, the following configuration file defines three server pools, each with different default values. The 3v3_MODE is intended for game servers hosting games with this mode. The LOW_POPULATION pool is intended for game servers that host games infrequently, for example, a tutorial game mode. The NORTH_AMERICA_REGION pool is intended for servers in a specific region, which allows for customization based on the geographical distribution of your players.

game:
  serviceConfigs:
    FleetServiceConfig:
      serverPoolManagementPolicies:
        1:
          id: "3v3_MODE"
          gameCapacityPerServer: 1
          capacityFloor: 200
          capacityCeiling: 10000
          capacityBuffer: 40
          serverMaxStartDurationMillis: 300000
          serverHeartbeatPeriodMillis: 1000
          serverHeartbeatExpiryFactor: 5.0
          gameCapacityResolvedTimeoutMillis: 60000
        2:
          id: "LOW_POPULATION"
          gameCapacityPerServer: 5
          capacityFloor: 0
          capacityCeiling: 25
          capacityBuffer: 10
          serverMaxStartDurationMillis: 300000
          serverHeartbeatPeriodMillis: 1000
          serverHeartbeatExpiryFactor: 5.0
          gameCapacityResolvedTimeoutMillis: 60000
        3:
          id: "NORTH_AMERICA_REGION"
          gameCapacityPerServer: 2 
          capacityFloor: 75 
          capacityCeiling: 400 
          capacityBuffer: 25
          serverMaxStartDurationMillis: 300000
          serverHeartbeatPeriodMillis: 1000
          serverHeartbeatExpiryFactor: 5.0
          gameCapacityResolvedTimeoutMillis: 60000

If setting gameCapacityPerServer to a value other than 1, see Run multiple game instances per server.

Consider what capacityFloor and capacityCeiling values are appropriate for your environment. Setting these values too low or too high can lead to undesirable game instance load.

Map server pools to server pool management policies #

To associate one or more server pool management policies with a server pool, set the server pool’s managementPolicyId value to the desired server pool management policy ID. In this example, we’ve defined the mapping in the plugin configuration section of the configuration file. We’ll fill in the additional custom data in the next step.

//Server Pools
{
    "serverPoolId": "pool1"
    "managementPolicyId": "3v3_MODE"
}
{
    "serverPoolId": "pool2"
    "managementPolicyId": "LOW_POPULATION"
}

{
    "serverPoolId": "pool3"
    "managementPolicyId": "NORTH_AMERICA_REGION"
}

Define custom server pool data #

You can define custom data to send to your game server hosting platform to help determine what server to spin up when capacity is added. This information is defined in the ExtServerPool payload. The ExtServerPool payload is populated by the Fleet Plugin selectServerPool method and returned on the ServerPool object, which, in turn, is used when adding capacity.

message ExtServerPool{
	String region;
	Int profileId;
}

In the following example, we put the custom server pool data in the plugin configuration section of the configuration file:

//Server Pools
{
    "serverPoolId": "pool1"
    "managementPolicyId": "3v3_MODE"
    "regionIds": ["us", "eu", "br"]
    "profileId": 1
    "supportedVersion": "0.48.3"
    "supportedModes": ["3v3_Ranked", "3v3_Casual"]
},
{
    "serverPoolId": "pool2"
    "managementPolicyId": "LOW_POPULATION"
    "regionIds": ["us", "eu", "br"]
    "profileId": 2
    "supportedVersion": "0.48.3"
    "supportedModes": ["tutorial"]
},
{
    "serverPoolId": "pool3"
    "managementPolicyId": "NORTH_AMERICA_REGION"
    "regionIds": ["us"]
    "profileId": 3
    "supportedVersion": "0.48.3"
    "supportedModes": ["3v3_Ranked", "3v3_Casual"]
}

Build server pool selection logic #

The Fleet Plugin’s selectServerPool method is where you define logic that determines what server pool should be used when allocating game servers for the given game allocation request.

You can use the game server version, game server zone, or custom-defined data (generated by the Game Server Provider Plugin’s handleBackendCreateByMatchmakingRequest method) to inform this logic.

fun selectServerPool(
  gameServerVersion: GameServerVersion,
  gameServerZone: GameServerZone,
  ext: ExtAllocateGameServer
): ServerPool

The method returns a new or existing ServerPool object to the allocation request. The ServerPool object includes the server pool ID, the management policy ID, and the ExtServerPool payload, all of which can be used when allocating game servers.

Assign server pool for unrecognized game servers #

The Fleet service executes the Fleet Plugin getServerPoolById method when Pragma does not recognize the game server reporting its capacity. This situation can occur when the Pragma platform restarts while game servers are still running or if you are developing on a local game server not allocated via the Fleet service. The getServerPoolById method will associate the provided server pool ID with a new or existing server pool, according to the logic you define in the method.

fun getServerPoolById(
  serverPoolId: String
): ServerPool

Allocate additional game servers #

If the Fleet service determines that the current available capacity cannot fulfill a request to create a game instance in a given server pool, the Fleet Plugin’s add method is called.

interface FleetPlugin {
  suspend fun add(
    serverPool: ServerPool,
    allocations: List<GameServerAllocation>
  )
}

The add method accepts a specific ServerPool and a list of GameServerAllocation objects, which map game servers IDs with the PartnerGameAuthTokens they should use when authenticating to Pragma. You can use the add method to provide the game server with these partner tokens, as shown in the following example:

suspend fun add(serverPool: ServerPool, allocations: List<GameServerAllocation>) {
  for (allocation in allocations) {
    ...
    val dispatchRequest = mapOf(
      META to mapOf(
        ...
        PARTNER_GAME_AUTH_TOKEN to allocation.pragmaTokens.gameToken,
        PARTNER_SOCIAL_AUTH_TOKEN to allocation.pragmaTokens.socialToken,
      )
    )
	 ...
  }
}
Each game server requires a set of partner tokens, regardless of how many game instances that game server can run at once.

Run multiple concurrent game instances on a single server #

To host multiple game instances concurrently on a single server, set the gameCapacityPerServer value in the server pool management policy for that server. When the server starts reporting capacity, pass the same value as the MaxGameInstanceCount parameter in the MatchApi.startReportCapacityPolling method.

A game server can reconfigure its max game instance count after capacity polling has started by calling MatchApi.UpdateMaxGameInstanceCount with a new maxGameInstanceCount value. The new value will be reported indefinitely.

Run subsequent game instances on a single server #

When a game instance ends, if the game server expects to receive subsequent game instances, the host game server should tell the engine that its used capacity has decreased. To do so, the game server should call MatchApi.ReportFreedCapacity when a game instance ends. The next time the game server reports its capacity, the freed capacity is reflected.