You will find another SO questions regarding concurrency however they don't quite address my scenario.

So let us state that I've a game title where customers communicate with one another, fighting and whatnot. At any time, a person may potentially engage in multiple interactions along with other gamers, all whom can easily see the big event happening. When any kind of these gamers hits the website, it must update data involved and reveal that towards the user.

Example situation: Player A is fighting with player B, and occasions happen every couple of minutes within this fight. Simultaneously, player A can also be getting together with player C. By dumb luck, the occasions for interactions occur to next be due in the identical second.

When that second arrives, by dumb luck again, both player B and player C hit the website simultaneously, to be able to look into the status of the fights with player A. Fighting requires updates to details about player A. Basically don't code correctly, A's data could possibly get screwed up.

I've two games with this particular situation, each having a different solution and various issues. One of these utilizes a lock, then when a person hits the website, they get a lock on the db row, browse the data for locks they effectively acquired, then write the alterations and release the lock. But sometimes, for reasons still unknown, this fails and also the lock will get stuck forever, customers complain and we must repair it by hand. My other game utilizes a daemon to complete these transactions, making the problem (nearly) moot as there's just one process ever making these changes. But gamers could still do other activities simultaneously, and potentially make the same problem.

I have read a little about different methods to this, like positive or timestamp-based control. I must request:

  1. Which could well be most generally employed for situations like mine, and that is simplest to implement?

  2. My next project is applying Kohana (PHP) and it is ORM, so my db creates will automatically go ahead and take form "just overwrite each one of these fields." Should i have to create my very own update queries with this or can one obtain a solution that's suitable for the ORM?

  3. How about transactions which involve multiple tables? The end result of the combat needs to alter the table of combats, and also the table of player information, possibly more things too. Which solutions are simpler to utilize here? Will all my tables need transaction timestamp posts?

  4. Many of these solutions state that when there's a conflict, either retry or ignore. Exactly what does this suggest for me personally? Does "retry" mean restart my entire script, which may cause additional load time for that user? I do not think ignore is really a valid option, because the occasions need to execute sooner or later. Within the other questions I discovered, showing a conflict error towards the user was often a valid option - for me personally, it is not.

  5. Do you know the performance implications of concurrency control - could it be even worthwhile?

I believe what you're searching for has already been found in your question : transactions. If you work with MySQL, you will have to setup your tables using the innoDb engine to have the ability to use transactions. Some documentation :

Create reinvent the wheel when you are able.