Virtual Machine with performance degraded

Scenario

In this scenario, a Virtual Machine named exercise4 is currently in a running state. The development team has reported performance issues with an application hosted on this VM.

Your task is to investigate the problem by analyzing the VM’s resource usage, including CPU, memory, and other relevant metrics. You are permitted to adjust the VM’s compute resources as needed to resolve the issue; however, a reboot is not permitted.

  • The goal is to identify bottlenecks or misconfigurations and implement optimizations to enhance the application’s efficiency within the virtualized infrastructure.

  • Do not kill any process running inside the virtual machine

  • Do not reboot the virtual machine

The steps to fix exercise4 are:

Console

  1. Login to OpenShift console using the assigned user account.

Username
userx
Password
{password}
  1. Go to Virtualization - VirtualMachines - Select the project for the assigned user account

04 break03
  1. Go to Virtual Machine details and check the resources being consumed and the Virtual Machine number of CPU’s

04 break04
  1. Click Configuration tab and change the CPU | Memory

04 break05
  1. Change the number of CPU’s from 2 to 4 and click Save

04 break06
  1. Verify the number of CPU’s has been changed from 2 to 4.

04 break07
Run grade to validate the exercise
lab grade exercise4

Command line (CLI)

  1. Login to Openshift server API using the assigned user account with oc command if not logged in.

OpenShift login command
{login_command}
  1. Go to the assigned namespace-userx

oc project namespace-userx
  1. List the virtual machines

oc get virtualmachine
NAME        AGE     STATUS    READY
exercise4   3m29s   Running   True
  1. List the pods

oc get pods
NAME                            READY   STATUS    RESTARTS   AGE
virt-launcher-exercise4-lb66m   1/1     Running   0          3m41
  1. Check the number of CPU’s

oc get vm exercise4 -n namespace-userx \
-o jsonpath='{.spec.template.spec.domain.cpu}'
{"cores":1,"sockets":2,"threads":1}
  1. Validate this information within OS virtual machine

virtctl ssh lab-user@exercise4 -c 'lscpu | grep Socket'
Warning: Permanently added 'vmi/exercise4.namespace-userx' (ED25519) to the list of known hosts.
2
  1. Check the virtual machine is using almost 100% CPU

oc adm top pods
NAME                            CPU(cores)   MEMORY(bytes)
virt-launcher-exercise4-lb66m   1993m        1224Mi
  1. change the virtual machine sockets from 2 to 4

oc patch vm exercise4 -n namespace-userx --type='json' \
-p='[{"op": "replace", "path": "/spec/template/spec/domain/cpu/sockets", "value": 4}]'
  1. check the virtual machine is now running with 4 sockets

oc get vm exercise4 -n namespace-userx \
-o jsonpath='{.spec.template.spec.domain.cpu}'
{"cores":1,"sockets":4,"threads":1}
  1. Validate this information within OS virtual machine

virtctl ssh lab-user@exercise4 -c 'lscpu | grep Socket'
Warning: Permanently added 'vmi/exercise4.namespace-userx' (ED25519) to the list of known hosts.
4
  1. Command to check the CPU usage on Virtual Machine

virtctl ssh lab-user@exercise4 \
--command "top -b -n 1 | grep 'Cpu(s)' | awk '{print \$2 \"% Used\"}'"

What you learned

In this exercise, you learned that when working with a RHEL 9 virtual machine, there is no need to shut down or reboot the VM to modify the CPU configuration. Instead, you can perform a CPU hotplug operation while the VM is running.