[erlang-questions] How would you do it?
Erik Søe Sørensen
eriksoe@REDACTED
Mon Jul 2 23:52:39 CEST 2012
(forgot to Cc the list.)
---------- Videresendt besked ----------
Fra: "Erik Søe Sørensen" <eriksoe@REDACTED>
Dato: 02/07/2012 23.50
Emne: Re: [erlang-questions] How would you do it?
Til: "Max Bourinov" <bourinov@REDACTED>
I think I'd do this...:
0) Not include the profile info if the score messages unless it really does
change that often.
1) Keep two ets tables: one with player-id as key and current score as a
column (and possibly other columns, for profile info etc., but for this I'd
only fetch the score column).
2) And the other ets table would have {Score,PlayerID} as key. No other
columns needed for the tasks you mention.
3) The first table would be a normal set, the second a sorted set. This
means that player rows can be found and updated in constant time, and the
score table row updated in logarithmic time (using the old score from the
first table). Top 100, and neighbouring scores, can be found using ets
iterators, in log time.
The performance of this should be quite adequate. There is at least one
advantage of using ets tables over in-heap data structures for this, namely
that it keeps the heap size down, so there's less work for the GC.
Happy hacking, whichever approach you settle on.
/Erik
(Reminds me, I ought to add mention of two-table approaches to AGttES
soonish. It can be quite handy to have your data indexed in several ways.)
/Erik
Den 02/07/2012 12.30 skrev "Max Bourinov" <bourinov@REDACTED>:
> Hi Erlangers,
>
> I need to build a ranking system for online game.
>
> I think I will have a ranking gen_server that will accept cast messages
> like this: {score, Player :: profile(), Score :: integer()}.
>
> So, the question is what would be most appropriate data structure if:
>
> 1. I have to rank about 50 000 - 100 000 different players.
> 2. On each score message I have to re-sort whole ranking table.
> 3. It must be very cheap to get:
> 1. top 100 players
> 2. player's rating +/- 10 players about current player
> 4. I expect about 20-50 score messages per seconds
> 5. Size of score message is about 4KB (profile takes most of the
> space).
>
>
> Any ideas or suggestions are welcome!
>
> Best regards,
> Max
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120702/6a816f9c/attachment.htm>
More information about the erlang-questions
mailing list