Coder Social home page Coder Social logo

cloudspannerecosystem / spanner-gaming-sample Goto Github PK

View Code? Open in Web Editor NEW
17.0 3.0 8.0 738 KB

This repository sets up a sample microservice architecture to highlight how Cloud Spanner integrates with other cloud technologies.

License: Apache License 2.0

Makefile 1.70% Python 7.21% HCL 8.87% Shell 0.50% Dockerfile 3.81% Go 75.14% Smarty 2.77%
cloud-spanner golang google-cloud kubernetes sample-app terraform

spanner-gaming-sample's People

Contributors

dependabot[bot] avatar dtest avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

spanner-gaming-sample's Issues

[Tradepost] Handle expired trade orders

After the expiration time, if an order is not purchased, handle expiring the trade order:

  • mark order as not active
  • make item visible to the listing player

[Items] Preload game items during setup

With the current setup, game_items table will be empty. This prevents game-workload and tradepost-workload from operating correctly.

There needs to be a way to seed the game_items table. A simple ./scripts/seed_game_items.sh could be created to run after the schema migration. But this would need to leverage Locust locally (or a dockerized version of the item workload ).

Or we just keep a small .sql file that gets imported.

Either way, the seeding step happens right after the very first schema migration, but before the service deployment.

TF managed APIs can mess up existing projects

It was reported that doing terraform destroy will destroy APIs that are enabled for the project, and thus projects with other Spanner instances will be messed up.

The TF scripts should be updated to not manage APIs. APIs should be enabled via a helper script that leverages the gcloud CLI and docs updated accordingly.

Add github workflows for PRs and Releases

PRs should initially run unit and integration test packages.

Releases should build binaries and create a .tar.gz with generators, binaries and readmes on 'vX.X.X' tags creation.

[Actions] Release note generation failing

The output from the automated release workflow for generating release notes is:

Run git log $(git describe HEAD~ --tags --abbrev=0)..HEAD --pretty='format:* %h %s' --no-merges >> ".github/CHANGELOG.md"
fatal: Not a valid object name HEAD~

So the release notes are not automatically generated. This should be fixed

[Generator] match_server.py should close the oldest open game

Currently, the generators/match_server.py file can only close games open during the same workload run.

This was done to prevent getting a big list of open games, which was an endpoint added specifically for the workload generator and not very performant.

Instead, we can implement a 'GET /games/open' endpoint with a filter on oldest to retrieve the oldest open game that can then be closed.

[Feature Request] Add player queueing

Due to the way matchmaking currently works, there is a bottleneck on scaling matchmaking and player signups:

  • If we have more than 1 createGame attempt at a time, we run into deadlocks as matchmaking tries to assign the same players to different games.
  • Due to locking for these deadlocks on the 'PlayerGame' index, actually inserting new players (CreatePlayer) suffers higher write latency.

To mitigate this, instead of assigning players to a game from ALL players ever, introduce a queue that simulates players 'getting ready to play'. This should reduce/remove lock contention on the PlayerGame index. We may still get deadlocks for concurrent CreateGame attempts, but it should be much smaller chance.

Design:

  • modify schema to allow for queue
  • modify matchmaking to assign players longest in the queue
  • keep track of average wait time in queue
  • game cannot be created if not enough players are in the queue.
  • game should not be created if players wait < average wait time. If there's not an average wait time, set a floor to prevent a flood of game creations.

Create initial UI

The initial frontend UI will have the following elements:

  • Ability to browse items listed on trading post
  • Leaderboard for players with games won vs games played

[Structure] Restructure the src directory

The idea that each service would be created in a different language is no longer a goal. Future services can be written in different languages to be useful as examples.

So the existing services should be moved to a backend_services directory to represent a full project.

[Tests] Split backend tests to only run for the respective service

Currently Github Actions runs lint, unit and integration tests for all backend services when any backend service changes. This causes long check times when PRs are opened, as well as dependency issues if one service is breaking unrelated to the one being modified.

The backend_pr.yaml workflow should be split up to only trigger the respective backend service's tests.

[Players] Track login behavior

This depends on functionality from #12

We want to track player login behavior over time. There are two ways to do this:

  • in Spanner itself, introduce a new 'ledger' table for player events such as 'login', 'logout', etc
  • Use BigQuery as an example for using Change Streams. This option has added architectural complexity.

[Feature request] add locust generators to GKE environment

In order to get the lowest latencies from the backend services, the load generator should run as close to the services as possible. This requires running on GKE once the services are located there.

Dependencies

Requires a GKE environment #2

[Terraform] Kubernetes provider information fails on first run

If the gke cluster is not setup, the kubernetes provider will fail to work.

Providers do not have a depends_on option currently. But Data blocks do. So setting the data.google_container_cluster.gke_provider to depend on the gke cluster resource being available should solve this.

[Workloads] Improve game-workload logic for getting players of open games

Game workloads get a random player for acquiring items and money (each call). The 'GetPlayer' endpoint is expensive and shouldn't be called very often.

Explore caching a list of players that are actively playing games for this workload.

The risk is a cached player could end their game before they're used to acquire items/money.

Add item categories

Items should have categories.

Come up with generic category list, and implement.

[Workloads] Improve logic for getting games to close in matchmaking workload

The query to get a random open game to be closed looks something like this:

query := fmt.Sprintf("SELECT gameUUID FROM (SELECT gameUUID FROM games WHERE finished IS NULL ORDER BY created DESC LIMIT 10) TABLESAMPLE RESERVOIR (%d ROWS)", 1)

These random queries are too expensive in terms of CPU, especially as the games table grows. Additionally, this is called very frequently.

It would be better to improve the generator logic to get a list of 100-1000 open games to store in a queue. When the queue is empty, another call to get more games to close is issued to the backend.

[Testing] Improve schema handling for integration tests on Spanner Emulator.

Currently the schema/players.sql and schema/trading.sql files are copied into the backend service's folder to run integration tests.

It would be nice to use wrench as part of integration tests to validate schema migrations are working.

There are some issues with this though:

  • applying migrations against the emulator will eventually take a while. This can be solved by loading the 'current' schema into a file. Question would be where to get that 'current' schema?
  • The emulator can lag on feature parity with Cloud Spanner. This means that integration tests can fail if the emulator doesn't support a particular SQL feature we're taking advantage of in this sample gaming app.

So will need to figure out how to handle those two points when improving integration tests.

Create bash script for running generators

This is to prevent users from having to manually type in locust commands.

The script should ideally allow running in headless mode or in webui by forking the process.

[Feature request] Enable player login

Add endpoints for players to login and logout

New endpoints for authentication server and players service:

  • PUT /players/login: takes username and password as arguments. Returns playerUUID on success
  • PUT /players/logout: takes playerUUID as argument, returns 200 success, but no content (some concerns about authenticating access to this endpoint, but really no endpoint should be able to be hit without proper credentials)

This will update a 'logged_in' timestamp field in the players table, which will be set to null on logout.

Track login events in a separate table player_login_entries

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.