Tuesday, November 8, 2016

Yesterday we  comparing Linux Containers with virtual machines and cited ongoing efforts such as with Kubernetes. Windows Azure now claims to support Kubernetes. Native Containers are small and fast. They have two characteristics. First the containers are isolated from each other and from the host in that they even have their own file system. which makes it portable across cloud and os distributions. Second the immutable container images can be created at build/release time rather than the deployment time of the application since each application doesn't need to be composed with the rest of the application stack nor tied to the production infrastructure environment. Kubernetes extends this idea of app+container all the way where the host can be nodes of a cluster. Kubernetes evolved as an industry effort from the native Linux containers support of the operating system.  It can be considered as a step towards a truly container centric development environment. Containers decouple applications from infrastructure which separates dev from ops. Containers demonstrate better resource isolation and improved resource utilization.
At this point it is important to differentiate Kubernetes from PaaS.  Kubernetes is not a traditional, all-inclusive PaaS. Unlike PaaS that restricts applications, dictates choice of application frameworks, restrict supported language runtimes or distinguish apps from services, Kubernetes aims to support an extremely diverse variety of workloads. As long as the application has been compiled to run in a container, it will work with Kubernetes. PaaS provides databases, message bus, cluster storage systems but those can run on Kubernetes. There is also no click to deploy service marketplace. Kubernetes does not build user code or deploy it. However it facilitates CI workflows to run on it.
Kubernetes allows users to choose logging, monitoring and alerting Kubernetes also does not require a comprehensive application language or system. It is independent of machine configuration or management. But PaaS can run on Kubernetes and extend its reach to different clouds.
#codingexercise
Find the modulus of very large numbers represented as (base^exp)%m
Modulus is distributive
(a*b)%m = ((a%m)(b%m))%m
(a+b)%m = ((a%m) + (b%m))%m
int modulus(int base, int exp, int m)
{
// assume parameter validation
base %= m;
int result = 1;
while (exp > 0)
{
 if (exp & 1)
     result = (result * base) % m;
 base = (base*base) % m;
 exp >> = 1;
}
return result;
}

Alternatively we can compute the operand first before the modulus
int power( int base, uint exp)
{
int result = 1;
while (exp > 0)
{
   if (exp & 1)
      result = result * base;
   base = base * base;
   exp = exp >> 1; // reduce exp by half
}
return result;
}
Then
int modulus( int operand, uint m)
{
var digits = operand.toString();
int remainder = 0;
for (int i = 0; i < digits.length; i++)
      remainder = (remainder * 10 + digits[i].toInt()) % m
return remainder;
}

And now we can also make this recursive by splitting
Int moduluswhole(int number, m)
{
// or make it recursive with a termination condition.
return (modulus(number/2, m)  + modulus(number - (number/2), m))%m;
}

Int modulusWhole(int operand, int m)
{
If (operand < 10000)
{
 return modulus(operand, m);
}
return (modulus(operand/2, m)  + modulus(operand- (operand/2), m))%m
}

https://github.com/ravibeta/PythonExamples/blob/master/iamapi.zip 

No comments:

Post a Comment