informa
/
3 MIN READ
News

In-depth: The Costco-ification of leaderboards

In this reprinted #altdevblogaday in-depth piece, Agora Games' lead engineer David Czarnecki looks at how you can improve your leaderboard's performance when ranking members in bulk.
[In this reprinted #altdevblogaday in-depth piece, Agora Games' lead engineer David Czarnecki looks at how you can improve your leaderboard's performance when ranking members in bulk.] It's beneficial, sometimes, to buy in bulk. Or in this case, to rank in bulk. I'll take a look at a recent improvement to our open source leaderboard library to show significant improvement when doing a bulk insert operation for ranking members in a leaderboard. Costco and you Let's face it, we've all been walking through Costco or Sam's Club at one point and we've thought to ourselves, "I do need a pallet of chocolate covered pretzels." or "We could use a drum of grape jam at home." Regardless of whether or not these are valid units of measurement, the time it takes to purchase an item in bulk is less than the time it takes to purchase the items individually when you know you're going to need the bulk amount. So let's explore this idea with leaderboards. Let's look at the performance of ranking 1 million members in a leaderboard.
insert_time = Benchmark.measure do
  1.upto(1000000) do |index|
    highscore_lb.rank_member("member_#{index}", index)
  end
end
=> 29.340000 15.050000 44.390000 ( 81.673507)
81 seconds isn't bad, but can we do better? What if a catastrophic failure forces us to rebuild our leaderboards from scratch? Every second counts right? Let's rank the same 1 million members in the leaderboard all at once.
member_data = []
 => []
1.upto(1000000) do |index|
  member_data << "member_#{index}"
  member_data << index
end
 => 1
insert_time = Benchmark.measure do
  highscore_lb.rank_members(member_data)
end
 =>  22.390000   6.380000  28.770000 ( 31.144027)
31 seconds! As it turns out, "buying in bulk" really paid off. It helps to understand your underlying data store, in this case Redis, to know when it can handle bulk operations to your advantage. If we were to compare the time it'd take to rank, say 10 million members in a leaderboard, we'd be looking at almost 14 minutes (ranking individually) vs. 5 minutes (ranking in bulk). Fin As shown in this post, bulk operations can significantly impact the performance of your systems if the underlying data store can optimize those bulk operations. So don't worry about that desk of Cheez-Its you just purchased. You're worth it! [This piece was reprinted from #AltDevBlogADay, a shared blog initiative started by @mike_acton devoted to giving game developers of all disciplines a place to motivate each other to write regularly about their personal game development passions.]

Latest Jobs

Treyarch

Playa Vista, Los Angeles, CA, USA
9.12.23
Senior Level Designer (Zombies)

PlayStation Studios Creative Arts

Petaling Jaya, Selangor, Malaysia
9.14.23
Lead Concept Artist

High Moon Studios

Carlsbad, CA, USA
9.20.23
Technical Designer at High Moon Studios

High Moon Studios

Carlsbad, CA, USA
9.18.23
VFX Artist
More Jobs   

CONNECT WITH US

Explore the
Advertise with
Follow us

Game Developer Job Board

Game Developer

@gamedevdotcom

Explore the

Game Developer Job Board

Browse open positions across the game industry or recruit new talent for your studio

Browse
Advertise with

Game Developer

Engage game professionals and drive sales using an array of Game Developer media solutions to meet your objectives.

Learn More
Follow us

@gamedevdotcom

Follow us @gamedevdotcom to stay up-to-date with the latest news & insider information about events & more