Back to Home

Fine tuning memory on demand in the cloud / Selectel Blog

selectel · memory on demand · clouds · cloud computing · xen

Fine tune memory on demand in the cloud


    News in one line: now customers can change MOD parameters from the control panel.

    A long time ago, in our mod-server, the ability to manage memory allocation parameters was implemented. This was implemented at the server level and database settings.

    ... But this was not in the web interface. The most persistent clients asked to change the settings - and we changed them manually. Stupid, huh?

    Finally, we corrected the situation - the settings of the MOD server became available to clients. Most of them are applied on the go and do not require a reboot or suspension of service.

    How Memory-on-Demand Works

    Depending on the number of running programs, a different amount of memory is required. Since memory is paid in “gigabyte-hours” (in fact, in kilobyte-nanoseconds), it is a pity to spend extra money on unused memory. But huddling in a small volume, climbing into a swap, is also not good.

    The entire MOD system consists of three components: server, database (settings) and agents.

    The agent - modd (mod daemon) is launched inside the guest machine, it writes to xenstore (a system due to which the guest system and the control system in dom0 can interact without using a network) information about the current memory status. More precisely, it simply writes data from / proc / meminfo to xenstore in data / mod_meminfo.

    The server looks at these numbers and decides whether to add memory or reduce it. The algorithm of the MOD server (in general terms): the amount of free memory is considered (we correctly consider buffers and cached), if it is more than necessary, then the memory is reduced. If less than necessary, then increase.

    Parameters that control the operation of MOD

    MOD has the following parameters:
    • hard memory limits - an absolute minimum and maximum. These limits determine the boundaries within which a change in memory capacity is possible. The presence of these boundaries is a technical limitation of the hypervisor used by us (Xen 3.4). The recommended ratio of minimum and maximum is approximately 1 to 4, maximum 1 to 8. (At extreme values ​​of the type 128MB - 48GB, you can easily get a kernel panic due to the fact that the kernel does not have its own memory to serve the theoretical limit). These limits are not MOD parameters - we combined them into one page simply because moving them to a separate place would increase confusion.
    • Jackdaw "turn on" / "turn off", it just turns off (on) MOD. If MOD is turned off, the memory is fixed at the last set value and does not change anymore.
    • "Soft limits" of memory. These limits determine the extent to which memory can be regulated. Note that these are not really “limits,” but rather a wish for memory size. If you set these numbers too small, then xen will ignore them, if you set them too large - similarly.
    • The boundaries of free memory. This is the most interesting pair of numbers - it determines how much free memory should be in the virtual machine. More precisely, similarly to the soft limit, it indicates what value the MOD server should strive for.
      These values ​​cannot be equal to zero (if you have 0 free memory, then you either go to the swap or the kernel crashes). They also cannot be equal to each other - this has a very rather specific explanation - if the limits were equal to each other, self-excited oscillations could arise (for example, we lack 8kb. Algorithm: add 16kb, remove 16kb, add 16kb, remove 16kb ...). Since when the memory is sent to the hypervisor, the guest machine cleans the memory (it would be strange to give memory along with the contents), this operation is not completely free for the client. Single memory additions / deletions take up insignificant resources; however, if the memory began to twitch back and forth constantly, this would create a stray load. The default values ​​are a minimum of 96MB, a maximum of 192MB. For the Mini template, the values ​​are 24 and 32 MB, respectively.

    If zero is written in the field (or nothing is written), then the default values ​​are used.

    Exceptions


    List of applications for which MOD is not needed. If the application is the main one on the server, the memory limits can be set the same and not torment the server in vain:
    • JRE, JEEE, Tomcat and other Java-based - java uses its own memory allocation mechanism
    • MongoDB - reads memory settings at startup, does not check and does not handle memory allocation errors


    PS Previous topic on this topic: habrahabr.ru/company/selectel/blog/99157

    Read Next