Tuesday, January 26, 2016

Automated configurations:
In today’s cloud computing, the unit of compute and storage offering is a virtual machine. Although limited in the cpu power and hard disk, a virtual machine suffices as a platform to host several applications, services and their workloads. However, cloud computing taught us to make the application more modular and host each in their own virtual machine. This poses two new requirements – we need more compute and storage and we need a container around these. We solved some of these with being able to create clusters and with  such as docker. However, clusters often are homogeneous in their constituents and dockers enable application isolation rather than compute and storage containers.
There is another challenge as well in that we cannot use cloud computing for storage of confidential or private data. This we have worked around so far by hosting storage solutions external to the cloud such as a database server with encryption and a massive disk to support. In other cases, we have even looked at providing trusted computing on specialized hardware. But data and logs are not the only things persisted and they cannot be even always secured on common servers unless they go to their own database and log indexes. Many times we don’t even have maintenance on these shared solutions or feedback cycle to improve the resource utilization.
This is where I propose a set of configurations I call templates that consists of a set of VMs each earmarked for a purpose. For example, we can take a set where one VM is designated ‘app1’ and hosts applications, another designated ‘app2’ also hosts applications, one designated as data1 for data storage, one dedicated as cache1 for cache and one designated as ‘message queue’ server etc. Templates vary in their size and configurations and are formed by eliciting patterns from existing virtual machine usages for a cloud that caters to many users.
Templates then become a unit of distribution and like the virtual machines they can be added and released. Template differ from so called ‘projects’ or other forms of containers in that they are pre-build, preloaded and come configured with a topology and software. The way we build and roll out templates are similar in nature to the way we build images. Images are central to how VMs are cut and released to end-users. Templates too can be used to create instances and assigned to users.
#coding exercise
N points are given on a plane that need to be covered with

K squares that are symmetrical, aligned to the coordinate axes and can overlap. What is the minimum length of an edge of the square ?
We know that N cannot be  less than K
If N == K, then the square lengths are known and nothing needs to be done.
if N > K, there will be some points that share the same square. 
Our task is to put the points within the squares.
Let us take a look at how to put points within the square

assume left[K], right[K], top[k] and bottom[k] to give the boundaries of the i'th-square of k-squares
int placePointInSquare(int i, int x, int y)
{
int newSize = 0;
int origleft = left[i];
int origright = right[i];
int origtop = top[i];
int origbottom = bottom[i];
left[i] = Math.min(origleft, x);
right[i] = Math.max(origright, x);
top[i] = Math.max(origtop, y);
bottom[i] = Math.min(origbottom, y);
newSize = Math.max(right[i]-left[i], top[i]-bottom[i]);
return newSize;
}
Initially we form a square one points with left=right=x and top=bottom=y and then we can add more points to it.
The idea in the above function is merely that we update based on both x and y axis.
The groups of K can be formed with combinations. We know combinations is recursive - an example of combining k elements from n is given by the combine() method as below

Combinations of  a string
Void Combine (List<point> a, List<point> b, int start, int level)
{

   For (int I  = start ; I < a.Length; i++)
   { 
       If (b.Length == a.Length) print b;
       b[level] = a[i];
       Print b.ToString();
       If (I < a.Length)
            Combine(a,b, start+1,level+1)
       B[level] = NULL;
   }
}
However, in this case we have to distribute n elements into k squares.
we do this with Stirling numbers of the second kind which can be defined recursively as :
s2(n,k) = 1, if n > 0 and k = 1
            = n * s2 (1,1), if n = k
            = k * s2(n-1) + s2(n-1, k-1), 0 < k < n
 This recurrence formula follows from the enumerations.
For example,
Thus if A {1, 2, 3, 4} and k 2 we would get the following subsets:

{1, 2, 3}, {4}


{2, 3, 4}, {1}


{1, 3, 4}, {2}

{1, 2, 4}, {3}

{1, 2},{3, 4}

{1, 3},{2, 4}

{1, 4},{2, 3}

 
In other words, we can combine the elements to form different lengths and take the Cartesian product of the combinations of lengths as above.

When we create different subsets of k from the n points, for each arrangement we can find out the newSize - one for each of the k subsets in the arrangement and choose the max from all the k subsets.

For this arrangement we have this resulting size of the squares available.
Similarly from each enumeration from the Stirling number, we can calculate the resulting size of square. Finally we choose the minimum resulting size from all such enumerations.

No comments:

Post a Comment