The scenario I'm facing is as follows:
Each user can click a button and enter a queue, called "waiting room". Once there are n users in this queue, this n users should be grouped together and ejected from this queue.
The implementation I have:
I used a non-persistent model
containing a ruby set to serve the purpose. user_id
can be added to the set. It works fine when users enter the queue in sequence.
The possible problem:
If the website is under heavy load such as 1000 (> n) users are entering the queue at the same time, I'm afraid bad things will happen (like some users get tied to multiple groups and ejected multiple times). I don't know if Rails has some internal mechanism to prevent this or it depends on the data structure of my choice. I want something like a event queue that web browsers have. That is, events can come in at the same time but only get handled one by one. How do I ensure that?
Testing:
How do I write RSpec tests to simulate the heavy load scenario?