A Simple yet Exact Analysis of the MultiQueue
Abstract
The MultiQueue is a relaxed concurrent priority queue consisting of internal priority queues, where an insertion uses a random queue and a deletion considers two random queues and deletes the minimum from the one with the smaller minimum. The rank error of the deletion is the number of smaller elements in the MultiQueue.
Alistarh et al. [2] have demonstrated in a sophisticated potential argument that the expected rank error remains bounded by over long sequences of deletions.
In this paper we present a simpler analysis by identifying the stable distribution of an underlying Markov chain and with it the long-term distribution of the rank error exactly. Simple calculations then reveal the expected long-term rank error to be . Our arguments generalize to deletion schemes where the probability to delete from a given queue depends only on the rank of the queue. Specifically, this includes deleting from the best of randomly selected queues for any .
Keywords and phrases:
MultiQueue, concurrent data structure, stochastic process, Markov chainCopyright and License:
2012 ACM Subject Classification:
Mathematics of computing Stochastic processes ; Theory of computation Data structures design and analysisFunding:
††margin:
This project has received funding from the European Research Council (ERC) under the European Union’s Horizon 2020 research and innovation program (grant agreement No. 882 500).
Editors:
Anne Benoit, Haim Kaplan, Sebastian Wild, and Grzegorz HermanSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl – Leibniz-Zentrum für Informatik
1 Introduction
Priority queues maintain a set of elements from a totally ordered domain, with an insert operation adding an element and a deleteMin operation extracting the smallest element. They are a fundamental building block for a wide range of applications such as task scheduling, graph algorithms, and discrete event simulation. The parallel nature of modern computing hardware motivates the design of concurrent priority queues that allow multiple processing elements to insert and delete elements concurrently. Strict111in the sense of linearizability concurrent priority queues (e.g., [19, 11, 7, 17]) suffer from poor scalability due to inherent contention on the smallest element [4, 8]. To alleviate this contention, in relaxed priority queues deletions should still preferentially extract small elements but need not always extract the minimum. In other words, the correctness requirement is turned into a quality measure: We speak of a rank error of if the extracted element has rank among all elements currently in the priority queue. In many scenarios, relaxed priority queues outperform strict priority queues, as the higher scalability outweighs the additional work caused by the relaxation. They are an active field of research and a vast range of designs has been proposed [10, 16, 22, 3, 18, 21, 15, 23].
The MultiQueue.
The MultiQueue, initially proposed by Rihani et al. [16] and improved upon by Williams et al. [21], emerged as the state-of-the art relaxed priority queue. Due to its high scalability and robust quality, the MultiQueue inspired a number of follow-up works [15, 23]. Its design uses the power-of-two-choices paradigm and is delightfully simple: We use (sequential) priority queues for some fixed . Each insertion adds its element to a queue chosen uniformly at random and each deletion picks two queues uniformly at random and deletes from the one with the smaller minimum.
Figure 1 illustrates the MultiQueue with queues. We can generalize this design to pick any number of queues for deletions where even non-integer choices of make sense: We would then pick queues with probability and queues otherwise. In practice, the individual queues are protected by mutual exclusion locks, and is proportional to the number of processing elements to find unlocked queues in (expected) constant time.
Existing theory on the MultiQueue.
Our theoretical understanding of the MultiQueue is still incomplete. One obstacle is that the order of operations matters: Intuitively, deletions can cause the distribution of elements to drift apart and increase the expected rank error, while insertions of small elements can mask accumulated differences. This suggests that the worst-case setting is when following the insertion of sufficiently many elements, only deletions occur. Like Alistarh et al. [2], we exclusively consider this setting. At first glance, this process seems closely related to the classical balls-into-bins process, where balls are placed one after the other into the least loaded of two randomly chosen bins. Famously, the difference between the highest load and the average load for bins is in with high probability for any number of balls. Numerous variants of the balls-into-bins process have been proposed and studied [5, 12, 6, 14]. However, reducing the process to a balls-into-bins process imposes multiple difficulties. The state of the MultiQueue is not fully described by the number of elements in each queue but also involves information about the ranks of the elements. Moreover, deleting an element from a queue can affect the ranks of elements in other queues. Despite these challenges, Alistarh et al. [2] managed to transfer the potential argument from the balls-into-bins analysis by Peres et al. [14] to a MultiQueue analysis via an intermediate “exponential process” that avoids correlations between the elements in the queues. They prove that the expected rank error is in and the expected worst-case rank error is in for any number of deletions and any , while the rank errors diverge with the number of deletions for . In follow-up work, this technique is generalized to other relaxed concurrent data structures [1] and a process where each processing element has its own priority queue and “steals” elements from other processing elements with some probability [15].
Contribution.
In this paper, we present an analysis of the MultiQueue that, compared to the potential argument by Alistarh et al. [2], is simultaneously simpler and more precise. We characterise the exact long-term distribution of the rank error for any and any . From this distribution we can derive, for instance, that the expected rank error for is . In addition to covering any , our analysis generalizes to all deletion schemes where the probability for a queue to be selected solely depends on the rank of the queue (when ordering the queues according to their smallest element).
We achieve this by modelling the deletion process as a Markov chain and observing that its stationary distribution can be described using a sequence of independent geometrically distributed random variables. In the full version of this paper [20] we also apply our techniques to the elegant exponential process by Alistarh et al. [2], which we believe to be of independent interest.
Outline.
First, in Section 2, we introduce the formal model of a generalized MultiQueue and the setting in which we analyze it. We then state our main results, including Theorem 1 that characterizes the long-term distribution of the ranks of the top-elements in the MultiQueue. In Section 3, we present our analysis of the generalized MultiQueue, leading to the proof of Theorem 1. We apply Theorem 1 to compute the expected rank error for any and any in Section 4. Finally, in Section 5, we discuss implications and limitations of our results and outline possible future work.
2 Formal Model and Results
Analogous to Alistarh et al. [2], we analyze the MultiQueue in a simplified setting where only deletions occur.
The -MultiQueue.
A -MultiQueue consists of priority queues and a choice distribution on that captures a generalised deletion strategy (as explained below). The queues are initially populated by randomly partitioning an infinite set of elements. 222Note that every queue receives an infinite number of elements with probability . The queues, identified with the sets of elements they contain, are denoted by , indexed such that . The minima are also called top-elements. We then perform a sequence of deletions. Each time, we select an index according to and delete the top-element of . 333We write as a shorthand for . Then, we relabel the queues such that their top-elements appear in ascending order again. Let be the sequence of queues after deletions and the rank of the top-element among , for any and .
Intuitively, should be biased towards smaller values of , i.e., towards selecting queues with smaller top-elements, to ensure that the rank error does not diverge over time. Using the notation and , the formal requirement for turns out as:
| () |
If does not satisfy , the MultiQueue deletes too frequently from “bad” queues (i.e., with large top-elements) and the gap between “good” and “bad” queues increases over time. We prove a corresponding formal claim in the full version of this paper [20].
Surprisingly independent random variables.
One might think that the ranks are correlated in complex ways. While they are correlated, they effectively arise as the prefix sum of independent random variables. More precisely, our main theorem draws attention to the differences between the ranks of consecutive top-elements.
Theorem 1 (Proof in Section 3).
Let denote the ranks of the top-elements of a -MultiQueue with satisfying after deletions. Then converges in distribution to a sequence of random variables where
where denotes the geometric distribution of the number of Bernoulli trials with success probability until (and including) the first success.
From the distribution of the ranks of the top-elements given by Theorem 1 it is straightforward to derive the rank error distribution.
Corollary 2 (Proof in Section 3).
Let denote the rank error exhibited by the deletion in step in the -MultiQueue with satisfying . Then converges in distribution to the random variable where
The expected rank error is (in the long run)
Application to the -MultiQueue.
For we define the -MultiQueue to be the -MultiQueue where is the distribution that corresponds to picking the best out of randomly selected queues as described in Section 1. For instance, the probability to select one of the first queues with is . Note that () is satisfied (see Lemma 8). We can then derive several useful quantities from Theorem 1, including the expected rank error.
Theorem 3.
Consider the expectation of the rank error of the -MultiQueue in the long run (i.e., after convergence).
-
(i)
For we have .
-
(ii)
For with , we have .
-
(iii)
For any we have ,
where is defined as follows using -
(iv)
Cruder but simpler bounds for any are:
The Exponential-Jump Process.
As an intermediate step in their analysis, Alistarh et al. [2] introduce the “exponential process”, where new top-elements are not given by the current state but generated by adding an exponential random variable to the current top-element. We reformulate this process as the equivalent exponential-jump process (EJP) as follows. The EJP involves tokens on the real number line and a distribution on . In every step, we sample and . We then identify the th token from the left and move it a distance of to the right. More formally, the state of the process is given by the sequence of positions of the tokens and the state transition can be described as
We provide an exact analysis, which we believe to be of independent interest, and explain the connection between the EJP and the MultiQueue in the full version of this paper [20]. With the same methods as before, we analyse the differences with .
Theorem 4.
Let and let be a distribution on that satisfies . The EJP admits a stationary distribution for the differences with
In other words, the distances between neighbouring tokens are, in the long-run, mutually independent and exponentially distributed with parameters as given.
3 A Direct Analysis of the -MultiQueue
When analysing random processes, it is often a good idea to reveal information only when needed, keeping the rest hidden behind a veil of probability. In our case, the idea is to conceal the queue an element is in until the element becomes a top-element.
We discuss this idea using the example in Figure 3 where queues are initially populated with the set .
In (a) we see an explicit representation of a possible state, where queues are labeled in increasing order of their top-elements. We can tell, for instance, that when removing the top-element of queue then the new top-element would be . In (b) we keep track of the current and past top-elements of all queues but do not reveal ahead of time which queue each element of is assigned to. As far as we know, the elements are assigned to each of the four queues with equal probability. It is unavoidable that we obtain partial information, however: If an element is smaller than the top-element of some queue, it cannot possibly be contained in that queue. The elements , and are in queue and with probability each, and the elements and are in queues , and with probability each. Element is surely contained in queue , but we can treat this as a degenerate probability distribution rather than as a special case. Note what happens when element is deleted: First, has a chance of of being the new top-element of queue . If it turns out that is not the new top-element, then gets the same chance, then . If all three elements are rejected, then element is considered, getting a chance of (because it could still be in three queues) and so on.
Since we are only interested in the ranks of top-elements over time, we can forget the removed elements and the concrete element values and arrive at representation (c), showing balls “ ” representing top-elements and dots “ ” representing other elements. Equivalently, in (d) we list the sequence of dot-counts in between the balls, omitting the infinite number of dots to the right of the last ball.
We now represent the -MultiQueue as a Markov chain with states in as in (d), borrowing language from (b) and (c) when useful. Since the state space is countably infinite, the role of the transition matrix is filled by an infinite family of transition probabilities where denotes the probability to transition from state to state . These probabilities are implicitly described below. We write for a state and denotes the th unit vector for . We avoid special cases related to the last ball by defining and .
A state transitions to another state via a sequence of transitional states in which one ball (numbered from left to right) is marked as the active ball.
-
1.
Given state , we sample and obtain the transitional state .
Interpretation: In terms of (c) we activate ball and in terms of (b) we delete the top-element from queue and look for a new one. -
2.
As long as we are in a transitional state , there are two cases:
-
2.1
If , then with probability we continue with transitional state and with probability the transition ends with state .
Interpretation: In terms of (c) the active ball decides to skip past the dot to the right of it, or consumes the dot and stops. In terms of (b), we reveal whether the next top-element candidate for is contained in ; if it is, the candidate becomes the new top-element and we stop, otherwise we continue the search. -
2.2
If , then we continue with transitional state .
Interpretation: In terms of (c) the active ball overtakes another ball, thereby becoming ball . In terms of (b), we update the ordering of the queues since the new top-element of is now known to be larger than the top-element of queue .
-
2.1
For clarity, we illustrate the possible transitions for a concrete state and resulting transition probabilities in Figure 4. We remark that the following analysis does not refer to the transition probabilities directly, but uses their implicit characterisation.
We now state the main result of this section, which characterizes a stationary distribution of . With this lemma, we can finally prove Theorem 1 and Corollary 2.
Theorem 5.
Let and let be a distribution on that satisfies . The transition probabilities admits the stationary distribution given by
where denotes the geometric distribution of the number of failed Bernoulli trials with success probability before the first success, and denotes the direct product of distributions.
In particular, the components of are independent random variables. We further make the following useful observation.
Observation 6.
For any and any we have .
Proof of Observation 6.
If then and so the claim is trivial. Now assume . For any we have
Hence, and the claim follows. The following auxiliary lemma captures the main insight required in the proof of Theorem 5.
Lemma 7.
Let be the probability that a transitional state occurs when transitioning from state according to with satisfying . Then,
Proof of Lemma 7.
We prove by induction. In the induction step we may assume that holds whenever or when and . In general, there are three ways in which a transitional state might be reached:
-
(i)
The transition started with and ball was activated.
-
(ii)
Ball has skipped a dot and we thus reached from .
-
(iii)
Ball has just overtaken another ball and we thus reached from .
For , consider a transitional state where the first ball is active. Here, only (i) is possible since the first ball never skips a dot (transition ends with probability in rule 2.1) and there is no ball to its left. The probability for to occur is thus
For , there are two cases depending on whether , i.e., whether there is a dot in between ball and ball . If , then only (i) and (ii) are possible, so
| (Induction) | ||||
| (6) | ||||
If , then only (i) and (iii) are possible, so
Proof of Theorem 5.
Given a state , we transition to a new state according to the transition probabilities . To end in , we first need to reach the transitional state for some and then decide to end the transition there. Note that we need rather than , since ending the transition (rule 2.1) reduces by one. The probability to end in is therefore
It follows that is again distributed according to and is a stationary distribution. Finally, we prove Theorem 1 and Corollary 2.
Proof of Theorem 1.
Let with . Then, is a Markov chain with transition probabilities . Since we can reach from any state and vice versa, the Markov chain is irreducible. The Markov chain is aperiodic since can transition into itself (if ball is activated and immediately stops). This implies that the stationary distribution that we found is unique and that converges in distribution to (see [13, Theorem 1.8.3]). Let with . Clearly, converges in the same way, except that the geometric random variables are shifted. By definition, we have so the claimed distributional limit of follows.
Proof of Corollary 2.
Theorem 1 states the ranks of the top-elements converge in distribution to . The distribution for follows from the fact that we select the queue to delete from according to and deleting an element with rank yields a rank error of . Using the fact that , we have for the expected rank error
4 Application to the -MultiQueue
In this section we apply our results on the general -MultiQueue to the -MultiQueue with . After checking in Lemma 8 that the corresponding satisfies , we proceed to compute expected rank errors (Theorem 3) and derive a concentration bound (Theorem 9). This involves straightforward (though mildly tedious) calculations.
Lemma 8.
In the -MultiQueue with we have
Proof.
Recall that we sample queues with probability and queues otherwise. We fail to select one of the first queues only if none of them were sampled. Hence for :
The inequality uses that we have , or , or both.
Proof of Theorem 3.
We have just checked in Lemma 8 that satisfies and computed . We can therefore specialise the formula for the expected rank error from Corollary 2 by plugging in and simplifying, which yields
| (cancel ) | ||||
| (substitute .) | ||||
| (using the definition of given above.) |
We are now ready to prove claim (i). Using that , we have
Similarly, we can prove (ii). First, we simplify for with :
We then get (omitting a simple calculation):
We now turn our attention to general again. Our goal is to approximate the sum by an integral. To bound the approximation error effectively, we will first show that is monotonic. For this let us examine the fractional term occurring in :
| (1) |
From (1) we can see that does not have a singularity at and by setting both functions are continuous on . We also see from (1) that is increasing in and decreasing in (recall that determines ). Because the other factor of is also increasing in and decreasing in , we conclude that as a whole is increasing in and decreasing in . This makes the upper and lower sums bounding the integral of particularly simple:
By rearranging we obtain (iii). We now turn to the cruder bound (iv). We begin with . In this case we have where for all . This gives:
Combining this with (iii) gives when . When we can use that is decreasing in and round conservatively to obtain the claimed result.
Theorem 9.
In the -MultiQueue444A similar analysis for is also possible., the highest rank error observed over a polynomial number of deletions is in with high probability.
Proof.
We will use a tail bound by Janson [9, Theorem 2.1] on the sum of geometrically distributed random variables from. It reads
where is a sum of geometrically distributed random variables (with possibly differing success probabilities), is the smallest success probability and .
We apply this bound to , which has the required form by Theorem 1. It is easy to check that and
Since the rank error clearly satisfies we have for large enough
By a union bound, the probability that we observe a rank error exceeding at some point during deletions is at most . For large enough , this probability is still small.
To give some intuition for how quickly the -MultiQueue converges to its stable state and for how close the observed ranks of top-elements are to their expectation we provide experimental data in Figure 5.
5 Future Work
While we have fully analyzed the long-term behavior of the MultiQueue in the deletion-only setting, there are still open questions in the general setting. Specifically, our methods are not directly applicable when insertions of arbitrary elements can happen after deletions. We conjecture that the deletion-only setting represents the worst-case in the sense that the expected rank error cannot be made worse even by adversarial insertions. On the flip side, we conjecture that the expected rank error is never better than before the first deletion. Our reasoning is as follows: Inserting sufficiently large elements does not affect deletions and is equivalent to inserting before deleting. When inserting many small elements, the state drifts towards the state where no deletions happened. In summary, we expect the state of the MultiQueue always to be “between” the insertion-only and the deletion-only setting, and that our analysis yields accurate predictions after sufficiently many deletions regardless of previous operations.
Our analysis applies directly to applications that do insert new elements after the first deletion, such as heap sort and simple batch job scheduling. A much broader range of applications, including Dijkstra’s algorithm and discrete-event simulations, process elements in monotonous fashion, meaning that the elements deleted from the priority queue are monotonically increasing. When using a MultiQueue, newly inserted elements are unlikely to become top-elements, and we expect the state of the MultiQueue to stay “close” to the deletion-only setting.
Williams et al. [21] proposed the delay as an additional quality metric and stickiness as a way to increase throughput. The delay of an element measures how many elements worse than are deleted while resides in the queue. Stickiness lets threads reuse the same queue for multiple consecutive operations. We believe that the delay can be analyzed directly with our approach and that the Markov chain can be adapted to handle stickiness as well.
In practice, it is relevant how fast the system stabilizes and converges to the postulated distributions of ranks or what rank errors are to be expected until then. Thus, analyzing the convergence speed is a natural next step.
Alistarh et al. [1] analyze the MultiQueue in concurrent settings where comparisons can become stale, meaning that after deciding which queue to delete from but before actually deleting from it, its top-element might change. We find it interesting whether our analysis can be adapted to this scenario as well.
References
- [1] Dan Alistarh, Trevor Brown, Justin Kopinsky, Jerry Z. Li, and Giorgi Nadiradze. Distributionally Linearizable Data Structures. In SPAA, 2018. doi:10.1145/3210377.3210411.
- [2] Dan Alistarh, Justin Kopinsky, Jerry Li, and Giorgi Nadiradze. The Power of Choice in Priority Scheduling. In PODC, 2017. doi:10.1145/3087801.3087810.
- [3] Dan Alistarh, Justin Kopinsky, Jerry Li, and Nir Shavit. The SprayList: A scalable relaxed priority queue. In PPoPP, 2015. doi:10.1145/2688500.2688523.
- [4] Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged M. Michael, and Martin Vechev. Laws of order: Expensive synchronization in concurrent algorithms cannot be eliminated. In POPL, 2011. doi:10.1145/1926385.1926442.
- [5] Yossi Azar, Andrei Z. Broder, Anna R. Karlin, and Eli Upfal. Balanced Allocations. SICOMP, 29(1), 1999. doi:10.1137/S0097539795288490.
- [6] Petra Berenbrink, Artur Czumaj, Angelika Steger, and Berthold Vöcking. Balanced Allocations: The Heavily Loaded Case. SICOMP, 35(6), 2006. doi:10.1137/S009753970444435X.
- [7] Irina Calciu, Hammurabi Mendes, and Maurice Herlihy. The Adaptive Priority Queue with Elimination and Combining. In DC, 2014. doi:10.1007/978-3-662-45174-8_28.
- [8] Faith Ellen, Danny Hendler, and Nir Shavit. On the Inherent Sequentiality of Concurrent Objects. SICOMP, 41(3), 2012. doi:10.1137/08072646X.
- [9] Svante Janson. Tail bounds for sums of geometric and exponential variables. S&P L, 135, 2018. doi:10.1016/j.spl.2017.11.017.
- [10] Richard M. Karp and Yanjun Zhang. Randomized parallel algorithms for backtrack search and branch-and-bound computation. JACM, 40(3), 1993. doi:10.1145/174130.174145.
- [11] Jonatan Lindén and Bengt Jonsson. A Skiplist-Based Concurrent Priority Queue with Minimal Memory Contention. In OPODIS, 2013. doi:10.1007/978-3-319-03850-6_15.
- [12] Michael Mitzenmacher, Andréa W. Richa, and Ramesh Sitaraman. The Power of Two Random Choices: A Survey of Techniques and Results, 2001. URL: http://www.eecs.harvard.edu/˜michaelm/postscripts/handbook2001.pdf.
- [13] J. R. Norris. Markov Chains. Cambridge Series in Statistical and Probabilistic Mathematics. Cambridge university press, 1997. doi:10.1017/CBO9780511810633.
- [14] Yuval Peres, Kunal Talwar, and Udi Wieder. Graphical balanced allocations and the (1 + )-choice process. RS & A, 47(4), 2015. doi:10.1002/rsa.20558.
- [15] Anastasiia Postnikova, Nikita Koval, Giorgi Nadiradze, and Dan Alistarh. Multi-queues can be state-of-the-art priority schedulers. In PPoPP, 2022. doi:10.1145/3503221.3508432.
- [16] Hamza Rihani, Peter Sanders, and Roman Dementiev. MultiQueues: Simple Relaxed Concurrent Priority Queues. In SPAA, 2015. doi:10.1145/2755573.2755616.
- [17] Adones Rukundo and Philippas Tsigas. TSLQueue: An Efficient Lock-Free Design for Priority Queues. In Euro-Par, 2021. doi:10.1007/978-3-030-85665-6_24.
- [18] Konstantinos Sagonas and Kjell Winblad. The Contention Avoiding Concurrent Priority Queue. In LCPC, 2017. doi:10.1007/978-3-319-52709-3_23.
- [19] N. Shavit and I. Lotan. Skiplist-based concurrent priority queues. In IPDPS, 2000. doi:10.1109/IPDPS.2000.845994.
- [20] Stefan Walzer and Marvin Williams. A Simple yet Exact Analysis of the MultiQueue, 2025. doi:10.48550/arXiv.2410.08714.
- [21] Marvin Williams, Peter Sanders, and Roman Dementiev. Engineering MultiQueues: Fast Relaxed Concurrent Priority Queues. In ESA, 2021. doi:10.4230/LIPIcs.ESA.2021.81.
- [22] Martin Wimmer, Jakob Gruber, Jesper Larsson Träff, and Philippas Tsigas. The lock-free k-LSM relaxed priority queue. In PPoPP, 2015. doi:10.1145/2688500.2688547.
- [23] Guozheng Zhang, Gilead Posluns, and Mark C. Jeffrey. Multi Bucket Queues: Efficient Concurrent Priority Scheduling. In SPAA, 2024. doi:10.1145/3626183.3659962.
