tags:

views:

37

answers:

2

Hello, I'm making this game where I'm trying to "pair people". So I have this database where I add people when they want to join a game. And when two people want to join a game, I redirect them to the game.

But I wanted to make this in ajax (which I'm a new to), so that it continually looks at the database if a new person has joined. I thought using this would be a good method:

new Ajax.PeriodicalUpdater('products', '/some_url',
  {
    method: 'get',
    insertion: Insertion.Top,
    frequency: 1,
    decay: 2
  });

But then he reminded me that it'd open and close the database all in vain very many times. Is there a better solution?

A: 

Correct, using the database is going to increase its load. Depending on how much load you have, it might take more than 1 second to return, in which case the application will eat itself.

Another option would be to keep something in memory on the server side. In PHP there is no 'app server' concept, so DB is a good place, or something like memcache.

Also, you need to think about transactionality. What if 3 people end up in the game?

NW Architect
Thank you so much, of course I should save it on the memory. This game will not be very public (it's for a school project), so the 3 people problem will not be common. :D
A: 

If the people can register for gaming only when the application is active, why to save this information to the database? Serving information from an url doesn't need to load it from the database. It could be a repository of different type (eg. memory).

If you have only one application server it is just fine to store the people list in shared memory object, for a application farm different rules may apply - depending of your configuration and session storage used.

twk
Yes one application server. Thanks again!