5

I have a multiplayer game which have started to generate some strange errors as more and more players have singed up.

There's about 1.5 million queries to the database/hour, and I think the problem is that some queries getting executed before some other queries have completed, since I didn't have any problems before, and I getting more and more as more people sign up.

I have two main classes: "sendTurn.php", and "removePlayer.php". If a player have taken to long to respond, he's kicked out. But I guess that problem is what happens if a player make his turn, just as he's being kicked out?

I read somewhere that the queries are put in a queue, but since it require several querys in each class to complete it, is it possible that when, for example, "sendTurn.php" is halfway done (done the first 1-2 queries) that the other class "removePlayer.php" will start to execute its queries?

In this case, what can I do?

Edit:

I use apace2 on a debian VPS server, with phpmyadmin

7
  • What kind of API are you using? mysql, mysqli, mysql-pdo? Commented Apr 28, 2012 at 11:47
  • How about wrapping those queries in a transaction? Commented Apr 28, 2012 at 11:49
  • thanks for reply. I use apace2 on a debian VPS server, with phpmyadmin Commented Apr 28, 2012 at 11:49
  • 1
    Is there any performance penalty for transaction? Commented Apr 28, 2012 at 11:52
  • What is the name of the php functions you use to connect to the database and perform queries? Commented Apr 28, 2012 at 12:03

1 Answer 1

3

It looks like a real solution would be a full architecture review, since this is more of an architecture question rather than a technical one. It's possible you can avoid this issue altogether but there is not enough information for me to use. However you could lock the sensitive tables whenever they are accessed for the full extent of their sensitive process. There will be a performance hit when a lot of players try to reach the same functions, but at least it will work.

For example for such a function

*LOCK TABLE*
Do queries
Do queries
Do queries
Do queries
*UNLOCK TABLE*

MYSQL example: http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.