Pages

Friday, July 22, 2022

GKE - conect to kubernetes cluster and get CPU allocations

 gcloud container clusters get-credentials observability-production --region europe-west3

# Show Current Kubernetes Cluster
kubectl config current-context
 
# Show all configured Kubernetes Clusters
kubectl config get-clusters

# Get all Pods CPU limits from namespace loki
kubectl get po -n loki -o jsonpath="{.items[*].spec.containers[*].resources['limits.cpu']}

# Get all Pods CPU, RAM limits from namespace loki
 kubectl get po -n loki -o jsonpath="{.items[*].spec.containers[*].resources['limits.cpu','limits.memory']}"

 

Perl script to calculate allocated CPUs for particular namespace

 #/usr/bin/perl  
 $gcloud_auth=`gcloud container clusters get-credentials observability-production --region europe-west3`;  
 $context = `kubectl config current-context`;  
 print "Kubernetes Context: $context";  
 $cpu_line = `kubectl get po -n loki -o jsonpath="{.items[*].spec.containers[*].resources['limits.cpu']}"`;  
 print "CPU limits: $cpu_line\n";  
 my @cpu = split(' ', $cpu_line);  
 $total_cpu_cores = 0;  
 foreach (@cpu) {  
  $unit = substr($_, -1, 1);  
  if ($unit eq "m") {  
   $cpu = substr($_, 0, - 1);  
   $cpu = $cpu / 1000;  
  } else {  
   $cpu = $_;  
  }  
  $total_cpu_cores += $cpu;  
 }  
 print "Total CPU cores: $total_cpu_cores\n";  

...

Wednesday, July 6, 2022

Monolithic versus Microservices application architecture consideration

Microservices application architecture is very popular nowadays, however, it is important to understand that everything has advantages and drawbacks. I absolutely understand advantages of micro-services application architecture, however, there is at least one drawback. Of course, there are more, but let's show at least the potential impact on performance. The performance is about latency.

Monolithic application calls functions (aka procedures) locally within a single compute node memory (RAM). Latency of RAM is approximately 100 ns (0.0001 ms) and Python function call in decent computer has latency ~370 ns (0.00037 ms). Note: You can test Python function latency in your computer with the code available at https://github.com/davidpasek/function-latency/tree/main/python

Microservices application is using remote procedure calls (aka RPC) over network. Typically as REST or gRPC call over https, therefore, it has to traverse the network. Even the latency of modern 25GE Ethernet network is approximately 480 ns (0.00048 ms is still 5x slower than latency of RAM), and RDMA over Converged Ethernet latency can be ~3,000 ns (0.003 ms), the latency of microservice gRPC function call is somewhere between 40 and 300 ms. [source

Conclusion

Python local function call latency is ~370 ns. Python remote function call latency is ~280 ms. That's the order of magnitude (10^6) higher latency of micro-services application. RPC in low-level programming languages like C++ can be 10x faster, but it is still 10^5 slower than local Python function call.

I'm not saying that micro-services application is bad. I just recommend to consider this negative impact on performance during your application design and specification of application services.



Tuesday, May 3, 2022

Photon OS & Docker host installation

Start with minimal Photon OS installation

User/Group Management

useradd -m -G sudo admin

-m creates the home directory, while -G adds the user to the sudo group

usermod -aG docker admin

-aG adds the user to the additional group (docker)

passwd admin

Change user password.

chage -M 36500 root
chage -M 36500 admin
 
Change user password expiry information. It sets password expiration date to +100 years. More precisely it sets "Maximum number of days between password change" to 36500, which means never.
You can validate settings by command
chage -l admin

Set static IP address 

Official process is available here.
 
cd /etc/systemd/network/
 
# remove DHCP configuration
rm  99-dhcp-en.network
 
# configure Static IP configuration 
vi 10-static-en.network
 [Match]
Name=eth0
 
[Network]
Address=192.168.8.11/24
Gateway=192.168.8.254
DNS=192.168.4.5
 
chmod 644 10-static-en.network
 

Firewall

Allow ICMP

iptables --list
iptables -A INPUT -p ICMP -j ACCEPT
iptables -A OUTPUT -p ICMP -j ACCEPT
iptables-save > /etc/systemd/scripts/ip4save

Update OS

Update Operating System

sudo tdnf update

Configure Docker

Enable and start docker daemon

sudo systemctl enable docker
sudo systemctl start docker

Grant permissions to docker socket file

sudo chmod 666 /var/run/docker.sock

Docker-Compose Plugin

Follow instructions at https://docs.docker.com/compose/install/compose-plugin/#install-the-plugin-manually or at https://runnable.com/docker/introduction-to-docker-compose

Quick install ... be logged as admin user and run following commands

  • DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
  • mkdir -p $DOCKER_CONFIG/cli-plugins
  • curl -SL https://github.com/docker/compose/releases/download/v2.7.0/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
  • chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose