On Sep 14, 2014, at 1:35 AM, Joe Crotchett <li...@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. 



-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/6BAB3C9D-4D7C-4798-870D-DCB5786329D8%40datatravels.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to