question

mattrochon avatar image
mattrochon asked

shared group data mutex

I am using shared group data for online game storage in a turn based game. The way the game works is that for each turn when all players have submitted their moves we process the turn end and send the results to the clients.

The issue is if 2 players (or more) submit at the same time causing a concurrent request. I am trying to minimize the amount of api/data requests to the playfab api so all the turn data is loaded at the start of the request.

To this end it creates a race where neither request notices that the turn should be completed now. Normally I would solve this with some sort of mutex or critical section but this doesnt seem to be available in cloudscript.

What is the recommended way to solve this?

CloudScriptShared Group Data
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

Shared Group Data was really only intended as a simple shared data solution for scenarios where you only have one player allowed to update it at a time, or where players are each writing to different Keys in the data, to prevent issues - realistically, if you're going more complex than turn-based games where only one player can be playing a turn at a time, there will be cases where things like simultaneous updates could cause problems. If you want to have full authority over those updates, we'd recommend either Photon Enterprise or a custom game server, so that you can have full control over this.

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

mattrochon avatar image mattrochon commented ·

So this actually isnt far off from what you describe, except that in each turn all the players (2-5) can make their moves at the same time, and I just need to detect when the turn is over to kick off some processing. There is no realtime or near-realtime transfer of information, all the moves just go into a queue to be processed at turn end.

If shared group data had a CheckOrSet type method that was psuedo atomic it would solve everything in this case.

0 Likes 0 ·
brendan avatar image brendan mattrochon commented ·

Understood, and I can add a request to the backlog, so that if others ask for this we can keep track of that, but the way Cloud Script is designed right now, I can't recommend it for this, for the reason you called out - concurrent updates. Since you need a way to manage that queue of moves and allow for simultaneous updates, I'd have to recommend using a custom game server or Photon Realtime.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.