PHP, MySQL, Memcache / Ajax Scaling Problem

Posted by Jeff Andersen on Stack Overflow See other posts from Stack Overflow or by Jeff Andersen
Published on 2011-01-16T03:45:02Z Indexed on 2011/01/16 3:53 UTC
Read the original article Hit count: 186

Filed under:
|
|

I'm building a ajax tic tac toe game in PHP/MySQL. The premise of the game is to be able to share a url like mygame.com/123 with your friends and you play multiple simultaneous games.

The way I have it set up is that a file (reload.php) is being called every 3 seconds while the user is viewing their game board space. This reload.php builds their game boards and the output (html) replaces their current game board (thus showing games in which it is their turn)

Initially I built it entirely with PHP/MySQL and had zero caching. A friend gave me a suggestion to try doing all of the temporary/quick read information through memcache (storing moves, and ID matchups) and then building the game boards from this information.

My issue is that, both solutions encounter a wall when there is roughly 30-40 active users with roughly 40-50 games running.

It is running on a VPS from VPS.net with 2 nodes. (Dedicated CPU: 1.2GHz, RAM: 752MB)

Each call to reload.php peforms 3 selects and 2 insert queries. The size of the data being pulled is negligible. The same actions happen on index.php to build the boards for the initial visit.

Now that the backstory is done, my question is:

Would there be a bottleneck in that each user is polling the same file every 3 seconds to rebuild their gameboards, and that all users are sitting on index.php from which the AJAX calls are made within the HTML.

If so, is it possible to spread the users' calls out over a set of files designated to building the game boards (eg. reload1.php 2, 3 etc) and direct users to the appropriate file. Would this relieve the pressure?

A long winded explanation; however, I didn't have anywhere else to ask.

Thanks very much for any insight.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql