Could we attach the weights to the queue to minimize the work done in the scheduling loop?
I agree that we want to minimize instructions in the scheduler. However, the getWeight method only does a null check and potentially a hashmap lookup. If we were to attach weights to the queue, say make the queue have a Pair<String, Integer> key instead of just a String key, that might cause a lot more objects (Pairs and Integers) to be created. Also, it would still have to call getWeight. It would just call it in the queue(...) method instead of in the schedule() loop. So getWeight would still be called the same number of times - once per request thread.
In the innermost loop, you should probably break the weighted loop if the thread popped is ever null
true - will add that.
The changes in ClientState are not necessary for this patch
They're not necessary for this patch, but it cleans up that method and removes the necessity for SCHEDULE_ON_KEYSPACE by just doing a switch over the values in that enum. Changing the name to SchedulingValue just seemed more intuitive to me as I had been confusing schedulerId and schedulingId. It helped me get them straight more easily - maybe that's just me.