Good day. I want to know how it will be better and faster to make a table of records in the game. There is a table with users who have a rating. It is necessary to display always the top 25 players of a million or more. In my head, there are two options.

  1. make a sample of the total number of players every time a player wants to see a table of records.
  2. start another table and each time as some user the rating changes, check it falls into that table or not.

The second option seems to me more benign, but it seems to me that it is possible to make something more beautiful, but I don’t know how. Maybe in mysql there are some tools that will help me achieve the desired? In general, any suggestions how to organize such top players advice would be helpful for me.

  • Who writes to the database? where should be displayed? when recorded in the database? - Vadim
  • The java game server writes to the database. The server must, with the appropriate request of the client, send it data on the rating. The rating value changes only at the end of the battle, say within the framework of one player this happens every 5 minutes directly in the game session - borisenki

2 answers 2

Option 3.

Make a static list in memory (player, rating). Set the timer to update this structure from the table in the database at intervals. The interval depends on your task. In my opinion, 30 seconds or 1 minute is quite good.

This option is optimized for a huge number of readings and significantly relieves the database.

  • And this list can be made a plate in the database? or easier and will it be stored elsewhere? - borisenki
  • In my decision we remove the load from the base. This is used when a large number of requests. - pavelip
  • What's the point? if there are all the necessary indices, then the load on the base is minimal. Why does everyone want to not use the DBMS correctly (and it’s sharpened to work with data), while trying to make its own version? :-) - Chad
  • @ Chad because under high load subd can’t cope - pavelip
  • @pavelip, usually does not cope, not because it can not, but because it is hammered with screws, instead of using it correctly - Chad

And a sample from the table of the first 25 values, sorted by rating, taking into account the fact that there is an index in the rating field than is bad?

This means that there is an index on the rating field, so that when querying, the base does not go through all the records, and in fact takes only 25

  • nothing, so I ask. Is the rating value assumed to be an index? - borisenki