First, Assuming a scene like this:
{ Queue1: [taskA1, taskA2, taskA3, ... ] }
{ Queue2: [taskB1, taskB2, ... ] }
...
{ QueueN: [taskN1, ... ] }
These queues contains varies number of tasks, where tasks are dynamically pushed.
Secondly, we have a list of users:
[ user1, user2, user3, ... ]
Different users have different permission for queues, for example:
{ user1: { Queue1, Queue2, ... } }
{ user2: { Queue1 } }
{ ... }
Thirdly, There are conditions:
- Queues will have priority, it means Queue1's task must be done before Queue2's task.
- Some queues may be empty since there is no tasks currently
- Priority Queue is not available, because every user wants as much tasks as he can
- System memory and System performance can be considered ample enough, and we use Gemfire
- So multi-threads are not available
- Thousands of Users, Hundreds of Queues
This is a real problem we met, when our system first went online, fetching a task takes no more than 50ms. But with the users and queues grows, system response time has increased to hundreds of milliseconds. We tried to optimize with BitSet, but only 50% of performance was improved.
So maybe StackOverflow will have the ultimate answer.