A short note on random load balancing

by Mateusz

Update: I’ve updated wording a little bit, as I did not express myself clearly when it came to distribution of balls into bins and few readers pointed it out. I have clarified the meaning, by explaining things by using number of balls. In the next post I will show how it is almost sure that we can have an empty bin when distributing balls with uniform distribution, which is not the property we want. The goal of this note was to educate the reader on a possibility of improving the distribution of balls into bins so that we have almost equal number of balls into bins.

The technique presented in this post is little known outside of academic circles but is really significant result in random allocations. Let’s say you have a problem of allocating balls into bins randomly, but you want the number of balls in bins to be distributed as evenly as possible. How would you do that?

Very frequently I see people picking a bin at random with a uniform probability distribution and dropping a ball there hoping that the balls would be distributed evenly. The problem is that this is not the case. Running a short program that does the allocations according to this scheme with 100 bins and 1000000 balls produces distributes the balls as in the picture below. Let’s look at that picture. The X-axis is a bin number, the Y-axis is the number of balls in it.

You can clearly see that the minimum ball count in one of the bins is just below 9700 and the maximum ball count is above 10200 for some bins (for the particular realization). The number of balls in each of the bins however varies a lot. Is there anything that can be done that could help solve the problem? Yes, there is. Instead of picking a single bin to throw the ball into, pick two bins at random and throw the ball into the one that is least filled. Let’s look at the distribution generated by this scheme.

You can now clearly see that the difference between the number of balls in bins is very small. Most of the bins have 10000 balls in them, the minimum number of balls in a bin for this particular realization of a random experiment is 9997 and the maximum number of balls in any bin for this particular realization is 10002. This is much closer to a uniform distribution than one would expect. I found this result very enlightening and significant.

Next time you perform random allocations think of the power of two random choices.