The author | source solution (flow) | alibaba cloud native public number

Introduction: This article will analyze a specific scenario, in order to hope that the relevant game development students resonate, but also hope to bring some inspiration to the non-game industry students.

One, foreword

1. Cloud focus for game customers

The games industry is a creative and competitive market, known as the Ninth Art. Game client Shangyun mainly focuses on the following four aspects:

  • Rapid iteration, global deployment

Rapid iteration is a common requirement of the game industry, including development efficiency, operation efficiency, architecture decoupling; At the same time, the game may also go to sea, so it may need to deploy overseas or globally.

  • High concurrency and flexibility

When each game is launched, it will go through the stages of new service opening and new operation. The game itself also has daily peaks and valleys, and the occasional activity operation will also produce peaks. Therefore, high concurrency and high flexibility is also a common demand in the game industry.

  • Stability, reliability and safety

To ensure the fairness of the game and the user’s player experience, to prevent cheating, so it is necessary to ensure the stability and reliability of the game.

  • Data, operation and maintenance, cost control

After the launch of the game, the user behavior is analyzed by collecting data from logs. According to the analysis results, different operation and maintenance strategies are implemented for different players, and the operation focus is placed on the swing players in the middle, so as to achieve accurate positioning and cost control.

2. Understand function calculation

The case to be introduced below is mainly related to function calculation, so here is a brief introduction to ali Cloud Serverless product – function calculation.

Functional computing: only need to focus on business code, oriented to functional minimalist programming (various programming languages), rich integration between cloud products and event-driven approach to provide end-to-end solutions.

  • Focus on business code

As you can see above, for game developers using functional computation, just pick the code you’re best at, write it, upload it to the computing platform, and you’re done. This function can then be called through the API/SDK or triggered from the cloud product event source.

This is a simple example, using Java function to write a “Hello World”, set it to Java8 execution environment, 256MB memory, set up the upload function calculation, the development task is complete, after the active call function, no need to pay attention to any infrastructure.

The “cloud product event source trigger function” is described separately here. In addition to active triggering functions, cloud products can also be used to trigger. For example, if you use the object storage OSS of Ali Cloud, upload a ZIP package to a directory in the OSS Bucket, and hope that a function will be triggered automatically after the upload, and then the function will automatically decompress the ZIP package. This effect can be achieved when triggered by the event source of cloud products. There are many other event sources, such as log event sources, MNS message event sources, timing event sources, and so on.

  • 100 < code

Functional oriented programming with minimal focus on core code. Also support a variety of programming languages, very friendly to developers, developers can choose their best language, write after upload function calculation can be.

  • 100ms extreme elasticity

If the function is triggered and 10, 100, 1000 or even 10,000 requests come at the same time, do not worry. The function calculation will pop up the execution environment at the level of 100 milliseconds. Each execution environment executes the function logic code, and then returns the result of the function execution, helping the online business to deal with all kinds of unexpected traffic.

  • 100% Resource Utilization

In terms of accounting, function calculation is based on the memory and execution time of the execution environment. The granularity of accounting can reach millisecond level. Only the resource consumption generated by the request is paid, and the resource utilization reaches 100%, reducing the cost.

Two, Serverless game scene practice cases

1. Highly flexible battle settlement service

Battle settlement is cpu-intensive, and the settlement system requires a lot of computing power every day, especially when a large number of players suddenly flood in during the opening of the server or activities, resulting in a sudden increase in computing amount. Meanwhile, the settlement system needs to maintain a stable delay to ensure the user experience of players.

In SLG games or turn-based game scenarios, for example, after a battle, for the sake of user experience, the client needs to settle up first and show the results of the round, such as winning the popup animation and losing the popup animation. If you rely purely on the client, it is likely that the client will cheat (such as cheaters), so the final settlement will definitely be done by the server.

As the game planning team came up with more and more ideas, the game became more and more complex, such as buffs, debuff, crits, etc. The more fun the game gets, the more complex the settlement system gets, the more likely the game will stall, and the best solution is to take the CPU-intensive logic of battle settlement out of the way. This scheme is especially suitable for new service opening, during activities and daily peaks and valleys.

As shown in the figure above, when the customer migrates the battle settlement to the function calculation, it is obvious that even though TPS linearly increases at 90° in daily peaks and valleys, the Latency is still basically stable between 200 and 300 ms, which fully ensures the user’s player experience.

In this scenario, the core values of function calculation are:

  • Elastic high Availability (HA) : You do not need to reserve any resources for expansion at a scale of 100 milliseconds.
  • CI/CD and version grayscale capability: The battle settlement function will be updated every time the game designer has a new idea, and you can safely grayscale to the next version of the battle Settlement function by setting the version and alias directly to the function.

This is a classic example of a Game setting that takes cpu-intensive logic out of the equation and puts it into the calculation of functions, allowing for the ability to scale in a hundred milliseconds without affecting the Game Server, ensuring the user experience.

2. Serverless to achieve super scale game marketing

Game manufacturers and advertisers jointly launch a large number of Internet advertisements. In such a business scenario, it is impossible to accurately estimate the operating traffic. High concurrency and high flexibility of back-end services are crucial to business results. In addition, a large amount of marketing data and original logs need to be analyzed offline to drive the upgrade of operation strategy.

The needs of game manufacturers are: first, the game requires massive marketing, with unpredictable peaks and troughs; Second, the game needs to be launched quickly and requires high development efficiency.

The solution is to embed a function in a web page, trigger the function automatically when clicked, and persist the user message sent by the click to Kafka. The TPS of this step is very high, and is estimated to be in the tens or hundreds of thousands. In the second step, after the kafka connector is used to persist messages, the Connector can have batch operations. For example, the connector can batch 50 clicks of data into one and send it to another function, which is equivalent to 1/50 of the call volume. In addition, this function is asynchronously triggered and batch operations are added to complete the task, as long as the message is not lost to the database. The logs printed by this function can also be analyzed using SLS or written to the database RDS/ADP for player portrait analysis.

The customer pressure test data is shown in the figure below. The TPS of the first function rises to tens of thousands, and becomes less than 30,000 after the second peak cutting and valley filling.

In this scenario, the core values of function calculation are:

  • Event driven, decouple architectural difficulties;
  • Elastic high availability, peak cutting and valley filling;
  • Rapid development on-line, 1 day to complete the development and pressure test.

3. Serverless Android game APK package distribution by channel

The game APK package of the GAME distribution platform of UC needs to obtain the channel number according to the parameters in the real-time request and write the channel number into the fixed position of the APK file. UC has a large number of download requests from different channels every day, which enables users to download the APK game package of the specified channel in real time.

Take Ali’s internal UC game distribution platform as an example. One original package is placed in the object store, and the other packages add something in the fixed position of the file. However, the UC Channel has different download requests every day. Channel=UC/ Xiaomi/Huawei to CDN, and CDN directly returns to the function for calculation. For example, when the function calculation shows that the back source is Xiaomi, get the original package from OSS, write in the information of xiaomi Channel, and then directly return the package to CDN. Once it’s downloaded, it’s cached into the CDN.

In this case, the core values of the function calculation are:

  • CDN directly back to source elastic high availability function computing Service (FC);
  • Reduce costs and pay on demand. Customers do not need to reserve computing resources for the peak, and the unit price of traffic is reduced by 40%.

4. Serverless to achieve fast multi-channel game packaging

Before a game is released, it is common to build the game master and the different channel resource packs into channel packs for different distribution channels. There are pain points in this build process that are error-prone, inefficient, and costly if you use manual methods.

  • ** low efficiency: ** for different channels to package, the traditional way is to buy a few fixed baler, baler may waste most of the time, a few times a week;
  • ** High cost: the number of ** channels is increasing, and there are only a few balers. If you want to check the channel package, you may need to play all night to see it the next day. With the increase of channels, baler also need to increase, idle cost is becoming higher and higher;
  • ** Error prone: ** how to assign tasks to the baler, the scheduling system needs to develop their own, if the baler appears abnormal, need to solve the problem of the baler.

In this scenario, the Serverless workflow is introduced, as shown below:

Workflow definition: Step 1, download the parent package from OSS; The second step is to package these packages in parallel, each channel package has a parallel task; The third step, after packing, for post-processing.

In this scenario, the core values of function calculation are:

  • Task automation: events are triggered by one button and run automatically. Workflow tracks and records the whole packaging process completely to improve the success rate of packaging.
  • Package parallelization: The package construction process of multiple channels is parallel, which improves packaging efficiency and supports configuration templates.
  • Low cost: pay by volume, high utilization of computing resources.

5. Serverless To achieve rapid global deployment of game services

As the first cloud vendor in China to integrate with Terraform, Aliyun has relatively complete ecological support (Serverless heavily relies on cloud services, with relatively complete support in China). Since it’s not possible to use many other cloud services, Terraform allows for fast, multi-cloud deployments.

6. Summary of practical cases

  • CPU intensive interface
    • Battle settlement;
    • In social games, in-game screenshots, online screenshots of live game videos, offline transcoding, etc.
    • Chat sensitive words detection and filtering, chat translation;
    • Leaderboards, etc.
  • Game activity operation
    • Activation code generation, consumption and other closed test operation activities;
    • Game packaging and publishing, advertising buying, activity page, operation platform and other business platforms.
  • User basic business data processing

Third, the current situation of Ali cloud function calculation

1. Function computing is the preferred product of Domestic enterprises’ Serverless architecture implementation and business innovation

According to the survey report of Chinese cloud native users in 2020, aliyun Serverless accounts for 66% of users. CNCF’s 2019 China Cloud Native Report shows that function computing is the preferred product of Domestic enterprises’ Serverless architecture implementation and business innovation.

2. Aliyun Function computing product panorama

Function computing is the Serverless product with the most complete ecology and rich functions in China, and the one-step cloud and one-button Serverless will become a reality for developers.

Picture: Aliyun function computing product panorama

  • System level: support a variety of languages, developers can choose their favorite language, but also support container mirror, embrace container ecology;
  • Instance type: 100 ms elastic instance is selected by default, but performance instance (such as strong CPU intensive audio and video transcoding) can also be selected.
  • Trigger layer: it can be triggered directly by API Gateway or SDK, or triggered by event sources such as Kafka, OSS, and CDN.
  • Tools layer: New Serverless-Tool, Fun, developer framework, and more;
  • Observability: including logs, monitoring, Metrics, alarms, Tracing, etc.
  • Application center: there are very good landing cases, you can quickly experience classic cases.

Appendix for reference

  • Jiangyu Interactive: Exploration of Serverless architecture in the field of games
  • Game packaging process is boring and tedious, how to improve the efficiency of packaging? A new way to watch whale flag games
  • In the game operation industry, how does Serverless solve the pain point of data acquisition and analysis?
  • Function calculation FC power game group acquisition marketing data is watertight
  • Build battle settlement service based on ECI+FaaS
  • Entertainment/education industry: Push stream, transcoding one-stop solution
  • Retail industry: Online and offline business Serverless transformation

About the author: Luo Song (Xiliu), currently responsible for the function development of Aliyun function computing products: After graduation, I have been engaged in the development of mobile games for two years, and experienced the complete process of project approval, RESEARCH and development, and launching of mobile games. I have devoted myself to Serverless tide for 17 years, and committed to implementing better Serverless/FaaS practice cases. Build the best open source Serverless community in China.

This article is compiled from the Serverless Live series matinee, 27 January

Live back to see links: developer.aliyun.com/topic/serve…

Serverless Ebook download

Book highlights:

  • Starting from the evolution of architecture, it introduces Serverless architecture and technology selection and construction of Serverless thinking.
  • Understand the operating principle of Serverless architecture popular in the industry;
  • Master 10 Serverless real cases, live learning and use.

Download link: developer.aliyun.com/topic/downl…