Page 1 of 1

Top scores page, how to efficiently?

Posted: Mon Jun 28, 2010 9:37 am
by Callan S.
What's the best way of going through all players and listing the top ten players who have the highest in X statistic?

I'm thinking this page would get accessed a fair bit, or could be, and the only way I know I think is too DB access intensive.

Thanks for any help :)

Re: Top scores page, how to efficiently?

Posted: Mon Jun 28, 2010 10:29 am
by PaxBritannia
You could cache the results. (Not using the standard definition of cache)

Set a cron to dump the results into a top scores page every midnight (or so often).

When someone wants to access the top scores, redirect them to the top scores page.

Pax.

Re: Top scores page, how to efficiently?

Posted: Tue Jun 29, 2010 9:03 am
by dave3460
yep i agree crons is the best way i have done the same type of time via crons .
if you need some help i can post it .
Mine gore from a recordset to using the dynamic data

Re: Top scores page, how to efficiently?

Posted: Wed Aug 25, 2010 9:53 pm
by Baseball435
i forget how i did it but there is a way you can grab information from the sql server like "SELECT * FROM x ORDER BY id DESC 10". something like that. its what shoutboxes use

Re: Top scores page, how to efficiently?

Posted: Wed Aug 25, 2010 10:41 pm
by Jackolantern
Baseball435 wrote:i forget how i did it but there is a way you can grab information from the sql server like "SELECT * FROM x ORDER BY id DESC 10". something like that. its what shoutboxes use
Yeah, that would work provided your score is based on a column in the database. Something like "SELECT name, score FROM users ORDER BY score DESC LIMIT 10" (basically what you have) will pull up the top scores. And then just use a cron set to run however often you want it to update.

Although I think it would be better to run it more often than once a day, as that helps feed the competition for the top slots. A small script like this basically takes almost no resources to run, so running it once every 10 or 15 minutes will have almost no impact on resources versus running it once a day at midnight. This way, players can immediately see the fruits of their work, and the over-taken player can immediately start playing harder to try to take their slot back.

Re: Top scores page, how to efficiently?

Posted: Thu Sep 02, 2010 8:26 pm
by spawnfestis
Jackolantern wrote:
Baseball435 wrote:i forget how i did it but there is a way you can grab information from the sql server like "SELECT * FROM x ORDER BY id DESC 10". something like that. its what shoutboxes use
Yeah, that would work provided your score is based on a column in the database. Something like "SELECT name, score FROM users ORDER BY score DESC LIMIT 10" (basically what you have) will pull up the top scores. And then just use a cron set to run however often you want it to update.

Although I think it would be better to run it more often than once a day, as that helps feed the competition for the top slots. A small script like this basically takes almost no resources to run, so running it once every 10 or 15 minutes will have almost no impact on resources versus running it once a day at midnight. This way, players can immediately see the fruits of their work, and the over-taken player can immediately start playing harder to try to take their slot back.
As far as you're not looping through thousands of users, you can run it as per query basis. So to speak, as long as your toplist ain't going to be looping through thousands, you can run it once everytime someone wants to check it!

But for large games, yes, updating it via cron.

Re: Top scores page, how to efficiently?

Posted: Thu Sep 02, 2010 10:46 pm
by Jackolantern
But of course, most devs do want to have 1000's of players. For a small game not open to the public, that would likely be fine, but typically you want to write your game to be as scalable as possible since sometimes you only have hours to expand your game to meet rising demand. Writing scripts that break or slow down the system with only a few thousand users should be avoided for public games.

Re: Top scores page, how to efficiently?

Posted: Fri Sep 03, 2010 3:05 am
by Callan S.
In the end I just made it record the last time the high score page was looked at, and if it's more than thirty minutes, it then updates the highscores. No cron needed.

Re: Top scores page, how to efficiently?

Posted: Fri Sep 03, 2010 4:35 pm
by Jackolantern
Callan S. wrote:In the end I just made it record the last time the high score page was looked at, and if it's more than thirty minutes, it then updates the highscores. No cron needed.
Yeah, for something that is not critical for it to only run once, such as a high scores page, the "page view" method would work fine :)