Open main menu

OpenVZ Virtuozzo Containers Wiki β

Difference between revisions of "Containers/Guarantees for resources"

< Containers
 
m (Protected "Containers/Guarantees for resources" ([edit=autoconfirmed] (indefinite) [move=autoconfirmed] (indefinite)))
 
(22 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 +
[[Category:UBC]]
 +
[[Category:Containers]]
 +
 
This page describes how guarantees for resources can be implemented.
 
This page describes how guarantees for resources can be implemented.
  
 
= How to guarantee a guarantee =
 
= 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'':
+
It's not obvious at the first glance, but ''there are only two ways of how a guarantee can be provided'':
# reserving desired amount in advance
+
# reserve desired amount in advance
# limiting consumers to keep some amount free
+
# limit consumers to keep some amount free
  
 
The first way has the followong disadvantages:
 
The first way has the followong disadvantages:
; reserving is impossible for certain resources
+
; Reservation 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;
+
: such as CPU time, disk or network bandwidth and similar can not be just reserved as their amount instantly increases;
  
; reserving is essentially a limit, but much more strict
+
; Reserved amount 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;
+
: cutting off X megabytes from RAM implies that all the rest groups are limited in their RAM consumption;
  
; reserving reduces containers density on the node
+
; Reservation reduces containers density
: 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.
+
: if one wants to run some identical containers, each requiring 100Mb on 1Gb system, reservations can be done for only 10 containers, and starting the 11th is impossible.
  
On the other hand ''limiting'' of containers can provide guarantees for them as well.
+
On the other hand, ''limiting'' of containers can provide guarantees for them as well.
  
 
= Providing a guarantee through limiting =
 
= Providing a guarantee through limiting =
Line 37: Line 40:
  
 
<center><math>
 
<center><math>
A L = G
+
A L = G\;
 
</math></center>
 
</math></center>
  
Line 59: Line 62:
  
 
<center><math>
 
<center><math>
L = A^{-1}G
+
L = A^{-1}G\;
 
</math></center>
 
</math></center>
  
  
Skipping boring calculations, the reverse matrix <math>A^{-1}</math> is
+
Skipping boring calculations, the reverse matrix <math>A^{-1}\;</math> is
  
 
<center><math>
 
<center><math>
Line 75: Line 78:
 
{
 
{
 
         int sum;
 
         int sum;
 +
        int i;
 +
 +
        if (N == 1) {
 +
                l[0] = R;
 +
                return;
 +
        }
  
 
         sum = 0;
 
         sum = 0;
 
         for (i = 0; i < N; i++)
 
         for (i = 0; i < N; i++)
                 sum += g[i];
+
                 sum += R - g[i];
 
         for (i = 0; i < N; i++)
 
         for (i = 0; i < N; i++)
                 l[i] = sum - (R - g[i]) - (N - 2) * (R - g[i]);
+
                 l[i] = (sum - (R - g[i]) - (N - 2) * (R - g[i]))/(N - 1);
 
}
 
}
 
</pre>
 
</pre>
 +
 +
== Disadvantages of this approach ==
 +
 +
This approach has only one disadvantage: O(n) time needed to start a new container.

Latest revision as of 12:43, 23 May 2011


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 of how a guarantee can be provided:

  1. reserve desired amount in advance
  2. limit consumers to keep some amount free

The first way has the followong disadvantages:

Reservation is impossible for certain resources
such as CPU time, disk or network bandwidth and similar can not be just reserved as their amount instantly increases;
Reserved amount is essentially a limit, but much more strict
cutting off X megabytes from RAM implies that all the rest groups are limited in their RAM consumption;
Reservation reduces containers density
if one wants to run some identical containers, each requiring 100Mb on 1Gb system, reservations can be done for only 10 containers, and starting the 11th is 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:

if any group   requires a   units of resource from   units available then limiting all the rest groups with   units provides a desired guarantee

For   groups in the system this implies solving a linear equation set to get limits   like this:

 

In a matrix form this looks like

 

where

 


and thus the solution is

 


Skipping boring calculations, the reverse matrix   is

 

This solutions looks huge, but the   vector is calculated in   time:

void calculate_limits(int N, int *g, int *l)
{
        int sum;
        int i;

        if (N == 1) {
                l[0] = R;
                return;
        }

        sum = 0;
        for (i = 0; i < N; i++)
                sum += R - g[i];
        for (i = 0; i < N; i++)
                l[i] = (sum - (R - g[i]) - (N - 2) * (R - g[i]))/(N - 1);
}

Disadvantages of this approach

This approach has only one disadvantage: O(n) time needed to start a new container.