Global Leader in Google App Engine

I want to create a backend for a mobile game that includes a global leaderboard in real time for all players, for events that last a certain number of days using the Google App Engine (Python).

Typical uses will be as follows: - The user starts and ends the battle by acquiring points (2-5 minutes for the battle) - Points are accumulated in the player’s account throughout the event. - The player can check the leaderboard at any time. - Leaderboard will return the top 10 players, as well as 5 players just above and below player points.

Now there is no real restriction on the real-time aspect, the board can be updated every 30 seconds, every hour. I would like it to be as fast as possible, without too much cost.

Since I am not very familiar with GAE, this is the solution I was thinking about:

  • Each Player object has an event_points attribute
  • Using the Cron job, a query to the data warehouse is performed at regular intervals for all players whose score is not zero. The request is sorted.
  • The cron job then iterates through the results of the query, writing down the ranks in each Player object.

When I think of this decision, it feels like brute force.

The problem with this solution is the cost of reading and writing for all objects. If in the end we get 50K active users, this will mean a sorted request of 50K + 1, and 50k + 1 will be recorded at regular intervals, which can be very expensive (depending on the interval)

, memcache , memcache, ? , , memcache , , " " , , .

?

+3
3

50 000 50 000 . , points. , , , , points. cron, .

, , : 6 ; - 6 . , , .

10, Memcache , , 5 . , Memcache. , Memcache.

EDIT:

. , . App Engine :

  • , , , .
  • , .
  • , , , , , , , .

, ASCENDING GREATER_THAN_OR_EQUAL DESCENDING LESS_THAN_OR_EQUAL . 6.

: 6 , . (userId NOT_EQUAL ), - . , GREATER_THAN/LESS_THAN , .

+2

Google Developer article, Google JAM . Google forum.

N- node, . node, . (O log (n)) , , . . , .

+1

, .

, - , . , .

( ). . , , . . . . , , .

, , ( 7 ), . (.. , - , ).

When players look at their rank, you can do this with two simple queries Players.query(Players.score > somescore).fetch(5)and Players.query(Players.score < somescore).fetch(5), it should not cost too much, and you can cache them.

0
source

All Articles