Empower your gaming apps with Amazon DynamoDB

Source: Internet
Author: User
Tags uuid ruby on rails dynamodb amazon dynamodb aws management console

Amazon Dynamodb is rapidly becoming the world's strongest game database. "Fruit Ninja" (developed by Halfbrick Studio), "Battle Camp" (developed by Pennypop) and other games take full advantage of Amazondynamodb's one-click Extensibility features to support the rapid development of the game, to provide services to millions of players worldwide. Amazondynamodb is also appreciated by a number of developers, including supervillain Studios, which include "Tower Cannon Wars" and "Tron: Evolution".

in today's article, you will learn how Amazon Dynamodb can help you quickly build a reliable and scalable database layer for your mobile games. We'll step through the design examples and learn how to provide elastic resources to the game at the cost of less than a cup of coffee per day. We will also simulate a fast-growing customer to see How AMAZONDYNAMODB can scale player support to millions of in time and cost efficiency.

The importance of the database tier

One of the key factors in designing architectures for large-scale applications is the database tier. This is especially important for games, after all, for write-intensive applications. Game data is constantly updated as players collect props, defeat enemies, earn coins, upgrade characters, and accomplish achievements. Each event must be written to the database layer to ensure that the content is not lost. As you can imagine, the player will become extremely grumpy once the progress is broken.

Games and Web App developers typically use The open source relational database, such as MySQL, serves as its own database layer, because such schemes are more familiar to people. Unfortunately, the MySQL-represented relational technology program has taken more of a high-intensity read workload at the beginning of development, and this mechanism is not well suited for games, social media applications, and image sharing sites. In view of this, the NoSQL solution came into being, leveraging strong write data throughput and scale-out capabilities to replace the traditional relational database's advantage in the area of query flexibility.

Three reasons Amazon Dynamodb is suitable for game developer needs

? Amazon is a business task.

It's tiring to develop the game itself, right? Amazon Dynamodb is a managed service that includes full operational support and multi-datacenter high availability. There is no need to worry about software installation, hardware failure handling, or performance tuning.

? By simply invoking a single API, you can dynamically scale the AMAZONDYNAMODB.

each one AMAZONDYNAMODB database tables are closely related to data throughput capabilities. You can set write operations per second to 1000 times, and Amazon Dynamodb handles all background database tuning. Depending on the user's needs, you can update the capacity, and Amazondynamodb will complete the resource reallocation as required. This resilience is great for game developers: When the game is launched, you may need to increase the player support scale from thousands of to millions of in a short period of time. Just as important, you can quickly reduce the size of your resources-a challenge for MySQL databases.

? performance will remain stable regardless of the size of the game player.

Amazon Dynamodb can maintain predictable, low-latency performance at any scale level. If everyone's game is sensitive to latency and needs to face millions of of players, this feature will become critical. With Amazondynamodb, you no longer have to waste any effort on performance tuning.


in the save game data in Amazon Dynamodb

we might as well imagine that you want to create a role-playing game. Game design follows a common mechanism: fight monsters, Collect loot, and perform character upgrades. In this case, you obviously need to save the user's current progress, we should create a key -value pair profile for each player, including the existing props, the role level and the number of coins earned. The data structure for everyone might look like this:

{

player_id:3612458,

Name: "Gunndor",

Class: "Thief",

gold:47950,

Level:24,

hp_max:320,

hp_current:292,

mp_max:180,

mp_current:180,

xp:582180,

num_plays:538,

Last_play_date: "2014-06-30t16:27:39.921z"

}

in this example, The player_id should be a unique value. Mapping it to a relational database such as MySQL is simple: Create a column for each key. This is certainly possible, but parsing and retrieving each column in the structure will put a heavy burden on the database, and the primary key (i.e. player_id) receives the query request almost every moment. Obviously, it is not possible to use the player's record point location or experience to record queries.

OK, here's a look at the map to what happens to Amazon Dynamodb. In Amazondynamodb, we only need to define the columns that need to be retrieved. In this case, we will create a single hash key as the primary key, and use it to implement a record query using the uniqueness of the player_id. We will define a set of tables called "Player_profiles" and set the hash key for "player_id". Here's an example of Python language writing:

Player_profiles =table.create (' Player_profiles ', schema=[

HashKey (' player_id ', data_type=string)

], throughput={

' Read ': 5,

' Write ': 5,

},

we have created a set containing A table of 5 read capacity units and 5 write capacity units, which are included in the AWS free Usage tier. You can also use the AWS Management Console to create this set of tables. If you do not know how to do this, please click here to view guidance information.

After the table has been created, our configuration file will look like this:

Player_profiles.put_item (data={

' player_id ': ' 3612458 ',

' Name ': ' Gunndor ',

' Class ': ' Thief ',

...

})

Profile =player_profiles.get_item (player_id= ' 3612458 ')

It's just Python Environment example, you can also use any AWSSDK to put/get the keys in Amazon Dynamodb.


Primary key value

A relational database uses an automatically incrementing integer, which is typically used as a primary key. In a large-scale scenario, the auto-incrementing primary key tends to be a performance bottleneck, so nosql like Amazon dynamodb does not save it. So how do we generate a unique player_id value? We use UUID, because the contents of the UUID are different, so different clients will always generate independent corresponding values. The UUID can generate a fairly long string for us, such as A8098C1A-F86E-11DA-BD1A-00112444BE1E. The UUID matches Amazon Dynamodb very well, because it helps ensure that the primary key is randomly distributed and accessed, so Amazon Dynamodb always has good performance.

Build The uuid is very simple:

player_id = UUID.UUID1 ()

Player_profiles.put_item (data={

' player_id ': player_id,

' Name ': ' Gunndor ',

' Class ': ' Thief ',

...

})

Atomic Increment

except put and Get,amazon Dynamodb also support atomic increments. This mechanism is useful in the update process after a change in value, because there is no conflict in multiple requests from the application-it is this kind of situation that raises most of the progress loss issues in online games. If the player picks up 100 gold coins, you can directly ask Amazon Dynamodb to automatically add the 100 gold increment atomically, without having to go through the process of acquiring records, adding coins, and returning them to Amazon Dynamodb.

Choose the right capacity level

Amazon Dynamodb allows you to specify the amount of data throughput capacity you need. But what if we don't know what this level is? When you start the game development, first create your own first set of tables (for example, 5 write capacity units and 10 read capacity units). As traffic grows, we can use Cloudwatch graphics to monitor usage and make adjustments in the Amazondynamodb console.

Dynamicdynamodb is another practical tool, a set of open source libraries designed to help us automatically scale table capacity. One of our clients Tadaa uses DYNAMICDYNAMODB to adjust resources in a timely manner when traffic levels fall, thereby controlling cost expenditures.




Can we really support thousands of of players with the cost of a cup of coffee a day?

Oh, yes! We use this example of saving games to estimate costs. Assuming that the game has a monthly average of 100,000 players , most of the players do not log in at the same time, so we roughly estimate that one-tenth of them will be online simultaneously. Also, we assume that the 10,000 players save the game every minute, and that each player's progress data is less than 1KB. Finally, we assume that each player needs to read the game state from the database every minute during the game. Since there are 60 seconds in a minute, our Amazon Dynamodb table must be able to support 167 write and read operations (10000 divided by 60) per second. Most businesses retain a portion of the buffer capacity, so we raise the write-to-read acceptance to 200 times per second, while the total storage space is set to 50GB.

according to the current The resource- charging standard for the Us-east-1 region, which costs only $4.16 a day! In other words, the price of a cup of coffee a day can be fully supported by 100,000 players (of course, this is the relatively expensive type of espresso that is used in fancy Italian enrichment). As a start, you can also use Awsfree usage tier with Amazon Dyamodb for free.


Customer Example: Battle Camp


as a model by Pennypop, a popular mobile game developed by the company, "Battle Camp" uses Amazondynamodb as its preferred data storage mechanism. The battle camp has downloaded more than 10 million downloads so far, and has topped hundreds of downloads in app stores in more than 40 countries. After comparing several other sets of NoSQL options, Pennypop's technicians chose Amazondynamodb because they wanted to focus on application programming rather than server maintenance and expansion.

The developer of the Battle Camp first downloaded Fake_dynamo, an open source client, for local development. (Amazon also publishes and supports a local dynamo client.) They build their own object- relational mapping (ORM) to enable them to collaborate with Ruby on rails. This ORM scheme greatly simplifies the functionality of DYNAMODB, as developers only need to use key-value retrievals in the application layer. The ORM saves the value as a JSON object-the so-called JSON object, which is a compressed Base64 string. This mechanism allows them to compress the JSON object to less than One-tenth of the original volume. Most Web application database query operations can be reduced by capturing and saving simplification, and the entire migration effort is completed in a few weeks-during which time they build their own custom ORM.

shows how the Battle Camp game will Amazon Dynamodb is integrated into its own architecture.



What's the result? Time and cost are greatly reduced. As Pennypop co-founder Charlesju explains:

" the cost savings of Amazon Dynamodb are achieved on the one hand by efficiency and ease of use, as well as significant reductions in maintenance costs. Building, maintaining, and splitting large, data-centric real-time projects has been difficult, and the creation and maintenance of projects has always required a large number of technical staff involved. Now, however, we are still only two-bit server engineers while providing a satisfying gaming experience for millions of of players. Our size is more streamlined than any known MMORPG manufacturer. ”

They also found that Dynamodb also works well in other larger scenarios and can even The MapReduce analysis protocol is successfully docked thanks to its excellent scalability flexibility. They can completely build an internal MapReduce protocol to perform data analysis in parallel.


Last Item: Analysis

In addition to real-time gaming services, Amazondynamodb also integrates a range of other AWS Services, including Amazonelastic MapReduce (EMR) and Amazonredshift. Amazon EMR and Amazonredshift are able to load analytics data directly from Amazon Dynamodb, simplifying the way analytics workflows are built. If you would like to learn more about the game content analysis on AWS, please comment in the comments section and we will focus on this topic in future articles.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.