Cost Optimization

Design guide for optimizing GS2 usage fees.

Since GS2 uses a pay-as-you-go pricing model, usage fees can vary significantly depending on the game’s design. This section explains key design points to keep costs down while maintaining performance.

1. Reduction of API Call Count

A large portion of GS2 fees is determined by the number of API requests.

Utilize SDK Caching Mechanism

The GS2 SDK has a built-in caching mechanism. When the same data is retrieved multiple times in a short period, it is designed to return the data from the cache without sending a request to the server. Use high-level APIs (access via Domain objects) whenever possible when using Future or Async versions of SDK methods.

Batch Retrieval and Updates

For example, when retrieving the quantity of multiple items, it is more cost-effective to retrieve the entire inventory at once rather than calling the API for each item individually.

2. Proper Resource Management with GS2-Deploy

If unnecessary namespaces or resources remain, small storage fees or management costs may continue to accrue. For development or verification environments, you can clean up related resources all at once by deleting the GS2-Deploy stack when they are no longer needed.

3. Execution Efficiency of GS2-Script

GS2-Script execution fees vary depending on execution time.

  • Efficient Code: Improve the efficiency of the Lua scripts themselves to reduce execution time, such as by avoiding unnecessary API calls within loops.
  • Minimize External Communication: External communication such as http.get can significantly increase execution time.

Note that while memory usage does not directly affect fees, there is a limit on the available memory capacity.

4. Leveraging Logs and Analytics

By associating GS2-Log in the namespace settings of each microservice, you can collect access logs (request and response content) for each microservice. This allows for detailed analysis of whether specific features are generating more requests than expected and which APIs are contributing to costs, helping you optimize your application.