Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Database locking/transactions techniques for browsergame PHP/MySQL


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 gdops   Members   -  Reputation: 101

Like
0Likes
Like

Posted 23 July 2012 - 10:56 AM

Hi everyone,

I'm wondering what's the proper way to handle concurrent actions in a browsergame, that access the same resource (e.g. one player's warehouse), combined with the "on view" method instead of cronjob.

Basically that means, instead of running some script that processes the action queues each second, the calculations are made when that resource (warehouse) is accessed the next time (e.g. one attacks and take resources, or the player itself spends some of them).

Problem obviously occurs when two players access the same resource at the same time, and I'm not sure if there's a good-proven standard way to implement this...

Some guesses of me would be:

1. Using MySQL transactions (one transactions includes: read from actions table, execute them, delete executed actions)
2. Using MySQL table lock for actions table
3. Locking with PHP flock()
4. Using semaphore with PHP sem_acquire()


Any suggestions?

Sponsor:

#2 hplus0603   Moderators   -  Reputation: 5693

Like
0Likes
Like

Posted 25 July 2012 - 04:16 AM

There are several standard ways of solving the simultaneous-update problem. For example:

1) Use a database transaction around the entire thing (and, if MySQL, make sure transaction isolation is "serializable.")

2) Use a manual spinlock, using something like a short-lived key in memcached to automatically remove it if the process crashes.

3) Use consistent hashing to map update requests for a particular "ID" go to a particular server and thread/instance; this makes updates for a particular "ID" be inherently serialized.

4) Use a worker queue to serialize updates that need to be done.

enum Bool { True, False, FileNotFound };

#3 Navyman   Crossbones+   -  Reputation: 4053

Like
0Likes
Like

Posted 26 August 2012 - 10:51 PM

Thanks for posting this. I had a friend that had a similar question.

Developer with a bit of Kickstarter and business experience.

34410.png




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS