Performing Load Balancing under Constraints

Andrea Fox<fnref n="1" />, Francesco De Pellegrini<fnref n="1" />, Eitan Altman², Arnob Ghosh³, and Ness Shroff⁴

**Abstract**—Join-the-shortest queue (JSQ) and its variants have often been used in solving load balancing problems. The aim of such policies is to minimize the average system occupation, e.g., the customer's system time. In this work we extend the traditional load balancing setting to include constraints that may be imposed, e.g., due to the communication network. We cast the problem into the framework of constrained MDPs, enabling the consideration of both action-dependent constraints, such as, e.g., bandwidth limitation, and state-dependent constraints, such as, e.g., minimum queue utilization. Unlike the state-of-the-art approaches, our load-balancing policies, in particular JSED-*k* and JSSQ, are both provably safe and yet strive to minimize the system occupancy. Their performance is tested with extensive numerical results under various system settings.

***Index Terms***—load balancing, constrained MDP, safe policies

# I. INTRODUCTION

Load balancing is a common strategy for task assignment in distributed architectures, including web services [1], distributed caching systems [2], and cloud computing [3]. In these systems, a job dispatcher seeks to distribute incoming jobs across servers as they enter the system, aiming to minimize the customers' queueing delays.

The performance of a load balancing system largely depends on the policy employed. A markovian policy, as those studied in this paper, decides the queue where to dispatch an incoming arrival depending on the current system state. In the literature on queueing theory, several works have tackled this problem using different approaches, including [4], [5], [6].

Despite the extensive body of research traditionally covered in the literature on load balancing, to the best of the authors' knowledge, the problem has not been studied so far in constrained systems. Indeed, many real-world applications could benefit from addressing this facet of the problem. Hence, in this paper our objective is to design new policies able to provide solutions for constrained load balancing, i.e., safe load-balancing policies. In particular, we restrict to two scenarios for constrained load balancing and define the related constraints accordingly.

The first type of constraint is a communication one. Jobs are uniform in their resource demand: each job may be different in service time, but it consumes a fixed fraction of resources, i.e., of the available channel capacity. Such type of constraint may represent, e.g., the finite capacity of the control channel connecting a load balancer and its servers. Violating such constraints can lead to higher latency and packet loss [7]. Similarly, in IoT systems, exceeding the access bandwidth

could disrupt communication and task allocation when executing jobs offloaded to edge servers. Also, in content delivery networks, multiple users request different video streams and each stream consumes an average fixed portion of the available bandwidth, as done e.g., in video streaming rate control [8] and virtual reality applications [9].

The second type of constraint we consider is meant to ensure a minimum level of activity on each queue to prevent underutilization, particularly in low-traffic scenarios. In practice, the high operational costs of maintaining physical resources like, for instance, machines and facilities in a datacenter, impose to avoid idle servers [10]. This becomes particularly critical in systems subject to rapid traffic load fluctuations. In fact, dynamic server provisioning is usually unable to effectively respond to small-time-scale traffic variations due to the substantial time delay introduced by powering servers on and off.

In this work, we propose a Constrained Markov Decision Process (CMPD) framework to address the problem of constrained load balancing. The model can incorporate the types of constraints described before and it can be applied flexibly to different systems. We also describe the structure of a policy that serves as a close approximation of the optimal solution, although we believe it remains impractical for real-world applications due to its computational complexity. Finally, we study new lightweight policies which are provably safe.

Specifically, the first policy, namely JSVED, relies on virtual queues to model the link capacity constraints and attains a conservative and yet safe solution. The second policy, namely JSED-*k*, maintains a memory of the last *k* actions to assess the satisfaction of the constraints. The numerical results demonstrate that JSED-*k* performs well under lighter traffic conditions but may become impractical in heavier traffic scenarios. For this reason, we propose a third alternative policy, namely JSSQ, which is determined by solving first a convex nonlinear problem related to the CMDP, whose solution provides a vector of feasible arrival rates at each server. This overcomes scalability issues at the price of larger system occupation and provably satisfies the constraints.

The paper is structured as follows. Section II introduces our reference model. Section III describes key properties of the optimal policy and presents a near-optimal approach via the Lyapunov-drift method. Section IV discusses new lightweight approximation policies that satisfy the constraints, while Section V addresses the problem using a generic gain function based on the occupancy of each queue. Section VII reviews related works in the literature. Simulation results are presented in Section VI. A final section concludes the paper.

<footnote n="1">¹LIA, Avignon university, Avignon, France; ²INRIA, Sophia Antipolis, France; ³New Jersey Institute of Technology, Newark, NJ, USA; ⁴The Ohio State University, Columbus, OH, USA;</footnote>
<table><caption>**Table I:** Main model notation.</caption><thead><tr><th>Symbol</th><th>Meaning</th></tr></thead><tbody><tr><td>N</td><td>number of queues</td></tr><tr><td>M</td><td>number of constrained queues constrained</td></tr><tr><td>Ξ</td><td>arrival rate of the system</td></tr><tr><td>ξ<sub>i</sub></td><td>arrival rate of queue i</td></tr><tr><td>μ<sub>i</sub></td><td>service rate of queue i</td></tr><tr><td>θ<sub>i</sub></td><td>constraint for queue i</td></tr><tr><td>μ'<sub>i</sub></td><td>capacity of virtual queue i – link capacity constraints. (μ'<sub>i</sub> = min(μ<sub>i</sub>, θ<sub>i</sub>))</td></tr></tbody></table>

## II. SYSTEM MODEL

We consider a system of $N$ parallel servers or queues as depicted in fig. 1. Server $1 \le i \le N$ has an exponential service time with known rate $\mu_i$, and all service times are independent. Clients arrive according to a Poisson process of intensity $\Xi$ and a load balancer immediately dispatches each customer to a given server.

Throughout this work, uppercase notation (e.g., $S$) represents a random process, while lowercase notation (e.g., $s$) refers to its realization. We consider the uniformization of the continuous-time process, resulting in the discrete-time Markov Decision Process (MDP) $M = (S, A, P)$ [11]. The state space $S$, action set $A$, and transition probabilities are defined hereafter.

The state space $S$ consists of nonnegative integer vectors $s = (s_1, \dots, s_N)$, where $S_t = s$ represents the system state at time $t$. Here, $s_i$ denotes the occupation of server $i$ for $i = 1, \dots, N$. It is important to observe that sampling the queues occupation may becomes increasingly challenging as the number of queues grows. In this work, we assume that the associated overhead remains manageable, even under heavy-traffic conditions. Methods that address this issue in the context of unconstrained load balancing have been explored in [12], [13], [14], [15]. Extending these approaches to constrained load balancing scenarios is left for future work.

The action set $A = \{1, 2, \dots, N\}$ specifies the server a client is dispatched to: $A_t = i$ indicates that the client arriving at time $t$ is assigned to server $i$. Define the transition probabilities $p(s'|s, i) := P(S_{t+1} = s'|S_t = s, A_t = i)$ and let $\hat{p}(u; s_j)$ denote the probability that $u$ customers of server $j$ leave in between two arrivals, given $s_j$ customers are present at the beginning of the inter-arrival interval.

$$ \hat{p}(u; s_j) = \Xi \int_0^\infty \binom{s_j}{u} e^{-\mu_j t(s_j-u)} (1 - e^{-\mu_j t})^u e^{-\Xi t} dt $$

for $0 \le u \le s_j$ and zero otherwise. Hence, the transition probabilities can be written as

$$ p(s'|s, i) = \hat{p}(s_i - s'_i + 1; s_i) \prod_{j \neq i} \hat{p}(s_j - s'_j; s_j) \quad (1) $$

With standard notation, $R_{t+1}$ is the reward attained after the action taken at time $t$ and $r(s, i) = E[R_{t+1}|S_t = s, A_t = i]$. We define the immediate reward at time $t$ as the time to serve all the customers currently in service, so that

$$ r(s, i) = \frac{s_i + 1}{\mu_i} + \sum_{j \neq i} \frac{s_j}{\mu_j} \quad (2) $$

<figure><img src="image_1.png" /><figcaption>**Figure 1:** Load balancing for a parallel of $N$ queues with access constraint.</figcaption></figure>

We consider the set of randomized stationary policies $\Pi$, where policy $\pi$ is a probability distribution over the state-action space set. In an unconstrained setting, the admission control problem can be written as

$$ \underset{\pi \in \Pi}{\text{minimize:}} \quad \mathbb{E}_{\pi, s_0} \left[ \lim_{T \to \infty} \frac{1}{T} \sum_{t=0}^{T} r(S_t, \pi(S_t)) \right] $$

for an initial state $s_0$. For every stationary deterministic policy, the resulting Markov chain is regular, meaning it has no transient states and a single recurrent acyclic class. We define the value function

$$ v_{\pi}(s) = \lim_{T \to \infty} \frac{1}{T} \sum_{t=0}^{T} \mathbb{E}_{\pi} [r(S_t, A_t) | S_0 = s] $$

Finally, the average reward is taken w.r.t. the initial state distribution $\beta: S \to \Delta$ [16]

$$ J_{\pi}(\beta) = \mathbb{E}_{S \sim \beta} [v_{\pi}(S)] \quad (3) $$

Next, we introduce the CMDP formulation to account for the constraints on the queue access capacity.

### A. The CMDP model

For now, we focus on the case where the constraint represents the channel capacity constraints, e.g., the capacity of the link connecting each server to the central dispatcher. The second case of constraint, involving a gain function dependent on the occupation of each server will be analyzed in Section V. The constraint will be represented by the vector $\theta \in \mathbb{R}^M$ and can be interpreted as the fraction of the arrivals that can be routed towards each constrained queue. The instantaneous cost $c_i: S \times A \to \mathbb{R}$ related to the access to queue $i$ is independent of the state of the queue and it is defined as:

$$ c_j(s, i) = \mathbb{1}\{j = i\} \quad (4) $$

The vector $K_{\pi}(\beta) = (K_{\pi}^1(\beta), \dots, K_{\pi}^N(\beta))$ represents the average cumulative constraint:

$$ K_{\pi}^{i}(\beta) = \mathbb{E}_{\pi, s \sim \beta} \left[ \lim_{T \to \infty} \frac{1}{T} \sum_{t=0}^{T} c_i(S_t, A_t) | S(0) = s \right] \quad (5) $$
For a fixed access capacity vector $\theta = (\theta_1, \dots, \theta_N)$, and a feasible initial state distribution $\beta$, we seek an optimal policy solving the constrained load balancing control (CLBC) problem

$$ \begin{array}{ll} \underset{\pi \in \Pi}{\text{minimize:}} & J_{\pi}(\beta) \\ \text{subject to:} & K_{\pi}(\beta) \le \theta \end{array} \qquad (6) $$

We let $J^*(\beta)$ denote the corresponding optimal value.

Throughout the paper, we assume that queues $1, \dots, M$ (M could be equal to N) are those constrained by their link capacities, while the remaining $N-M$ queues have no link capacity constraint.

### B. Condition for the stability of the system

In the absence of constraints, if $\Xi < \sum_i \mu_i$, then there is a policy that stabilizes the system, that is, such that $\sum_{s \in S} \Xi\pi(i|s)\rho(s) < \mu_i$ for all $i$; for example, the trivial constant policy $\pi(i|.) = \min\{\mu_i, \sum_j \frac{\mu_j}{\mu_i}\}$ does so.

Under the presence of constraints, we define an equivalent Markov Decision Process (MDP) by modifying the service rates $\mu_i$. Specifically, for the constrained queues $(1, \dots, M)$, the service rates are adjusted to $\mu'_i = \min\{\Xi\theta_i, \mu_i\}$, while for the remaining queues, the service rates remain unchanged, i.e., $\mu'_i = \mu_i$. In this formulation, $\mu'_i$ for the constrained queues represents the maximum arrival rate that the link can handle under the given constraints. Notably, for these queues, $\mu'_i$ is smaller than their original processing capacity $\mu_i$, reflecting the imposed limitations. In this context, we have actual queues replaced by virtual ones. Stability holds if $\Xi < \sum_i \mu'_i$. To stabilize the system under these constraints, we can construct a policy that allocates arrivals proportionally to the modified capacities. This ensures that the system operates within the constraints while maintaining stability.

### III. OPTIMAL POLICY PROPERTIES

The optimal policy in the unconstrained case for a setting with homogeneous servers is Join the Shortest Queue (JSQ). Following intuition, this policy assigns each new arrival to the queue with the shortest current length. The optimality of JSQ was first established in [4].

In this work, however, we focus on the case of heterogeneous queues, where servers may have different processing speeds. In the unconstrained case, the optimal policy is JSED (Join the Shortest Expected Delay), that generalizes JSQ by routing arrivals to the queue with the smallest expected response time. The asymptotic optimality of JSED under heavy-traffic conditions was proved in [17], [18].

Let $s_i$ denotes the current number of jobs in queue $i$, and $\mu_i$ represent the processing speed of the $i$-th server. JSED's action is chosen at each time step according to the rule

$$ \pi_{\text{JSED}}(s) = \underset{i}{\operatorname{argmin}} \left\{ \frac{s_i}{\mu_i} \right\} \qquad (7) $$

Both JSQ and JSED are Markovian policies, which act based on the system state, i.e., the system occupation. Since

the problem studied in this work is the optimization of a constrained problem, it is natural to resort to CMDP models. From the theory of CMDPs, see Thm 4.4 in [16], an optimal policy is stochastic in at most M states and deterministic in all the others. As proved in Theorem 12.7 in [16], the solution of (CLBC) is equivalent to the solution of a MDP whose reward function is

$$ J_{eq}^{\lambda}(\beta, \pi) = J_{\pi}(\beta) + \langle \lambda, K_{\pi}(\beta) - \theta \rangle $$

Let us fix the value of the Lagrange multiplier $\lambda$: we can study a new MDP where the immediate reward writes

$$ r(s, a) = \sum_{i=1}^{N} \frac{s_i}{\mu_i} + \delta_i(a)\lambda_i \qquad (8) $$

where $\delta_i(\cdot)$ is the indicating function having value equal to one when the argument is $i$ and 0 otherwise. This leads to a relaxed problem where the objective is to minimize the average reward using the instantaneous penalized reward defined in (8).

We leave the study of the structure of optimal policis of the CMDLDP for future works. For the moment, we address a method which combines a Lyapunov drift-plus-penalty optimization technique and a Lagrangian approach to design a policy that stabilizes the system while attempting to minimize the time-average network occupancy.

#### A. Lyapunov optimization

Lyapunov optimization performs queue stabilization based on a greedy, real-time optimization strategy which does not require to know the underlying system dynamics. It is possible to define a parameter $V \ge 0$ to tune the balance between two conflicting objectives: the stability of the system, i.e., of individual queues, and the time average of a certain penalty function. In our case, the penalty is represented by the expected instantaneous reward, namely, the expected makespan corresponding to the current state-action pair $(S_t, A_t)$. We shall leverage a fundamental result tying the time average of the penalty function, which can be rendered close to its optimal value within $O(1/V)$ [19].

Lyapunov online optimization can be performed directly while treating the instantaneous reward of the relaxed problem (8) as the instantaneous penalty. We follow the procedure described in [19], [20], [21] and apply Theorem 4.2 in [21]. The resulting greedy policy, at each timestep $t$, performs action

$$ A_t = \underset{i}{\operatorname{arg min}} \left\{ V \cdot r(s, a) + \sum_{i=1}^{N} s_i(t) (\alpha_i(t) - \eta_i(t)) \right\} $$

where $\alpha_i$ denotes the arrivals dispatched to queue $i$ and $\eta_i$ the corresponding departures.

In particular, if we make the approximation $\alpha_i(t) - \eta_i(t) \sim 0$ and we impose $V = 1$, we obtain the following greedy action choice

$$ A_t = \underset{a}{\operatorname{arg min}} \left\{ \frac{s_a(t) + 1}{\mu_a} + \lambda_a \right\} \quad \forall t \qquad (9) $$
which in fact corresponds to the minimization of the instantaneous reward of the equivalent MDP. Actually, with this particular choice of parameter $V$, the resulting policy is the Join-the-Minimum-Cost-Queue (JMCQ) policy described in [22]. This policy is designed to manage a system of parallel queues offering differentiated service levels to a multiclass customer base. JMCQ operates by assigning different joining costs to each queue, which correspond to the Lagrange multiplier in our framework.

For the general case, the following result holds:

**Proposition 1.** For $\lambda \in \mathbb{R}^M$, $V \in \mathbb{R}$ and let $r^*$ the optimal reward we can obtain in this setting. There exists a greedy load-balancing policy $\tilde{\pi}$ such that time-average of the reward function $\bar{r}$ satisfies $\bar{r} \le r^* + O(1/V)$, and $\lim_{T \to \infty} \frac{1}{T} \sum_{t=1}^T \sum_i s_i(T) \le O(V)$.

The full proof is reported in Appendix B. A further, natural optimization step would require to optimize the multiplier vector $\lambda \in \mathbb{R}^M$, e.g., by using standard stochastic approximation techniques [23]. However, learning optimal Lagrange multipliers through consecutive iterations has two major drawbacks. The first drawback is that it may involve the evaluation of policies that do not satisfy the constraints during the online learning process. At runtime, undesirable outcomes may occur, possibly compromising system reliability or performance. The second one is that this primal-dual method becomes increasingly inefficient as the number of queues grows, since it entails optimization across a high-dimensional space. We defer to section VI for a detailed discussion on the viability of the primal-dual approach in our context. In the next section we focus on a class of lightweight algorithms to solve the constrained load balancing problem.

## IV. FINDING A SAFE POLICY

Throughout the rest of the paper, we will denote policies that satisfy all the constraints as *safe*. The priorities in the design of the safe algorithms presented hereafter are *scalability*, namely, in the number of served queues, and *online safety*, i.e., they should avoid the execution and evaluation of policies violating constraints to grant stability and safety throughout the optimization process.

### A. JSVED: Greedy policy w.r.t. virtual queues

The first solution uses virtual queues [19]. We define an auxiliary unconstrained MDP, denoted by $\tilde{M}$. In $\tilde{M}$ each queue of the original system is associated with an additional virtual queue. Such virtual queue has a processing speed corresponding to the access capacity constraint of its associated real queue, namely $\mu'_i = \theta_i$. In $\tilde{M}$, for every new arrival routed to queue $i \in \{1, \dots, M\}$, a corresponding virtual arrival is also routed to the associated virtual queue. The departures of the virtual queue are simulated according to virtual queue processing rate $\mu'_i$.

The first policy follows the JSED based on the simulated $\tilde{M}$ dynamics. For the constrained queues, it acts based on the state of the corresponding virtual queues as well as their processing

speed. For every constrained queue $i \in \{1, \dots, M\}$, let $\tilde{s}_i$ the occupation of the corresponding virtual queue. The resulting policy $\pi_V^*$ chooses the action as follows:

$$ \pi_V^*(s) = \min \left\{ \min_{i \in \{1, \dots, M\}} \left\{ \frac{\tilde{s}_i}{\mu'_i} \right\}, \min_{i \in \{M+1, \dots, N\}} \left\{ \frac{s_i}{\mu_i} \right\} \right\} $$

The policy $\pi_V^*$ is defined as JSVED (Join the Shortest Virtual Expected Delay). By construction, it is immediate to show that if $\pi_V^*$ renders $\tilde{M}$ stable, it also ensures constraints are respected in $\tilde{M}$.

The main limitation of JSVED is that it tends to be conservative. In fact, whenever $\theta_i \le 1/\mu_i$, we have $\tilde{s}_i \le \tilde{s}_i$ w.p.1. Because JSVED determines its actions based on the occupation levels of the virtual queues, the chosen action may be optimal with respect to the virtual queues, but suboptimal concerning the actual state of the real queues. The two safe policies we introduce in the next section guarantee safety, but rely on the real occupation vector only.

### B. JSED-k: JSED with memory

The second policy we propose is similar to the approach used in JSED, but with a key difference: it stores the last $k$ actions in memory. This allows the system to estimate the average cost at the time when an action is taken. Based on this estimate, the action space for the current timestep is constructed to prioritize safety. More precisely, at each step, the policy selects a queue that has been chosen no more than $k\theta_i$ times within the last $k$ steps.

JSED-k evaluates the average constraint in the last $k$-step window: for sufficiently large $k$, the policy is safe, as indicated by the following result. The full proof, just sketched here, can be found in Appendix B.

**Proposition 2.** The policy JSED-k is safe for a sufficiently high value of $k$.

*Proof:* First, observe that $k$ determines the accuracy of the average cost estimate, which in turn defines the action space at each timestep. Moreover, for $k = \infty$, i.e., when the entire past history is used to define the action space at a given timestep, the policy is seen to be safe. Hence, for all $\epsilon > 0$, there exists a value of $k$ such that the constraint is violated with probability at most $\epsilon$. ■

The JSED-k approach may require significant memory resources to store a sufficiently long action history. As the number of queues in the system increases, the required memory size $k$ must grow at least linearly to provide an accurate estimate of the average cost. In section VI, we study numerically the relationship between the number of queues $N$ and the memory size $k$ required to ensure safety.

### C. JSSQ: Join the Shortest Safe Queue

The last policy does not need to store the last $k$ actions in memory and yet makes decisions directly based on the actual occupancy of the queues. This dynamic policy sets a target average arrival rate per queue to respect the average constraints and minimize the average occupation. Actions are decided at
each timestep based on the current server occupation and the corresponding target value $L_i$.

To find the desired arrival rate for each queue, first consider the nonlinear problem describing the system behavior, whose objective is to minimize the average system occupation:

$$ 
\begin{array}{ll}
\text{minimize:} & \displaystyle\sum_i \frac{\xi_i}{\mu_i - \xi_i} \qquad (10) \\
\text{subj. to:} & \xi_i < \mu_i' \quad \forall i, \\
& \displaystyle\sum_i \xi_i = \Xi,
\end{array}
 $$

where $\Xi$ represents the total arrival rate in the system. In the stability region, 10 is a convex optimization problem as the objective function $\frac{\xi_i}{\mu_i - \xi_i}$ is convex for $\xi_i < \mu_i$. Standard convex optimization methods can be employed to solve this problem efficiently. Once the optimal arrival rates $\xi_i$ are determined, the corresponding target queue lengths $L_i$ can be computed as $L_i := \frac{\xi_i}{\mu_i - \xi_i}$ where $\xi_i$ is the solution of (10) for queue $i$, and $\mu_i$ is its processing rate.

Once the desired values of $L_i$ are known, we can define a policy whose primary goal is to maintain the occupancy of each queue as close as possible to its optimal level while satisfying the constraints.

At each timestep, the policy operates as follows. If at least one queue has an occupancy below its desired average, the policy selects a queue from this subset $G$. The selection is made with probability proportional to the desired arrival rates, $\xi_i/\sum_{j \in G} \xi_j$. In the case where every queue $i$ exceeds their target average occupations, i.e., $s_i \ge L_i$, the policy employs a randomized assignment dispatching an arrival to queue $i$ with probability $\xi_i/\Xi$.

The safety of this policy can be established. The proof, just sketched hereafter, is detailed in Appendix C.

**Proposition 3.** *JSSQ is safe.*

*Proof:* If a queue’s occupancy is below its desired average, it implies that the arrival rate to that queue has been lower than its target rate and, consequently, lower than the constraint associated with that queue. Conversely, if all queues have occupancies above their desired averages, the randomization step is performed according to a safe policy. ■

This policy presents several advantages compared to the methods discussed before. First, it enables real-time decision-making by acting on the actual state of the system, unlike JSVED. Second, it achieves memory efficiency, since it does not require storing the last $k$ actions, making it computationally more efficient than JSED-$k$. This policy can also be easily adapted, with minimal modifications, to solve the constrained version of the unconstrained problem analyzed in [12], [13], [14], [15]. This suggests a potential application of JSSQ in the context of those works, where the focus is the scalability to a large number of queues

JSSQ addresses the constraint satisfaction using randomization. As the other proposed heuristics, this approach does not guarantee the optimality of the policy, which, as remarked

before, requires rather to optimize the Lagrange multipliers. Indeed, a promising avenue for future work is to refine JSSQ by integrating approximations of the Lagrange multipliers described in section III. This enhancement could result in a policy that closely approximates the optimal solution while maintaining the safety guarantees, and it is left as future work.

## V. ENSURING RESOURCE EFFICIENCY THROUGH MINIMUM OCCUPATION CONSTRAINTS

In this section, we consider a different system in which the gain function depends on the stqte of the system. Specifically, we assume that each queue $i$ must satisfy an average constraint of the form:

$$ K_{\pi}^{i}(\beta) = \mathbb{E}_{\pi, s_0 \sim \beta} \left[ \lim_{T \to \infty} \frac{1}{T} \sum_{t=0}^{T} c_i(S_t) \mid S_0 = s_0 \right] \geq \theta_i \qquad (11) $$

for a generic convex gain function $c_i(\cdot)$.

In the remainder of this section, we will analyze how JSED-$k$ and JSSQ, two of the policies introduced in section IV to solve the initial problem, can be applied to the one considering the constraint in (11). We will exclude JSVED from the discussion due to its poor performance (see Section VI).

JSED-$k$ extends naturally to the general case by approximating the gain function in a manner similar to how it is handled for constraints of type (4).

Finally, we will demonstrate how to construct the JSSQ policy for the problem with a generic constraint of the type (11). As outlined in section IV-C, the first step is to determine a value for the target arrival rate $\xi_i$ that satisfies a nonlinear problem characterizing the case under study:

$$ 
\begin{array}{ll}
\text{minimize:} & \displaystyle\sum_i \frac{\xi_i}{\mu_i - \xi_i} \qquad (12) \\
\text{subject to} & c_i\left(\frac{\xi_i}{\mu_i - \xi_i}\right) > \theta_i \quad \forall i, \\
& \xi_i < \mu_i \quad \forall i, \\
& \displaystyle\sum_i \xi_i = \Xi,
\end{array}
 $$

where $\theta_i$ is now the generic constraint and $c_i(\frac{\xi_i}{\mu_i - \xi_i})$ is the gain function associated to the $i$-th queue computed in the average state. Clearly, the constraints related to flow conservation and those related to stability still need to be verified.

Once the desired values of $\xi_i$ are known, the policy is defined as in section IV-C, i.e., JSSQ tries to keep the occupation of the MDP as close as possible to the one induced by the solution of (12).

The safety of this policy is an immediate consequence of Jensen inequality:

**Corollary 1.** *If a policy induces a set of arrival rates that satisfy (12), then the policy is also safe.*

*Proof:* In (12) the first condition to satisfy involves the gain of the average state obtained by a policy, while in the
MDP we have to consider the average gain of a policy. By Jensen inequality $c(E[s]) \le E[c(s)]$ as the gain function $c(\cdot)$ is assumed to be convex. Therefore, if we can guarantee that $c_i(E[s]) > \theta_i \forall i$, we know that the constraint is satisfied if the queue has arrival rate $\xi_i$.

## VI. NUMERICAL RESULTS

Numerical results are divided into four main groups.

The first one explores the computational complexity of the Lagrange multipliers optimization, i.e., the additional step required to obtain a near-optimal policy described in section III. In the second set of experiments, we study the performance of JSED-$k$ for increasing $k$. We specifically focus on the memory size required for the resulting policy to be safe. The third experiment compares the performance of the policies presented in section IV - namely, JSVED, JSED-$k$, and JSSQ - with JSED, the state-of-the-art algorithm conceived for unconstrained load balancing. The last experiment provides a comparative analysis of the algorithms discussed in section VI, dealing with a cost function which depends on the current state.

We randomly sampled the system parameters from predefined sets for all experiments and normalized their outcomes accordingly.

Throughout this section, we considered either light or heavy load conditions to represent different system load conditions. Under light load conditions, the arrival rate of tasks or requests falls between 70% and 95% of the total processing capacity of the system. These conditions represent a system operating with sufficient spare capacity, experiencing manageable workloads and relatively small delays. This is meant to measure the system performance under relatively relaxed operating conditions, providing insight into efficiency and responsiveness when resources are not critically constrained.

Under heavy load conditions, the arrival rate exceeds 99% of the system's total processing capacity. This reflects near-saturation levels, where the system is pushed to its operational limits. Heavy load conditions are particularly relevant for stress-testing the system's ability to maintain performance under high demand. These scenarios are critical to understand the robustness and reliability of the system in real-world situations where demand may approach or even exceed design thresholds.

### A. Optimizing Lagrange multipliers

The first experiment reports on the number of policy evaluation steps needed to determine the optimal Lagrange multipliers as described in (9). We considered environments with light traffic conditions and 5, 10, and 25 queues. The results shown in table II are obtained from 30 independent experiments per value of $N$. We can observe that, even for smaller values of $N$, the convergence speed, measured by the required policy evaluation steps, remains remarkably high. We set an upper limit of 50 for the number of policy evaluations. It is worth observing that, in these tests, the number of policy evaluation steps using unsafe policies was very close

<table><caption>**Table II:** Number of iterations for the stochastic approximation method optimizing the Lagrange multipliers; the policy chooses actions according to (9); low traffic conditions.</caption><thead><tr><th><i>N</i></th><th>5</th><th>10</th><th>25</th></tr></thead><tbody><tr><td>mean # of iterations</td><td>16.475</td><td>24.9</td><td>41.72</td></tr><tr><td>occurrences with > 50 iterations</td><td>17%</td><td>30%</td><td>60%</td></tr></tbody></table>

<figure><img src="image_2.png" /><figcaption>**Figure 2:** Average occupation and max cost of JSED-$k$ for increasing values of memory size $k$; light traffic conditions.</figcaption></figure>

to the total. This finding highlights a critical limitation of this approach, particularly in scenarios where evaluating unsafe policies online could lead to undesirable consequences.

### B. Performance of JSED-$k$: different memory size

In this section, we analyze JSED-$k$ for increasing memory size $k$. A larger memory size reduces the probability of violating the constraints. But, it introduces practical challenges, as discussed in section IV-B.

We reported our findings in fig. 2 and fig. 3. The first one compares the reward and the maximum cost for increasing memory size. The system has $N = 25$ queues, $M = 13$ of which are constrained. The second figure shows the evolution of the critical memory size, i.e., the smallest memory size $k$ that guarantees safety as a function of the number of queues.

Figure 2 presents data from a system operating under light traffic conditions, i.e., the arrival rate does not exceed 95% of the system's total capacity. As expected, increasing $k$ reduces the cost associated with the queue experiencing the highest cost, bringing the system closer to satisfying all constraints.

<figure><img src="image_3.png" /><figcaption>**Figure 3:** Evolution of the critical memory size at the increase of the number of queues.</figcaption></figure>
<figure><img src="image_4.png" /><figcaption>**Figure 4:** Comparison of the policies described in section IV for increasing ratio between arrival rate and capacity of the system.</figcaption></figure>

Notably, for $k = 250$, even the highest observed cost across all experiments attains, on average, the constraint threshold.

In fig. 3, we analyze how the critical memory size evolves as the number of queues in the system increases, with $M = N/2$ for simplicity. The results indicate that in both load conditions, the critical memory size follows an exponential growth pattern as $N$ increases. However, for light load conditions, the critical memory size remains practically viable, namely up to 100 queues. Conversely, for heavy load conditions, the critical memory constraints grows significantly faster, becoming impractical even for relatively small systems. Larger values of $N$ ($N > 50$) required $k$ to exceed 10,000, which was also the maximum value we tested. We excluded those data points for the sake of readability.

### C. Comparison performances of different safe policies

We then analyzed the performance of the methods introduced in section IV, comparing them to JSED, the state-of-the-art algorithm for unconstrained load balancing. The comparison is carried out under both heavy and light traffic conditions by varying the ratio between the arrival rate and the system's cumulative processing rate. We fixed the same set of 50 environments to test all policies; the arrival rate, on the contrary, was progressively increased.

For each method, fig. 4 presents the distribution of the normalized occupation and the normalized maximum cost. The occupation has been normalized with respect to the value obtained by JSVED. Cost normalization is performed component by component relative to the value of the constraint. A method is considered safe if the cost associated with each queue remains below its corresponding constraint. In fig. 4, we emphasize the value of the worst-performing queue observed in each experiment to illustrate the safety of the policies.

As expected, JSED achieves the lowest average system occupation across all experiments, as it is provably the optimal policy in the unconstrained case. However, it fails to respect the constraints, particularly in scenarios with heavier traffic. In contrast, the results clearly show that the safe policies

<figure><img src="image_5.png" /><figcaption>**Figure 5:** Comparison of the reward and safety guarantees for different policies in the case of a convex generic gain function.</figcaption></figure>

introduced in section IV successfully satisfy the constraints across a range of arrival rate values.

Regarding average system occupation, JSVED performs the worst, as discussed in section IV-A, with its limitations becoming even more pronounced under heavier traffic conditions. Finally, JSED-$k$, when equipped with an appropriately sized memory as outlined in section VI-B, demonstrates superior resource management compared to JSSQ, striking a balance between performance and constraint compliance.

By combining the results discussed in this section and those in section VI-B, we conclude that for relatively small systems, JSED-$k$ emerges as the most effective safe policy in terms of minimizing average system occupation, with JSSQ showing slightly lower performance. We recall, however, that even under heavy traffic conditions, JSSQ has $O(1)$ memory requirements. Hence, JSSQ is preferable once memory allocation or computation of actions' statistics required by JSED-$k$ become impractical.

### D. State-dependent cost function

The numerical section concludes by analyzing the performance of the methods introduced in section V. Additionally, we evaluated the performance of a randomized policy that selects a server based on probabilities induced by the arrival rates obtained by solving (12). This policy is referred to as *Randomized JSSQ*. As expected, it performed consistently worse than JSSQ across all experiments.

The experiments were conducted with $N = 10$ servers, for linear and convex gain functions. The same set of 50 environments was used in both cases. For sake of space, and because of the minor differences between the two cases, only the results for the convex gain function are presented here. All experiments were performed under light traffic conditions.

In fig. 5, we compare the normalized occupation and the minimum normalized gain across all queues. A policy is considered safe if the minimum gain exceeds the unitary normalized constraint (all values are normalized).

In terms of occupation, JSED performs the best, as expected, while JSSQ slightly outperforms JSED-$k$. The policies, as defined in the experiments, remain safe throughout all tests.
JSSQ consistently achieves performance close to JSED in terms of occupation, while JSED-k exhibits higher variance. JSED-k's performance is more sensitive to changes in the environment, unlike JSSQ, which shows greater stability.

## VII. RELATED WORKS

State-dependent routing problems have been extensively studied in the literature (see, e.g., [24] for an overview). A notable setting where simple structures for optimal policies have been successfully identified involves homogeneous stations. In such cases, the “Shortest Delay Routing” (SDR) policy has been demonstrated to be optimal under various conditions [4], [5]. However, [25] showed also several trivial cases in which this policy is not optimal. For the more complex case of routing problems that do not assume station homogeneity, [18] showed the asymptotical optimality of the JSED policy in the heavy traffic case. When the cost function is a convex function of occupation, [17] proves the optimality under heavy traffic of a policy which chooses at each step the greedy action minimizing $c_i(s_i)\mu_i$, i.e., the immediate cost multiplied by the processing speed of the queue. [26] defines a near-optimum queue-assignment rule that offers a generalization of the shortest-queue rule to the case of dissimilar queues to minimize the average sojourn time. [27] provides an optimal policy when $N$ queues compete for a single server (as in call centers). Finally, [6] proposes an optimal solution in the case of non-linear cost functions. To the best of the authors' knowledge, despite being a problem of clear practical interest, the constrained version of the load balancing problem has not been tackled so far in the literature.

## VIII. CONCLUSIONS

Load balancing is critical in many applications to ensure efficient resource allocation and system performance. However, standard load-balancing algorithms are oblivious to constraints such as link capacities or state-dependent restrictions on individual queues. As a result, while similar constraints are the norm in real-world systems, current load-balancing methods are not designed to address them.

In this paper, we first identified a near-optimal method based on a CMDP relaxation. While it provides theoretical insight, the method is hardly viable for real-world scenarios since it entails policy evaluation steps which are computationally demanding. Hence, we proposed new lightweight policies to perform load balancing and incorporate constraints at once.

This work is just an initial step in constrained load balancing. Future research will focus on simplifying the near-optimal approach using fast approximation methods to estimate optimal Lagrange multipliers. Also, in heavy traffic, scalability depends on message complexity and delay constraints, as queue occupancy must be sampled in real time. Solving these open challenges will broaden the applicability of constrained load balancing solutions to real-world scenarios.

## REFERENCES

[1] V. Gupta, M. H. Balter, K. Sigman, and W. Whitt, “Analysis of join-the-shortest-queue routing for web server farms,” *Performance Evaluation*, vol. 64, 2007.

[2] R. Nishtala, H. Fugal, S. Grimm, et al., “Scaling memcache at Facebook,” in *10th USENIX NSDI*, 2013.

[3] I. Foster, Y. Zhao, I. Raicu, and S. Lu, “Cloud computing and grid computing 360-degree compared,” in *Proc. of IEEE Grid computing environments workshop*, 2008.

[4] W. Winston, “Optimality of the shortest line discipline,” *Journal of applied probability*, vol. 14, 1977.

[5] R. R. Weber, “On the optimal assignment of customers to parallel servers’,” *Journal of Applied Probability*, vol. 15, 1978.

[6] A. Stolyar, “Optimal routing in output-queued flexible server systems,” *Probability in the Engineering and Informational Sciences*, 2005.

[7] H. Al-Bahadili, *Simulation in Computer Network Design and Modeling: Use and Analysis*. IGI Global, 2012.

[8] T. Ozcelebi, F. De Vito, A. Tekalp, M. Civanlar, M. Sunay, and J. De Martin, “An analysis of constant bitrate and constant psnr video encoding for wireless networks,” in *Proc. of IEEE ICC*, vol. 11, 2006.

[9] D. V. Nguyen, T. T. Le, S. Lee, and E.-S. Ryu, “Shvc tile-based 360-degree video streaming for mobile vr: Pc offloading over mmwave,” *Sensors*, vol. 18, 2018.

[10] D. Xu, X. Liu, and A. V. Vasilakos, “Traffic-aware resource provisioning for distributed clouds,” *IEEE Cloud Computing*, vol. 2, 2015.

[11] S. Lippman, “Applying a new device in the optimization of exponential queuing systems,” *Operations research*, vol. 23, 1975.

[12] X. Zhou, N. Shroff, and A. Wierman, “Asymptotically optimal load balancing in large-scale heterogeneous systems with multiple dispatchers,” *Performance Evaluation*, vol. 145, 2021.

[13] X. Zhou, J. Tan, and N. Shroff, “Heavy-traffic Delay Optimality in Pull-based Load Balancing Systems: Necessary and Sufficient Conditions,” *Proceedings of the ACM on Measurement and Analysis of Computing Systems*, vol. 2, 2018.

[14] X. Zhou, F. Wu, J. Tan, K. Srinivasan, and N. Shroff, “Degree of Queue Imbalance: Overcoming the Limitation of Heavy-traffic Delay Optimality in Load Balancing Systems,” *Proc. of ACM Measurement and Analysis of Computing Systems*, vol. 2, 2018.

[15] X. Zhou, F. Wu, J. Tan, Y. Sun, and N. Shroff, “Designing Low-Complexity Heavy-Traffic Delay-Optimal Load Balancing Schemes: Theory to Algorithms,” *Proc. of ACM Measurement and Analysis of Computing Systems*, vol. 1, 2017.

[16] E. Altman, *Constrained Markov decision processes*. Routledge, 2021.

[17] A. Mandelbaum and A. Stolyar, “Scheduling flexible servers with convex delay costs: Heavy-traffic optimality of the generalized $c\mu$-rule,” *Operations Research*, vol. 52, 2004.

[18] G. Foschini, “On heavy traffic diffusion analysis and dynamic routing in packet switched networks,” *Computer performance*, vol. 10, 1977.

[19] M. Neely, “Stability and probability 1 convergence for queueing networks via Lyapunov optimization,” *Journal of Applied Mathematics*, vol. 2012, 2012.

[20] L. Bracciale and P. Loreti, “Lyapunov drift-plus-penalty optimization for queues with finite capacity,” *IEEE Communications Letters*, 2020.

[21] M. Neely, *Stochastic network optimization with application to communication and queueing systems*. Morgan & Claypool, 2010.

[22] R. Tandra, N. Hemachandra, and D. Manjunath, “Join minimum cost queue for multiclass customers: Stability and performance bounds,” *Probability in the Engineering and Informational Sciences*, 2004.

[23] M. Fu and S. Hill, “Optimization of discrete event systems via simultaneous perturbation stochastic approximation,” *IIE Transactions*, vol. 29, no. 3, 1997.

[24] N. Argon, L. Ding, K. Glazebrook, and S. Ziya, “Dynamic routing of customers with general delay costs in a multiserver queuing system,” *Probability in the Engineering and Informational Sciences*, 2009.

[25] W. Whitt, “Deciding which queue to join: Some counterexamples,” *Operations research*, vol. 34, 1986.

[26] K. Krishnan, “Joining the right queue: A markov decision-rule,” in *26th IEEE Conference on Decision and Control*, IEEE, 1987.

[27] C. Buyukkoc, P. Varaiya, and J. Walrand, “The $c\mu$ rule revisited,” *Advances in applied probability*, vol. 17, 1985.
A. *Proof of Proposition 1*

*Proof:* We write the Lyapunov function of the system [21] as

$$L(s(t)) = \frac{1}{2} \sum_{i=1}^{N} \frac{s_i(t)^2}{\mu_i} \qquad (13)$$

and the corresponding conditional Lyapunov drift in slot $t$ writes

$$\Delta(s(t)) = \mathbb{E}[L(s(t+1)) - L(s(t)) | s(t)] \qquad (14)$$

The proof of Proposition 1 is an immediate consequence of the fundamental result in [21][Thm. 4.2] that we recall here for the sake of reading:

**Theorem 1.** If $\epsilon \ge 0, V \ge 0, B \ge 0$ exist such that for all $t$ slots we have

$$\Delta(s(t)) + V \mathbb{E}[r(t) | s(t)] \le B + V r^* - \epsilon \sum_{i=1}^{N} \frac{s_i(t)}{\mu_i} \qquad (15)$$

then all queues $s_i(t)$ are (mean-rate) stable and the time-averaged expected penalty $\bar{r}$ are bounded by

$$\bar{r} \le r^* + \frac{B}{V} \qquad (16)$$

$$\lim_{T \to \infty} \frac{1}{T} \sum_{\tau=0}^{N-1} \sum_{i=1}^{N} s_i(\tau) \le \frac{B + V(r^* - r_{min})}{\epsilon} \qquad (17)$$

where $B$ is a positive constant that upper bounds the expression $\mathbb{E}[\frac{\alpha(t)^2 + \eta(t)^2}{2} | s(t)]$

It remains to prove that we can apply Theorem 1 and in particular that (15) is verified.

We observe how

$$
\begin{align*}
\Delta(x(t)) &= \mathbb{E}[L(s(t+1)) - L(s(t))] = \mathbb{E}\left[\frac{1}{2}\sum_{i=1}^{N} \frac{s_i(t+1)^2}{\mu_i} - \frac{s_i(t)^2}{\mu_i}\right] \\
&= \sum_i \frac{1}{2\mu_i} \mathbb{E}[\alpha_i^2(t) + \eta_i^2(t) + 2s_i(t)\alpha_i(t) - 2s_i(t)\eta_i(t) - 2\alpha_i(t)\eta_i(t)] \\
&\le \sum_i \frac{1}{2}\mathbb{E}[\alpha_i^2(t) + \eta_i^2(t)] + \sum_i \frac{1}{2\mu_i}\mathbb{E}[2s_i(t)(\alpha_i(t) - \eta_i(t))] \\
&\le B + \sum_i \frac{1}{2\mu_i}\mathbb{E}[2s_i(t)(\alpha_i(t) - \eta_i(t))] \\
&\le B - \epsilon \sum_i \frac{s_i}{\mu_i}
\end{align*}
$$

with the last inequality following from the fact that the expected $\mathbb{E}[\alpha_i(t) | s_i(t)] \le \mathbb{E}[\eta_i(t) | s_i(t)]$ is a necessary condition for the stability of the system. ■

B. *Proof of Proposition 2*

*Proof:* We want to prove that for every $\epsilon > 0$ there exists $k$ such that

$$J_{\pi_k, i}(\beta) \le \theta_i + \epsilon$$

where $\pi_k$ denotes the JSED-$k$ policy, assuming memory size $k$, and $J_{\pi_k, i}$ is the corresponding reward.

First, we observe that the policy $\tilde{\pi}$, which considers the entire past history to determine the action set, is safe. In particular, at each timestep, it can determine which actions would not violate the constraint if chosen.

Then, we observe that, given a certain state $s_t$ and the past actions, the estimator $\tilde{c}_{k,i}(s_t) = \sum_{j=1}^{k} \frac{\delta_i(a_{t-k+1})}{k}$ is a consistent estimator of the average cost for the full trajectory, denoted as $c_i(s_t)$. This implies that, for every $\Delta > 0$,

$$\lim_{k \to \infty} \mathbb{P}(|c_{k,i} - c_i| < \Delta) = 1$$
This further implies that, for every fixed $\Delta$ there exists $k \in \mathbb{N}$ such that for every $\epsilon > 0$ it holds

$$ \mathbb{P}(|c_{k,i} - c_i| > \Delta) < \epsilon \quad (18) $$

Now, fixed $\epsilon > 0$ and $k = k(\Delta) \in \mathbb{N}$ defined above it holds

$$
\begin{align}
|J_{\pi_k, i}(\beta) - J_{\tilde{\pi}, i}(\beta)| &= \left| \mathbb{E}_{a_t \sim \pi_k, s_0 \sim \beta} \left[ \lim_{T \to \infty} \frac{1}{T} \sum_{t=1}^{T} c_i(s_t, a_t) \right] - \mathbb{E}_{a_t \sim \tilde{\pi}, s_0 \sim \beta} \left[ \lim_{T \to \infty} \frac{1}{T} \sum_{t=1}^{T} c_i(s_t, a_t) \right] \right| \nonumber \\
&= \left| \mathbb{E}_{a_t \sim \pi_k, s_0 \sim \beta} \left[ \lim_{T \to \infty} \frac{1}{T} \sum_{t=1}^{T} \delta_i(a_t) \right] - \mathbb{E}_{a_t \sim \tilde{\pi}, s_0 \sim \beta} \left[ \lim_{T \to \infty} \frac{1}{T} \sum_{t=1}^{T} \delta_i(a_t) \right] \right| \nonumber \\
&\le \mathbb{E}_{s_0 \sim \beta} \left[ \lim_{T \to \infty} \frac{1}{T} \sum_{t=1}^{T} \left| (1 - \delta_{\pi_k(s_t)})(\tilde{\pi}(s_t)) \cdot (\delta_i(\pi_k(s_t)) + \delta_i(\tilde{\pi}(s_t))) \right| \right] \tag{19} \\
&\le \mathbb{E} \left[ \lim_{T \to \infty} \frac{1}{T} \sum_{t=1}^{T} \mathbf{1} (|c_{k,i}(s_t) - c_i(s_t)| > \Delta) \right] \nonumber \\
&= \mathbb{P}(|c_{k,i}(s_t) - c_i(s_t)| > \Delta) \nonumber
\end{align}
$$

where each term appearing in the sum in (19) is equal to one if and only if a policy chooses action $i$ and the other does not, and it is zero otherwise.

Finally, this implies that, for every value of $\epsilon > 0$, there exists a value $k$ such that

$$ |J_{\pi_k, i}(\beta) - J_{\tilde{\pi}, i}(\beta)| < \epsilon $$

This, combined with the fact that $\tilde{\pi}$ satisfies the constraints, gives the desired result. ■

### C. Proof of Proposition 3

Let $\xi_i$ denote the desired arrival rate obtained by solving the nonlinear problem (10). We introduce a new policy, referred to as *Randomized JSSQ* ($\pi_{RJSSQ}$ for brevity), which selects the destination server at each timestep based on a probability distribution

$$ \pi_{RJSSQ}(s, i) = \frac{\xi_i}{\sum_j \xi_j} $$

where the $\xi_i$s are determined by solving (10)

**Proposition 4.** *The policy Randomized JSSQ satisfies the constraints.*

*Proof:* By definition, under $\pi_{RJSSQ}$ each queue has arrival rate $\xi_i$ solving (10) and therefore satisfies the constraints. ■

This allows us to prove Proposition 3:

*Proof:* When the occupation of every queue is above their respective threshold $L_i$, JSSQ's coincides with Randomized JSSQ. In all the other states, arrivals are assigned only to the set of queues which have an occupation lower than their threshold, according to the proportion implied by their corresponding values of $\xi_i$.

Hence, JSSQ can be seen as a randomization between two safe policies: Randomized JSSQ, and a safe assignment based on the instantaneous occupation. As such the resulting policy is safe. ■