开发者

PHP, MySQL, Memcache / Ajax Scaling Problem

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) r开发者_如何学Ceplaces 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.


Use a socket server to share active game information, PHP & MySQL really shouldn't be used to maintain active game sessions.

An opensource example of a socket server would be red5, if you dont mind paying a bit then I would recommend Smartfox.

It's also not too difficult to set up your own socket server, if you're only using it for basic communication between clients.


each game gets its own file. eg, 459675.html or .txt or .json or w/e this file can be an html page, or whatever you need to communicate the current state of the game.

the clients poll the webserver for the latest version of the file. the webserver acts like a good little webserver and serves this file extremely efficiently from disk because it doesnt need to do any scripting language junk to process the request.

when a client makes a move, it sends request to a script. script rewrites the file...repeat.

your webserver is probably already configured to send last modified headers for static files. your clients(browsers) already know how to do a conditional http request when they're given last-modified header. So, you get bonus efficiency boost for very little work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜