Skip to content

[Enhancement]: Rework matchmaking #33

@DaniElectra

Description

@DaniElectra

Checked Existing

  • I have checked the repository for duplicate issues.

What enhancement would you like to see?

Current issues

The current matchmaking implementation has many issues, including the following:

  • It is very prone to race conditions, since the Sessions map doesn't use any mutexes
  • We currently store the participants based on the connection ID, but this is inaccurate since Nintendo uses the PID instead. We need to change this in order to support multiple players from one console such as on Mario Kart 8
  • This model of storing the session data in memory is kinda flawed. While it works for games that only use MatchmakeSession, it doesn't work for games that use other gathering types. For example, Mario Kart 7 communities use PersistentGathering which uses the same gathering ID count as MatchmakeSession and must be always preserved between server reboots/crashes, but both MatchmakeSession and PersistentGathering use UnregisterGathering to delete them (which would require various hacks to handle on the current model). This model is also problematic for tracking, since we don't keep records of previous sessions

Proposal

PR #28 fixes the race conditions issue and it could be expanded to fix the second one, but as explained above this isn't enough. We will have to redo matchmaking from scratch. On Discord it has been proposed to store everything on an SQL database (since it's what Nintendo does) which would be managed by the common protocols implementation, while giving the liberty to the servers to choose a specific SQL database.

On this new implementation we still need to take into account race conditions and avoid them along the way, and we would also store connections based on the PID. This new model would also solve the session tracking issues since we are keeping records of all previous sessions

Any other details to share? (OPTIONAL)

As a nice to have, it would be great to design the new matchmaking model in a way that could support any Gathering type and not be limited to only MatchmakeSession and PersistentGathering. I think this could be reasonably done but we will have to see until it gets implemented.

Since we intend to use SQL, this issue partially depends on PretendoNetwork/nex-go#56 since the current NEX primitive types limit us on how we use them as native types.

On this new implementation we would also like to allow any SQL database, but we currently have a big dependency on Postgres and the pq.Array function (among possibly other Postgres-specific queries) across our different servers. While it may be doable, we would require some assistance from people that would be interested on this and would like to use other SQL databases.

Metadata

Metadata

Assignees

Labels

approvedThe topic is approved by a developerenhancementAn update to an existing part of the codebase

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions