This weekend, huge numbers of people have been carrying out their Haj pilgrimage. But no matter how they travelled, they could be sure of one thing: being stuck in queues.
With the numbers travelling to Mecca increasing each year, and expected to top 1.8 million this year, airport and border officials are well-versed in dealing with this bane of long-distance travel. But they also know how even the slightest mishap can result in queueing chaos.
It's an apposite phrase, for even a single line of people is a manifestation of what mathematicians call a "non-linear phenomenon".
Queues have much in common with the weather in that they too can fall prey to the proverbial flap of a butterfly's wings.
This is just one of the insights that emerge from one of the lesser known but most useful branches of applied mathematics, queuing theory.
Its origins lie in a classic case of a simple problem with a solution that proved anything but: how to best design a telephone exchange. In the early 20th century, a Danish engineer named Agner Erlang had to work out how many operators would be needed to handle incoming calls efficiently. This led him to discover the most basic paradox concerning queues. Imagine that calls arrive at an average of 10 a minute. How fast should operators deal with them to prevent a backlog of irate callers? The answer seems obvious: the team must also deal with them at an average rate of 10 a minute.
But Erlang's equations revealed this just isn't good enough. They showed that merely matching the rate guarantees ever-increasing numbers of irate callers waiting to be put through.
It's the same with people queuing at supermarket checkouts and border crossings: if the rate at which people are dealt with merely matches the rate at which they join the queue, the queue will get ever longer. To avoid this, operators, cashiers and immigration officials must process people faster than they arrive.
The explanation lies in that phrase "average rate". People (and phone calls) don't arrive like clockwork. They are subject to random effects, with sudden surges of arrivals followed by none at all.
Erlang captured this effect mathematically and showed the only way to avoid being caught out is for the average processing time to exceed the rate at which people turn up.
A simple point, but one with big implications. For example, it shows managers seeking "efficiencies" in service industries face a choice. They can cut staff dealing with those using the service and face ever-increasing numbers of dissatisfied clients, or they can keep the clients happy and tolerate the sight of staff standing around "doing nothing".
If clients turn up at random, as they have an annoying habit of doing in, say, hospital casualty wards, it's impossible to avoid both dissatisfaction and "overstaffing".
Queuing theory provides insights into other long-standing issues. As every woman knows, while equality may slowly be increasing in many aspects of life, there is one where it remains as distant as ever - the need to queue for the lavatory.
Yet as every architect will tell you, the provision of restrooms is usually at least as generous for women as it is for men. So why do the queues persist? Part of the answer comes from studies that confirm the suspicions of every man: women take their time.
Indeed, international studies (don't ask) show that women take about 1.5 minutes a visit, compared with just 40 seconds for men.
But queuing theory shows this doesn't mean women face queues 2.3 times longer. By a quirk of the mathematics, the length of a queue increases according to the square of the time - leading to queues more than five times longer.
At least the solution is obvious. Provide women with at least twice as many stalls as the men get. How long it will take architects to catch on to that, though, is anyone's guess.
One way around the mathematical implications of queuing theory is to use psychology. All queuing theorists have stories of how complaints were cured by giving people either entertainment or information while they wait. One such anecdote relates how the owners of a new skyscraper in America were faced with complaints about the slowness of the lifts. This seemed to demand an expensive refit until someone suggested fitting full-length mirrors next to the lifts.
The complaints evaporated almost immediately, as people passed the time preening themselves or watching others as they waited for the same slow lifts to arrive.
Designers of theme parks have found it can actually be beneficial to keep people queuing. Research has shown visitors give higher ratings to rides they have to wait for than ones they can simply walk straight on to.
It seems the anticipation of taking the ride, and seeing it in action while you queue, builds excitement in a way instant gratification cannot.
But sometimes the answer to frustration lies in our own hands. Take, perhaps, the most notorious of all its manifestations - choosing one of several queues for the supermarket checkout, only to find the one next door is surging ahead.
As ever, the source of the trouble lies with randomness. After making our choice, there are three queues we care about: the one we're in, plus our two neighbouring queues.
Even if all the queues have the same risk of random delay, the chances that on any particular occasion we've chosen the fastest is just one in three. About 66 per cent of the time, one or other of those neighbouring queues will beat ours.
The solution? Relax. In the end it all evens out and everyone has their fair share of queuing success.
Robert Matthews is visiting reader in Science at Aston University, Birmingham, England