Nancy: An efficient parallel Network Calculus library

This paper describes Nancy, a Network Calculus (NC) library that allows users to perform complex min-plus and max-plus algebra operations efficiently. To the best of our knowledge, Nancy is the only open-source library that implements operations working on arbitrary piecewise affine functions, as well as to implement some of them (e.g. sub-additive closure and function composition). Nancy allows researchers to compute NC results using a straightforward syntax, which matches the algebraic one. Moreover, it is designed having computational efficiency in mind: it exploits optimizations of data structures, it uses inheritance to allow for faster algorithms when they are available (e.g., for specific subclasses of functions), and it is natively parallel, thus reaping the benefit of multicore hardware. This makes it usable to solve NC problems which were previously considered beyond the realm of tractable.


Motivation and significance
Worst-case analysis of networked systems is gaining importance due to the emergence of safety-critical applications with real-time requirements, such as factory automation within the Industry 4.0 paradigm, automated or teleoperated driving, coordinated unmanned aerial vehicles, etc. With all these distributed applications, ex-ante certification that end-to-end network transit will complete within a predictable (worst-case) time is required to guarantee safety for humans and property. Network Calculus [1] is a well-known theory that uses min-plus and max-plus algebra to infer deterministic worst-case bounds on the delay and backlog of network traffic. It represents application traffic as a function of time, and network elements (e.g., regulators, schedulers, links) as operators that modify said functions. Given bounds on the input of a traffic flow (e.g., as enforced by a traffic shaper at the entrance of a network) and knowledge of minimum service given to that flow at network elements (e.g., as enforced by possibly different schedulers at every hop), NC allows one to compute the maximum delay that traffic from that flow will undergo, under any possible scenario.
Algebraically speaking, NC relies on few basic operations, such as minimum, min-plus convolution and sub-additive closure, which can be composed in arbitrary sequences or nested into one another. However, in less-thantrivial cases, pen-and-paper computation of NC expression is not viable, and automated computation of the relevant performance measures (e.g., a maximum delay for a flow traversing a multi-hop network) is instead required. Defining efficient computational representations for functions of time and algorithms implementing NC operators thereupon is by no means a simple task. Book [2] discusses the above issue at length, identifying Ultimately Pseudo-Periodic (UPP) functions as the most general class closed with respect to NC operators. These are piecewise-affine functions, that have an initial "transient" part, followed by a "period" which is repeated an infinite amount of times. Some NC operators, such as min-plus convolution, have a superquadratic complexity with respect to the number of linear pieces of the operands. Others, such as the sub-additive closure, are exponential. This holds for both the number of elementary operations involved and the number of linear pieces of the result, and implies that chaining a number of NC operators may yield expressions that -while visually and algebraically neat -are algorithmically unfeasible, e.g., take days to compute, or may exhaust the hardware resources and not compute at all [3]. This constrains -sometimes severely -the practical uses of NC analysis, and calls for efficient software libraries that implement NC operations.
To the best of our knowledge, there are no public, open-source libraries that implement NC operators working on UPP curves. By "library" we mean a set of implementations of min-and max-plus algebra operations, providing ease of constructing and manipulating curves, and ways to specialize algorithms for improved efficiency. The two existing libraries that can handle UPP curves are the RTC Toolbox [4] and the RTaW-Pegase library [5]. The former is a publicly available Java library, whose source code is not available. Thus, one cannot improve on its bugs (e.g. it sometimes cycles infinitely without any discernible cause) or lack of features, such as the lack of subadditive closure or of a function to find the intersection between two curves (which is essential to speed up several algorithms). RTaW-Pegase is proprietary, and cannot be used for benchmarking purposes. An online interpreter is freely available to try its functionalities [6], but its use is limited by the browser interface and license. To the best of our knowledge, the COINC library [7] is no longer available. We remark that there are several common situations where UPP curves arise spontaneously: work [8] shows that this is the case whenever packetization and finite transmission speeds are factored in. Moreover, flow-controlled networks [3], currently being envisaged for data centers, have UPP service curves, and so do wormhole-routing networks [9] used in systems architectures.
There are, instead, several NC network analysis tools, i.e., software packages that implement methods of analysis of particular networks. These often implement their own versions of min/max-plus algebra operators, often restricted to the type of application network they target. A review of their capabilities is reported in [10]. For instance, DEBORAH [11] analyzes FIFO tandems of rate-latency curves traversed by leaky-bucket-shaped flows. As such, it only implements min-plus convolution and subtraction of pseudoaffine curves, both of which are algorithmically trivial. NC-TANDEM-TIGHT [12] analyzes FIFO tandems by modeling their worst-case delay computation as a linear programming problem (hence implicitly ruling out generic UPP curves, which would yield non-convex programs instead). The DiscoDNC tool [13] is limited to concave/convex piecewise linear curves, for which NC operations are considerably simpler. Unfortunately, none of these tools provide reusable, general-purpose NC operations.
In this work, we fill the above gap by releasing Nancy, an open-source NC library released under the MIT licence. Nancy is coded in C#, consists of more than 32k LoC, and is natively parallel. This means that it can exploit multiple cores when available. Most of the NC operations on UPP curves entail comparing linear segments and/or taking minima or maxima, and these operations are easily parallelizable. This allows it to reap a considerable speedup over a single-thread implementation. Furthermore, it implements smart algorithms for NC operators working on particular sub-classes of UPP functions (e.g., sub-additive ones), as well as for minimizing the representation of functions, which concur to abate the computation times by orders of magnitude, as shown in [3]. Nancy can be used to implement existing methods of analysis (e.g., Total Flow Analysis or Single Flow Analysis, [14]) used in other tools, without the restrictive hypotheses on the type of input curves. Moreover, it can be exploited to devise new methods of analysis, possibly for types of networks that were considered computationally untractable [3]. Last, but not least, it is designed so that a NC researcher will find it very easy to translate pen-and-paper computations to code: the names used for objects are those which are widespread in the research community, and the syntax is very intuitive.
The Nancy library is expected to be useful to researchers in both academia and industry that face worst-case analysis problems, such as those working in avionics, embedded systems, computer networks at large, and to help system engineers in performance-oriented design. In the rest of the paper,  we describe the software design and functionalities, we provide examples of how it works, and we discuss the impact of the above library.

Software description
A functionin NC often represents the amount of data observed at a network element up to time t. Accordingly, we will often refer to its abscissa as "time" and to its ordinate as "data". The Nancy library provides rich classes that allow one to model, manipulate and run computations with piecewise affine UPP functions. The UPP property states that: The above implies that, in order to compute f (t) for any t ≥ 0 we only need to store its values in [0, T + d[ and the three parameters T , d and c. This is visualized in Figure 1. The left plot depicts a function whose transient part (up to T ) consists of two segments, and whose period (repeated twice) consists of two segments too.
We represent this in code with the class Curve, which is composed of a BaseSequence and the values PseudoPeriodStart (T ), PseudoPeriodLength (d) and PseudoPeriodHeight (c).
The BaseSequence is of type Sequence, which models a piecewise affine This allows us to model non-continuous UPP curves as well. The right plot of Figure 1 shows the transient part consisting of four elements, and a period consisting of four elements. Quadruple {R f , T, d, c} is the information required to represent the above function in code.
The numeric type used throughout the library is Rational, which represents numbers in Q ∪ {+∞, −∞}. This allows us to perform computations without any approximations (unlike what happens when using the double type). To avoid overflow issues, we use BigInteger, although we support using long instead for better performance, using a compile flag.
These types are immutable, i.e. they cannot be modified after construction, and methods will instead create new objects to return. This has a twofold advantage: on one hand, safety of use -an object will never change properties unless it is reassigned explicitly. On the other hand, it favors parallelization, since all computations are independent and can be safely executed concurrently.
Many min-and max-plus operators are implemented as methods of these classes, and are closed, i.e. they return objects of the same class they belong to -in fact, they compute the bounded UPP representation of the result. This implies that they can be chained, allowing for computation of complex NC expressions. The main operators implemented are [2]: • (min−plus) Convolution and Deconvolution; • Vertical -and HorizontalDeviation; • MaxPlusConvolution and MaxPlusDeconvolution; • Lower-and UpperPseudoInverse; • Sub-and SuperAdditiveClosure; • Composition, i.e. h(t) = f (g(t)) 1 .
We also implement many utility methods and properties for common manipulations and checks, such as: • Sampling a curve at or "near" a time with ValueAt, LeftLimitAt and RightLimitAt; • Properties, such as IsContinuous, IsNonDecreasing, IsConcave, IsSubAdditive, etc. ; • Shift along the time axis (DelayBy, AnticipateBy) and data axis ( VerticalShift ); • Restriction of a Curve to a finite time interval, with the Cut operator.
As discussed in [3], the representation of the result of the above operations is often (unavoidably) much larger than necessary -i.e., it includes many more segments than required. This may lead to severe memory/speed inefficiency, especially with chained operations (recall that NC operators often involve algorithms that are superlinear in the number of segments). The Nancy library implements an efficient post-hoc representation minimization algorithm, run by default in all operands before returning the result, which solves this issue.
Moreover, we exploit the high parallelizability of the above operators using PLINQ. The Nancy library will parallelize the following: • aggregate operators, such as the aggregate convolution of a large set of curves; • large sets of independent tasks. For instance, convolution involves computation of the lower envelope of a set of Elements over a time domain. Elements are first grouped in (time) buckets according to their interval of definition. Then, per-bucket lower-envelopes are computed independently in parallel.
Lastly, many methods of the Curve class are defined as virtual, so that its subclasses can provide more efficient algorithms. For instance, the convolution of ConcaveCurves is replaced with their minimum, which is less complex. This makes the library easily extensible to exploit existing -or yetto-be-found -mathematical properties. For instance, specialized algorithms for SubAdditiveCurves have been implemented, which are considerably more efficient [3].
As an example of the above, we report in Table 1 the time it takes to compute the convolution between two sub-additive curves, using both the standard algorithm and the optimized one in [3], in both a sequential and a parallel setting. We run the above computations on a laptop computer (i7-10750H, 32 GB RAM). We can cleralry see that the mathematical properties described in [3] reduce the computation time by orders of magnitude. This highlights that the flexibility of the type system implemented in Nancy is a great benefit for future improvements. On the other hand, we observe that parallelization brings considerable benefits even for the unoptimized  [3]. Results are reported for each case as 25th percentile (Q1), median (Q2) and 75th percentile (Q3) over 10 independent runs.
computation. This can be generalized to cases where optimized mathematical properties are not available or not enough (many example of which can be found in [3]). However, trying to parallelize the optimized algorithm does not yield any benefits: this is to be expected, as the computation time is already under 1 ms, thus the overhead required by parallelization is higher than the time saved. The library allows for fine tuning of the algorithms used via the settings parameter, which can be used to avoid sub-optimal settings, such as misusing parallelization as in the above case.

Illustrative examples
In this section we show how the Nancy library can be used to easily build curves and compute NC expressions. These examples are provided in the GitHub repository as .NET Interactive Notebooks, were we use XPlot.Plotly to visualize the computed curves, as shown in the figures below. Our aim here is to show that the library syntax, which is rather intuitive, closely matches NC algebra, making it very easy for a practitioner to compute (and possibly plot) the results of its expressions.
The first example in Figure 2 shows how to construct a generic Curve, providing the limited Sequence description and the pseudo-period parameters. The library also provides simplified constructors for common types of curves, as shown in Figure 3.
We can then use such curves to compute more complex curve expressions, or delay bounds, as shown in the example of Figure 4 (from [2, p. 121]).
We now show two examples of more complex computations taken from the NC literature. In Figure 5 we show the computation of a residual service curve for a flow in a FIFO aggregate, whose expression is ([1, Ch. 6]):       where β is the aggregate service curve, α is the arrival curve of the cross-flow, δ x is a right-shift by x and θ ≥ 0 is a time parameter.
Our last example is based on the recent work in [15,Th. 1], which computes a strict service curve for Interleaved Weighted Round Robin (IWRR) through multiple steps. In Figure 6, we implement this computation using the parameters in [15, Fig. 3].

Impact
Despite being 30 years old, Network Calculus is still a flowering field of research. A search on Scopus reports 758 scientific papers published in the last 10 years (80 in 2021 only) where "Network Calculus" appears in the title, abstract or keywords. Research groups working on it exist in both  the academia (at least in Europe, US, Canada, China, India, Brazil) and the industry (components, avionics, systems). It is in particular industrial interest that has sparked a renewed attention in NC in the last few years, with the advent of new standards (e.g., Time-Sensitive Networks) and new scenarios and opportunities (e.g., the possibility of running real-time control algorithms of physical objects from the Cloud or the emergence of Digital Twins). The Nancy library presented in this paper can be used by all the above actors to address their research needs. It has already been used in research projects (namely, a joint project between Arm Ltd and the University of Pisa), as well as to write scientific papers [3].

Conclusions
This paper has presented Nancy, a C# library for Network Calculus operations, written for NC researchers. One of the features provided by the Nancy library is the attention to computational efficiency. As already discussed, NC is widely believed to be computationally hard, especially when generic UPP curves are concerned. This has severely limited its applicability to practical problems so far. Quite often, researchers have resorted to pessimistic bounding techniques in order to obtain computable results, or have been forced to limit the scope of their analysis to few network nodes. Nancy tackles the problem of computational efficiency in several concurrent ways. The first one is inheritance: while algorithms for UPP curves at large are known, research is currently discovering subclasses of UPP curves whose properties allow more efficient algorithms. One such examples are subadditive curves, discussed in [3], where the cost of convolution can be abated by orders of magnitude. The second one is built-in optimization of the curve data structures. It is shown in [3] that NC operations yield results whose UPP representation is redundant. Optimizing that representation ex-post comes at negligible cost, and may save orders of magnitude of computations (besides memory occupancy, which often becomes a problem itself). The third one is native parallel implementation, which harvests all the underlying computational power, distributing both NC operations and sub-tasks thereof.

Declaration of Competing Interest
The authors declare that they have no known competing financial interests or personal relationships that could have appeared to influence the work reported in this paper.