Containers/Guarantees for resources
This page describes how guarantees for resources can be implemented.
How to guarantee a guarantee
It's not obvious at the first glance, but there are only two ways how a guarantee can be provided:
- reserving desired amount in advance
- limiting consumers to keep some amount free
The first way has the followong disadvantages:
- reserving is impossible for certain resources
- such resources as CPU time, disk or network bandwidth and similar can not be just reserved as theirs amount instatntly increases;
- reserving is essentially a limit, but much more strict
- cutting off X megabytes from RAM implies that all the rest groups are limited in theis RAM consumption;
- reserving reduces containers density on the node
- if one wants to run some identical containers each requiring 100Mb on 1Gb system reservations can be done for 10 only and starting the 11th becomes impossible.
On the other hand limiting of containers can provide guarantees for them as well.
Providing a guarantee through limiting
The idea of getting a guarantee is simple:
For Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle N} groups in the system this implies solving a linear equation set to get limits Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle L_i} like this:
In a matrix form this looks like
where
and thus the solution is
Skipping boring calculations, the reverse matrix Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle A^{-1}}
is
This solutions looks huge, but the Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle L} vector is calculated in Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle O(N)} time:
void calculate_limits(int N, int *g, int *l)
{
int sum;
sum = 0;
for (i = 0; i < N; i++)
sum += g[i];
for (i = 0; i < N; i++)
l[i] = sum - (R - g[i]) - (N - 2) * (R - g[i]);
}