Dynamic Resource Management for Application Containers
App container resource management is crucial, especially to help with optimization. Here's a look at resource allocation and deallocation, with a focus on Host Auto-Scaling.
Join the DZone community and get the full member experience.Join For Free
nirmata provides multi-cloud container services for enterprise devops teams. nirmata is built to leverage infrastructure as a service (iaas) providers, for dynamic allocation and deallocation of resources. in this post, i will discuss a nirmata feature that helps you optimize your cloud resource usage: host auto-scaling.
host groups and policies
a core principal in nirmata is to directly leverage cloud provider constructs, and not attempt to hide or abstract away the underlying infrastructure services. nirmata supports multiple public or private cloud providers and makes it easy to define pools of compute resources using a construct called host groups. for example, you can define an openstack cloud provider, and created several host groups each with a unique machine template and settings for security, networking, and storage.
in nirmata, policies are used to map compute, network, and storage resources to applications and services. to auto-scale hosts, you can define host scaling rules that will control how your host groups will scale-up, or down, based on the runtime characteristics of your services. one nice aspect of this, like most features provided by the nirmata platform, is that it works on any supported cloud provider: aws, digital ocean, vcloud air, openstack, cisco metapod and vmware’s vsphere.
let’s take a look at this in action…
host scaling policy configuration
to demonstrate this feature, we are going to start with an openstack host group with only one host instance (a virtual machine). this instance has 3,953 mb of memory available and is not running any containers.
in order to enable auto-scaling on this host group, you have to create a host scaling rule. there are 3 easy steps to create a scaling rule:
provide a user-friendly name for the rule and select one or multiple host groups to which this rule will apply. in our case, we select the ‘ openstack-hostgroup ’.
next, you can now define the condition that will trigger a host to be added to this host group.
this rule specifies that a new host must be created when the memory allocated across all the hosts of the host group exceeds 80% for more than a minute. under this condition, nirmata will keep adding hosts to this host group till it reaches a size of 10 hosts.
since we are starting with only one host with 3,953 mb of memory, a second host will be automatically created when the first host reaches 3,162 mb of memory allocated.
finally, you can define when hosts can be removed from the host group(s).
this condition specifies that an empty host can be removed from this host group when the total memory allocated is below 60% for more than a minute.
the percentage of memory allocated in the host group is computed without taking into account the host that we want to remove. for instance, let’s assume we have a host group with the following hosts:
- host 1: total memory=1000 mb, allocated memory=700 mb
- host 2: total memory=1000 mb, allocated memory=700 mb
- host 3: total memory=1000 mb, allocated memory=0 mb
host 3 cannot be removed because the host group memory usage without host 3 would be (700+700)*100/(1000+1000) = 70%.
now, let’s see how this host group will scale up automatically when we deploy and scale an application. to illustrate this behavior, we are going to use a simple ‘hello world’ application composed of only one service. here is the blueprint of this application:
the two pieces of information that are important for our test are:
- the size of the container required to run this service is 256 mb
- we use a dynamically allocated host port, so multiple service instances can run on the same host.
we can now deploy this application on our openstack host group:
after deploying the hello world application, we can take a look at the host group view to observe how much memory is now in use:
we can see that we are running 1 container and that this container occupies 6.5% of the host group memory.
going back to the environment running our application, we can now start scaling the application. let’s add 11 more service instances of our hello-world service:
eleven services are added to the environment:
since we haven’t crossed the threshold of 80%, there is no host created yet. however, if we add one more hello-world service instance to our environment then we can see that a new host is added to the host group.
in order to understand when an empty host can be removed from a host group, there are two important points to consider:
- container removal strategy
- memory usage computation
container removal strategy
when you are scaling down your application, nirmata must decide which containers should be removed first. the strategy depends on whether or not you have configured a host scaling rule.
if you haven’t configured a host scaling rule, nirmata will pick a container running on the most loaded host. this strategy is applied to guaranty that your services are evenly distributed across your hosts.
if you have configured a host scaling rule, nirmata will deduce that you favor minimizing your cloud resource usage and, therefore, it will pick a container running on the least loaded host. this strategy is applied to free-up a host as soon as possible.
let’s consider the following example:
if we disable the host scaling rule, and then scale down the number of services of our application from 16 to 15, then nirmata will remove one container from the host running 15 containers (ip=192.168.1.96).
if we do the operation with the host scaling rule enabled then nirmata will remove one container from the host running 2 containers (ip=192.168.1.101)
memory usage computation
the computation of the host group usage is not based on the current usage but rather on the usage that will result from removing an empty host. let’s consider the following example:
we can see that there is an empty host and the current memory usage is 42%. since we configured a host scaling rule with a threshold of 60% one could expect the host to be removed. this is not the case because removing the host would cause the host group usage to jump back to 84% which is obviously higher that our scale down threshold of 60%. in this particular case, we have to scale down the application down to 9 containers to see the host being removed.
host auto-scaling provides a powerful, easy to use, and fully automated way of optimizing the usage of your cloud resources. we’ve designed and implemented this feature working with our customers. however, there is more to come. we will soon be releasing container level auto-scaling as well as various container re-balancing strategies.
we would love to hear your feedback on these features or anything else that could help you manage application containers across clouds.
Published at DZone with permission of Jim Bugwadia, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.