Trending
Opinion: How will Project 2025 impact game developers?
The Heritage Foundation's manifesto for the possible next administration could do great harm to many, including large portions of the game development community.
In this reprinted <a href="http://altdevblogaday.com/">#altdevblogaday</a> in-depth piece, Agora Games' lead engineer David Czarnecki looks at how you can improve your leaderboard's performance when ranking members in bulk.
June 13, 2012
[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.]
You May Also Like