How I did the rating system for LMSSPLUS with hundreds of millions of documents

Tram Ho

I make a web site LmssPlus that allows to look up League game personal information, there is a very sweet part (for me) that the player wants to know how much proficiency score they are using is in the whole VN server. .

Let me explain a little to those of you who don’t play League. In general, you will have many different generals to choose from a total of 150 generals, but people instead of playing all 150 generals, they usually only play about a dozen, and up to about 30 generals is a lot. . Each time you play that hero, you will gain more proficiency points.

So the needs of users here:

  • They want to know how much proficient General X they play in the server.
  • They wanted to know the top players who were most proficient at General X’s server.

My first thought was quite simple, I used Mongodb, first the model

  • Index {accountId: 1, championId: 1} to upsert data (when the user changes proficiency score).
  • Index {championId: 1, point: 1} to get rank.

The rank query looks like this:

So championId’s rank is simply the result above plus 1.

We need to take the rankings of all their champions to play, and then display the highest ranked champion, like I am the top 731 Katarina.

So the query would look like this:

For each user who enters, we take about 10-30 queries, the result rate is about 300-500ms, the result of our server is in this situation:

Data will be updated day and night (there is a cron in charge of getting information and updating into db) and when the user goes to the web (for the latest data)

Hmm, after reading a few more blogs, I decided to use Redis with its super-fast advantages, and the amount of ram used is only equivalent to mongodb (1)

First, I write a function to bring data from mongodb to redis, on the mongodb side, I remove the ssranks collection to save ssranks ram on the index, instead the hero data will be saved to 1 field champions in the collection accounts .

Key will be cp_id_id, score will be the proficiency score, and the value be accountId

And results

  • 30ms speed
  • Cpu reduced, stable at 5%

Above is what I do, my understanding is limited, so there are any mistakes I hope you to forgive. Thanks!

Ref:

Share the news now

Source : Viblo