I have an iphone based online game with many games running at the same time. I am in the process of optimizing the code since today I and the server crashed.
This is the setting:
Right now I have one table that "matches" (70 data fields for each row. Structure) that track all active matches. Every 7 seconds, the iphone will connect, download all matches in the match table in which he / she is active, and update the user interface on the iphone.
This did a great job until around 1,000 people downloaded the game and played. The server crashed.
So, to optimize, I suppose I can create a new table called "matches_needs_update". This table has 2 rows; name and identifier. "Id" matches the match in the matches table. When a match is updated, it is placed in this table.
Now, instead of searching the entire matches table, the query simply checks to see if the player has any matches that need to be updated, and then get these matches from the matches table.
My question is twofold:
- Is this the best solution?
If a player is active, say, 10 matches, is there a good way to get these 10 matches from the match table at the same time, or I need a for loop to execute 10 queries, one for each match:
"SELECT * FROM match WHERE id =?"
Thanks in advance
Blackmouse
source share