There is a Facebook-based Flash game that pings the application server once a second to check the connection. The essence of ping is to write the timestamp in the database when the client was last connected.

One player - one request per second. But here are 10 thousand players, and somehow the resources of the database are wasted, 10 thousand times per second updating not particularly valuable data, which live less than a second.

While it occurred to me to connect memcache (it happens on Heroku), and store / update player timers in it. Synchronize with the database once every N minutes already. As a separate worker, go over the cache, removing from it in the database the records of players who fell off more than 3 minutes ago, for example.

Surely, there are normal / best practices how to deal with this kind of task. Hint?

  • @sergiks, why is the problem not relevant? In general, according to the normal, in this kind of games, the client should open a real-time connection, thus, most likely, more than half of the crutches can be thrown into the database, incl. This is because, if the user is offline, you will immediately see this (handling the disconnect event), and you will be able to implement, for example, sending from one user to another without crutches in the form of queues in the database. In general, as for me, PHP is out of place here at all - Zowie
  • In this project, everything was decided by correcting the logic of the game communication with the server. In fact, this is not RT communication, because there is no simultaneous involvement of several players. It is rather a "problem counters." - Sergiks
  • In this case, I don’t see a problem in using, say, redis and completely refusing to store such data in rdms - Zowie
  • I agree. But here is the case when you have to go, and not checkers. Run the game as soon as possible in public. - Sergiks pm
  • In my opinion it is better to postpone the trip and then go normally than start driving and are afraid of an accident :) - Zowie

1 answer 1

Why constantly ping the server?

If the user does some actions, he calls the server on any, but you should not constantly write his logs of calls.

Why have every second value online user on the site? Who needs it? It would be all the same to me, for me + - an hour is quite the right time with a lot of site traffic. so I see no reason to ping every second just a server and load the database.

Meaning then in the game what? Load a server with values ​​when the user was last in the game?

If the game is made as an Iframe, then you can think about the cache, but no more than once every 15-30 minutes, otherwise the meaning of the cache itself, storing 1 variable for 1 minute.

  • "Moped is not mine," customers like that. My task is to prevent their server from crashing. A 2D shooter game. Perhaps in the near future semi-interactive in semi-real time, for which they synchronize time. At the same time, some game resources are tied up, such as the airplane's gas tank. - Sergiks
  • so that the server does not fall, you do not need to finish it with stupid queries. if they do not know the word "optimization" then the client is "Always wrong!" In this case, the game will always fly out. 10K players, constantly send data to the server. Example: - let's say 16Mb on php - apache process result: 1 server never pulls it, and 2 too, here they need at least 5-10, with such requests + backups are constant, once you need real time and everything works, SSD screws for quickness. and so on. > customers like that. > My task is to prevent their server from crashing. Will fall! - Artem