DevOps Practices in the Gaming Industry — Game server infrastructure: AWS Gamelift
In my previous article, I mentioned that the main cloud providers offer a variety of services and infrastructure oriented to the game development industry, especially for servers.
In this article, I would like to introduce an Amazon Web Services offer called Amazon Gamelift, its companion service Gamelift FleetIQ, and the characteristics of both of them.
Prerequisites
To follow this article, you should have a basic understanding of the cloud engineering mindset and its differences from traditional on-premise infrastructure, specifically Amazon Web Services. Having had some hands-on experience with this provider is highly recommended.
What is Gamelift?
AWS GameLift is a powerful service that enables game developers to deploy, operate, and scale multiplayer games with ease. It’s a great option whether you’re running small-scale sessions or massive multiplayer experiences, as GameLift provides the infrastructure and tools you need. In this article, we’ll explore the main features GameLift offers, alongside the main differences with the other gaming stack service called Gamelift FleetIQ.
Introducing FleetIQ — Balancing, Optimization, and Management of your Game Sessions
FleetIQ is an intelligent balancing feature within AWS GameLift that enhances the default GameLift service by optimizing the distribution of game sessions across available server instances.
While plain GameLift uses a rule-based system for server distribution, FleetIQ leverages dynamic Spot Instances and advanced algorithms to efficiently manage server capacity based on real-time demand. With this feature, game developers can achieve significantly lower costs, as spot instances offer lower prices compared to on-demand instances. Additionally, FleetIQ automatically places game sessions on instances with low player demand, maximizing server utilization and providing a seamless gaming experience for players.
What if the spot instance is terminated in the middle of a process?
Games hosted on Spot Instances are subject to random interruption, which will cause the players’ game session to end, leading to a poor experience. This would appear to make Spot Instances unsuitable for hosting games. GameLift FleetIQ uses a predictive heuristic to assess the viability of Spot Instances for game hosting.
GameLift FleetIQ can use a variety of instance types and balance the number of instances and their types to optimize the viability of the fleet.
GameLift FleetIQ manages instances of in-game server groups. These groups are an abstraction that contains and manages instances for hosting games in a group. At the same time, it adds game abstractions and methods on top of the EC2 AutoScaling group in your AWS account. The following image shows a heterogeneous AutoScaling group that can be used with Gamelift:
Note: For reference, GameLift FleetIQ will be compared with Amazon GameLift. One important distinction is that GameLift FleetIQ uses an entirely different workflow from Amazon GameLift.
Comparing Amazon GameLift with GameLift FleetIQ
Think of Amazon GameLift as a high-end camera. It has sophisticated automatic controls, and it makes numerous decisions automatically to produce good results for common situations.
Using GameLift FleetIQ is like putting the camera into manual mode, as it is represented in the following image. It turns off the automation but gives you control. There is a direct trade-off between automation and control.
Unlike other AWS services, GameLift FleetIQ is primarily controlled by the command line and APIs rather than the AWS Console.
Game server group elements and structure
The game server group is a complex object. As we said before, it’s an abstraction that builds upon an EC2 Auto Scaling group. The game server group implements game-specific objects, such as game servers, and methods for managing instances used for game server hosting.
The elements that comprise a game server group are as follows:
- IAM Role: As with any other service, it must be established to provide GameLift FleetIQ with the authority to create and modify infrastructure in your AWS account.
- Auto Scaling group: Not different from any other one, but mandatory for this service.
- Auto Scaling group configuration and fleet management: The number of EC2 instances in the group is controlled by Auto Scaling group configuration values, such as the minimum and maximum number of instances that should be in the group.
- Instance type list: GameLift FleetIQ constructs Auto Scaling groups with a list of Instance Types. The list must contain at least two instance types and can support up to 20 instance types.
- Launch template: GameLift FleetIQ starts the Auto Scaling group using a launch template.
The launch template has several features that the launch configuration does not. The launch template is a versioned document, making it easy to track changes and roll back to a previous version if necessary. The launch template also contains configuration information for using Spot Instances. By default, launch templates used with GameLift FleetIQ specify using Spot Instances for lower costs. - Amazon Machine Image (AMI): Any AWS AMI compatible with Gamelift FleetIQ that can be built to contain your game server software.
- Game servers: When an instance is launched by the Auto Scaling group, your code determines when a game server starts. The game server will make calls to GameLift FleetIQ, such as
RegisterGameServer()
andUpdateGameServer()
. These actions complete the control loop, giving GameLift FleetIQ knowledge of game servers and not just instances.
Next, you can see how every point mentioned before glues together to form a game server group:
What is the difference between Game Server Groups and Auto Scaling Groups?
Regular AutoScaling groups and Game Server Groups aren’t the same. In the following table, we can see the differences between them:
The AWS SDK and Integration
The first preparatory step in the creation of a game server group workflow is to install the AWS SDK in your development environment. Then you need to integrate the game server APIs into your game server software and game backend software. Your game server software is required to make specific GameLift FleetIQ API calls so that GameLift FleetIQ can manage the usage and capacity of all the game servers in the group. To place these calls, you will need to incorporate the AWS SDK into your game server software.
The process of deciding where the API calls should be made in your game is called GameLift FleetIQ integration. Example of the flows and architecture of an AWS SDK API call:
Gamelift FleetIQ is supported in the AWS SDK for the following languages:
- C++
- Java
- .Net
- Go
- Python
- Ruby
- JavaScript / Node.js
Using Spot Instances with games
Games are generally stateful and commonly low-latency. Migrating multiple game server workloads to a new instance during the two-minute grace period is usually not possible. Games hosted on Spot Instances are subject to random interruption, which will cause the players’ game session to end, leading to a poor experience. This would appear to make Spot Instances unsuitable for hosting games. How does Gamelift FleetIQ solve this?
As we can see in the previous image, GameLift FleetIQ implements a game-server-specific control layer on top of an EC2 Auto Scaling group. The logic modifies the instance type list used by the Auto Scaling group to manage instances.
When you create a game server group, you specify the instance type list. GameLift FleetIQ preserves the game server group source version of the instance type list and introduces changes to the Auto Scaling group copy of the instance type list. This allows GameLift FleetIQ to remove instances from the Auto Scaling group instance type list when they are nonviable and reinsert them when they become viable again.
GameLift FleetIQ drains and terminates instances of nonviable instance types and prevents new instances of those types from being provisioned by the Auto Scaling group by removing the instance type from the Auto Scaling group instance type list while it adds viable instance types to ensure that the Auto Scaling group instances are balanced across all viable instance types on the desired list.
Latest Gamelift features worth exploring
Of the most critical features, the following are some of the newest and really useful features that these technology stacks provide:
- Matchmaking with Amazon GameLift FlexMatch: It allows you to match players for your game on rules you define (player skill, latency, resources obtained, or any custom mix of your choosing). It has a simple but powerful rules language, and it lets you balance the player assignment based on metrics such as latency and server cost, among many others.
- Amazon Gamelift Anywhere: simplifies game server deployment and management across various environments. You can deploy dedicated game servers in the cloud, on-premises, or via hybrid setups using a single management solution. With Local Iteration, your computer becomes a registered hardware option, mimicking an Amazon EC2 fully managed server, allowing you to compile, deploy, and test game sessions directly on your machine. Unified Session Management enables you to create an “Anywhere Fleet” by registering different compute resources, seamlessly combining on-premises and Amazon EC2 hardware. This eliminates the need for separate server management software for cloud and on-premises workloads, streamlining your game server operations.
- Real-time game servers: It simplifies game server development with minimal backend requirements, making them ideal for mobile, turn-based, and messaging games. They come equipped with a built-in network stack supporting TCP and UDP networking. Customizing server behavior on the fly is effortless, allowing for real-time script adjustments and scheduled server logic execution. These servers seamlessly integrate with Amazon GameLift, enabling scalable operations with benefits such as reduced lag, improved stability, and minimized cheating. As a huge plus, their compact size allows for cost-effective hosting of multiple games on a single server instance, all while being free to use, with no extra charges beyond GameLift’s current pricing.
Using GameLift FleetIQ with Containers
You can have the option to work with and without containers, but these two approaches need to be thought of a bit differently. Here are the main highlights of each approach.
Game Server Relationships without Containers
With GameLift FleetIQ, you can establish game server groups to oversee EC2 Auto Scaling groups that include EC2 instances within your AWS account. The interpretation of a game server can vary depending on the specific context of your game design, emphasizing the importance of defining what a game server signifies within your design framework.
- Example 1 shows the relationship when a game server has a one-to-one relationship with an executable process. (One game server represents one process).
- Example 2 shows a game server with a one-to-one relationship to a game session. (One game server represents one game session).
- Example 3 shows a game server with a one-to-one relationship with a player session. (One game server represents one player session).
Thinking about game servers in this way will help you understand the way GameLift FleetIQ game servers are used with container technologies such as Kubernetes.
Game Server Relationships with Containers
In the case of Kubernetes, the game server represents one game.
Draining game servers and deregistering them is a crucial step in the process of rebalancing instance types, a requirement for managing GameLift FleetIQ Spot Instances effectively. In this context, containers introduce complexities, as having multiple game servers within a container necessitates draining the container of game servers before it can be deleted.
Since neither kubectl drain
nor GameLift FleetIQ’s draining feature currently offers direct support for draining game servers from containers, it becomes imperative to verify that game server draining and instance rebalancing are functioning smoothly in the presence of this added layer of container abstraction.
An example approach to using Kubernetes with GameLift FleetIQ
Upon instance initialization, launch as many containers or pods as comfortably accommodate the game server instance. Each of these containers or pods can host a single game server. Following the conclusion of a game, perform the process of deregistering and subsequently re-registering the server within the container. This approach ensures a mix of active game-running pods and available pods. In the event of accidental pod termination, Kubernetes will automatically restart them. The scaling operations, in this scenario, are efficiently managed by GameLift FleetIQ.
Conclusion
For DevOps engineers and developers familiar with Amazon Web Services, their offer for the gaming industry: Amazon GameLift and GameLift FleetIQ are invaluable assets. These services simplify multiplayer game deployment and management, offering fine-grained control over resources. GameLift optimizes game server distribution, reducing costs and enhancing player experiences. FleetIQ intelligently handles spot instances, ensuring minimal to no disruptions. These tools integrate seamlessly with existing games, granting total resource control and straightforward integration with AWS core services. Moreover, the latest GameLift features like FlexMatch, GameLift Anywhere, and Realtime Game Servers offer efficient matchmaking, versatile deployment options, and compact game hosting.