Ruby on Rails Monday, September 15, 2014


On Sep 14, 2014, at 1:35 AM, Joe Crotchett <lists@ruby-forum.com> wrote:

I'm using Ruby on Rails to build a real-time game web app. When a player
taps "Play Now", I want to match them up with another player that is
looking for a game (match-making). With my basic understanding of RoR,
one immediate way I think I can do this is create a DB table that
contains the players that are looking for a game. When a new player
wants to play, I can just query the DB for the two most recent players
and connect them together, and remove them from the DB. But this doesn't
sound optimal since the list of players can potentially be large and the
query could be slow.

Did you test that hypothesis? With proper indexing on the field you are searching by there's no reason to think that the query should be slow, particularly if you put the LIMIT into the query. (Generally speaking, object instantiation in Rails is relatively slow, but the actual querying happens at the speed the database can handle it)



Are there more efficient ways to implement this kind of match-making in
RoR? Or a more efficient way to implement a persistent queue?



You could try Redis as a data store, but if I were you I'd just try it with a normal SQL query and fix your 'scale' issues when you can identify where the bottleneck is. 



No comments:

Post a Comment