It’s Juggling Time

If you lead a busy life, you should learn how to juggle. The physical activity is great for stress relief, but I also mean juggling in the sense of multitasking. Knowing how to efficiently allocate time between tasks is a valuable skill to have. We juggle jobs, tasks, family, and friends as if they were tangible things that we could throw and catch. Though just a figure of speech, delving into juggling as metaphor reveals some interesting ways to think about concurrent tasks.

Juggling, like music, is steeped in patterns that can be described using math. From siteswap to temporal logic, there are many ways to think about juggling patterns. One of the more obscure descriptions I wanted to explore is Shannon’s juggling theorem. I was first introduced to this formula when it was offhandedly mentioned during a weekly juggling session at the UW Juggling Club. The equation is as follows:

(F + D) H = (V + D) B

where

F = Flight time of a ball

D = Dwell time that a ball spends in a hand

V = Vacant time that a hand spends empty

B = Number of balls

H = Number of hands

Formulated by Claude Shannon, this equation describes how the collective time of the balls relates to the collective time of the hands. If we examine one juggling cycle (i.e. one iteration where every ball passes through each hand) and trace through said cycle from the hand and the ball perspective, we can derive the equation. Without the insight to watch just a ball or just a hand, it’s hard to decipher the relationship from merely watching someone juggle.

JugglingLoop
3 Ball Cascade

I could never fully grasp the equation by juggling until I started to imagine the time values as coloured bars of varying length. To show you what I see, I’ve coded up a visualizer to illustrate the timing of all the juggling events happening in the clip above.

3BallCascade

The diagram consists of three ball timelines and two hand timelines.

We can observe that the ball has two states: in a hand and in the air. On a ball timeline, the time a ball spends in a hand (D) is coloured and the time the ball is in the air (F) is left blank. As for the hands, we can observe that it also has two states: holding a ball and empty. When the hand is holding a ball (D), the timeline is coloured using the colour of the ball being held. The rest of the hand timeline is blank (V) meaning the hand is empty.

With this diagram, we can start to play around with the timing relationships. In one cycle, we can see that a ball is thrown and caught once by each hand (i.e. “(F + D) H” meaning a ball trip happens H times) and a hand throws and catches each ball once (i.e. “(V + D) B” meaning a hand trip happens B times). The coloured area in all the ball timelines is equivalent to the coloured area in all the hand timelines because the time a ball spends in a hand is the same as the time a hand spends holding a ball. As we play with this equation, we can see how various aspects of the juggling pattern are temporally related.

3BallCascadeLongFlight

If we start throwing the balls higher, the coloured portions of the ball timeline will proportionally shrink as the ball spends more time in the air and, consequently, the hands will spend more time empty.

5BallCascade

If we add two more balls, we will see flight times increase because the balls will be thrown higher. On the other hand, there will be less vacant time as the juggler gets busy trying to accommodate the new balls.

This is a neat observation that does not have any practical value, but it is an interesting way to think about juggling. Coincidentally, I learned about Shannon’s juggling theorem around the same time I was attending lectures on concurrent programming. I developed a hunch that juggling and concurrency were related, but didn’t explore the relationship much. It wasn’t until a few semesters later that I was reminded of the topic during a lecture on computer systems performance analysis. The arithmetic used in the lecture felt somewhat similar to the juggling formula so I decided to revisit it.

Let’s reframe the equation I described in terms of computation.

3ThreadCascade

Let’s say there are three threads and two processors.

For simplicity, we can observe that the thread has two states: processing and suspended. On a thread timeline, the time a thread spends in a processor is coloured in and the time a thread is suspended is left blank.

As for the processors, we can observe that it also has two states: processing and idle. When it is processing a thread, I have coloured in the timeline using the colour of the thread it identifies. The rest of the processor timeline is blank meaning the processor is not processing a thread.

The coloured area of all the thread timelines is equivalent to the coloured area of all the processor timelines because the time a thread spends in execution is the same as the time a processor spends processing it.

The concepts map onto this problem domain nicely. You could also apply the math on other scenarios involving two interacting parties. Let’s say there is a group of patients at a hospital that need to go through a fixed set of medical examinations. If you reframe patients as balls and examination rooms as hands, you can start to apply the same intuition to it. However, the equation wouldn’t exactly work in this case because of some assumptions we have made.

Shannon’s Juggling Theorem is a succinct equation because it is meant to describe a cascade pattern where every ball cycles through each hand. It assumes that there is at most one ball in a hand at any given time. The equation does not account for multiplexing where multiple balls are thrown and caught at the same time. Additionally, if we changed the pattern so that some balls are thrown higher than others, then the ball trips would not have a uniform length. Simply multiplying by the number of trips would instead become a sum of all the trip times. Even though the equation requires throws of equal height (i.e. round-robin scheduling) to work, the intuition behind it still holds in the case there balls are thrown different heights.

Hypothetical31Timeline

You could generalize this intuition to any two sided system where each side has a set amount of time interacting and not interacting. This works because of double-counting  the set of time from each perspective and equating the two sides. It makes sense when you start manipulating the variables at the aggregate level. For example, if you add more patients to the hospital scenario above while holding the number of examination rooms the same, you will increase the aggregate wait time of the patients. This increase is especially apparent if you view the system from patients’ perspective.

My takeaway from Shannon’s insight is to think in the other perspective. Given what you know about your side of the equation, you might be able to imagine what it’s like on the other side of the system. Whether you’re figuring out multitasking with processors or multitasking with daily life, I recommend thinking not just in terms of the juggler, but also the juggled. Think not only of your schedule, but that of others. Hopefully, this perspective will help you navigate the juggling patterns of life. After all, life is a juggling act.

Additional Reading:

The Science Of Juggling
Peter J. Beek and Arthur Lewbel in Scientific American, Vol. 18, Issue 4, pages 92-97; November 1995.

The Operational Analysis of Queueing Network Models
Peter J. Denning and Jeffrey P. Buzen in ACM Computing Surveys, Vol. 10, Issue 3, pages 225-261; September 1978.