Top scores page, how to efficiently?

C++, C#, Java, PHP, ect...
Post Reply
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

Top scores page, how to efficiently?

Post 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 :)
Fight Cycle : My latest Browser game WIP
Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog
User avatar
PaxBritannia
Posts: 680
Joined: Sun Apr 18, 2010 1:54 pm

Re: Top scores page, how to efficiently?

Post 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.
dave3460
Posts: 117
Joined: Wed Jul 01, 2009 2:13 pm

Re: Top scores page, how to efficiently?

Post 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
Baseball435
Posts: 548
Joined: Sun May 30, 2010 3:49 am

Re: Top scores page, how to efficiently?

Post 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
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Top scores page, how to efficiently?

Post 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.
The indelible lord of tl;dr
spawnfestis
Posts: 79
Joined: Fri Dec 04, 2009 3:19 am

Re: Top scores page, how to efficiently?

Post 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.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Top scores page, how to efficiently?

Post 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.
The indelible lord of tl;dr
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

Re: Top scores page, how to efficiently?

Post 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.
Fight Cycle : My latest Browser game WIP
Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Top scores page, how to efficiently?

Post 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 :)
The indelible lord of tl;dr
Post Reply

Return to “Coding”