Monday, 17 February 2014

Objective 3.2 – Optimize Virtual Machine Resources

Knowledge - Compare and contrast virtual and physical hardware resources
Virtual hardware resources are abstracted by the software so have a slight performance disadvantage over direct physical.  Although direct physical access can be given to VM by way of pvSCSI, RDM, DirectPath IO etc.

Virtual hardware gives flexibility of being hardware independent allowing the VM to move between hosts,  sites etc to move load and avoid downtime.

Knowledge - Identify VMware memory management techniques
Unused memory recovery, hosts allocate memory to virtual machines based on their most recent working set size and relative shares to the resource pool. The working set size is monitored for 60 seconds (default period). This interval can be changed by modifying the advanced setting Mem.SamplePeriod.

Transparent Page Sharing (TPS) allows common memory pages are written once and referenced many. You can set advanced settings per-host to specify a custom interval of how often the host scans for memory and host much CPU resources to consume doing it. Those two settings are Mem.ShareScanTime (default 60 minute) and Mem.ShareScanGHz (default 4).

Memory Compression has a performance impact but is a technique that is used before pages start getting swapped to disk. Memory pages that can be condensed into 2KB or less are stored in what’s called the virtual machine’s compression cache. You can set the maximum size of the compression cache with the Mem.MemZipMaxPct advanced setting. The default is 10%. If you want to enable/disable memory compression us the Mem.MemZipEnable advanced setting. Use the value 0 to disable and 1 to enable.

Memory ballooning uses the memory balloon driver (vmmemctl) which is loaded into the guest operating system as part of the VMware tools. When memory pressure exists the balloon driver determines the least valuable pages and swaps them to the virtual disk of the virtual machine. Once the memory is swapped to virtual disk, the hypervisor can reclaim that physical memory that was backing those pages and allocate it elsewhere. Since ballooning is performing swap to virtual disk, there must be sufficient swap space within the guest operating system.

There are now two types of swap to disk mechanism; swap to disk and swap to host cache. Swapping to disk is the same as it’s been in previous versions; a swap file is created (by default in the same location as the virtual machine’s configuration file) during power-on and during times of memory contention, if ballooning doesn’t slow/stop contention or the balloon driver isn’t working or available, swapping to disk occurs. Alternatively, for swap file location, you can change this per-VM, per-host, or specify a datastore for an entire cluster

Swap to Host cache is new it, you have a datastore that lives on an SSD, you can designate space on that datastore as host cache. Host cache acts as a cache for all virtual machines on that particular host as a write-back storage for virtual machine swap files. What this means is that pages that need to be swapped to disk will swap to host cache first, and the written back to the particular swap file for that virtual machine.


Knowledge - Identify VMware CPU Load Balancing Techniques
CPU affinity can be used to restrict a VM to a CPU or set of CPU, by tying a VM to CPU can restrict the VM and also the clusters ability to assign shares and reservations.

Hosts take advantage of all physical CPU and there cores,  these are managed by the CPU scheduler.  The CPU scheduler default is to load balance across all available socket and cores. Using "sched.cpu.vsmpConsolidate = True" on a VM will prevent its workload from being spread across and limit it to same socket.

If the CPU supports hyper threading, enable it in the BIOS, this allows a single core to run multiple threads,  however it is still only a single core so take care when assigning CPU affinity on systems with hyper threading enabled so you don't tie two to the same core.

If your hosts support and are configured for NUMA you need to be aware that memory in NUMA systems the memory bus is linked to the CPU,  despite this all memory can be accessed from anywhere but the cost of working with the memory is variable.  There is a NUMA scheduler and when a VM is allocated memory it takes its locality into account and attempts to select the closest memory to CPU. If memory and CPU get pressured this can lead the scheduler to dynamically load balance the memory pages.

Knowledge - Identify pre-requisites for Hot Add features
Admin Guide link
  • For best results, use hardware version 8 virtual machines.
  • Hot-adding multicore virtual CPUs is supported only with hardware version 8 virtual machines.
  • Not all guest operating systems support CPU hot add. You can disable these settings if the guest is not supported.
  • To use the CPU hot-add feature with hardware version 7 virtual machines, set Number of cores per socket to 1.
  • Adding CPU resources to a running virtual machine with CPU hot plug enabled disconnects and reconnects all USB passthrough devices connected to that virtual machine.
Configuration Prerequisites
  • Verify that the virtual machine is running under the following conditions:
  • VMware Tools is installed. This condition is required for hot plug functionality with Linux guest operating systems.
  • The virtual machine has a guest operating system that supports CPU hot plug.
  • The virtual machine is using hardware version 7 or later.
  • The virtual machine is powered off.
Skills and Abilities - Tune Virtual Machine Memory Configuration
We should always aim to right size a VM memory, to right size it, gather as much information about a servers workload before you provision a VM.  Once you have been running for a while,  ensure VM has enough memory is not experiencing any memory swapping by using esxtop.  Also ensure that the memory is not allocated too much memory than it requires.

As well as aiming to right size all your VMs memory,  you can use memory shares to manage which VMs have presidency on the physical memory.

If VM memory swapping to disk is unavoidable for some reason you can use a SSD in your ESXi host to provide a vswp host cache.


Skills and Abilities - Tune Virtual Machine Networking Configuration
Where possible use the paravirtualized network adapter, VMXNET3 adapter

When a Windows virtual machine in vSphere 5.1 transmits UDP packets larger than 1024 bytes, you experience lower than expected or oscillating throughput even when other traffic is negligible. In case of a video streaming server, video playback freezes.  If the Windows virtual machine has a VMXNET3 vNIC adapter, configure the VM see here for details.
 
Skills and Abilities - Tune Virtual Machine CPU Configuration
As with memory,  the aim is always to right size your VM so provide at time of provision your best estimate on how many vCPU your VM will use. If your application or guest OS can’t leverage multiple processors then configure them with only 1 vCPU. When it has been running check it has enough CPU.

If your physical hosts are NUMA capable, ensure the virtual machines are hardware version 8.  This exposes the NUMA architecture to the guest operating systems and allows guest to take advantage (vNUMA).

Skills and Abilities - Tune Virtual Machine storage configurations
Where possible map a single OS guest volume to a single VMDK file,  this will allow you to grow and skrink volumes to enable right sizing,  it will also allow you to place volumes with a particular characteristic to be placed on SAN disk of the best attributes to take advantage of deduplication etc.

Consider using the paravirtualized SCSI (PVSCSI) adapter, the PVSCSI adapter can provide higher throughput and lower CPU utilization.

Ensure your guest OS block size is aligned to that of your SAN disk,  see link

Skills and Abilities - Calculate available resources  
In vSphere 5 there are many visualizations within the GUI that will show you what the available resources are for a cluster, host or a virtual machine. You can also determine available resources for a host using esxtop.

Quick and easy to view CPU and memory is to use DRS: Resource Distribution Chart


Be careful with datastore usage,  SAN techniques such as thin \ over provisioning are not displayed to vCenter fully unless you use SAN vendor vCenter plugins.

Skills and Abilities - Properly size a Virtual Machine based on application workload
To properly size a virtual machine view the software vendors details on resources it requires to set the initial VM parameters,  but also review once it is running memory and CPU to ensure it has enough but isn't over resourced,  both ways lead to inefficiency.

Skills and Abilities - Modify Large Memory Page Settings
See details here

Skills and Abilities - Understand appropriate use cases for CPU affinity
CPU affinity should only be used when necessary, such as
            Simulating a workload
            Load testing for an application

If you are using NUMA hardware, the NUMA scheduler may not be able to manage virtual machine with CPU affinity, essentially disabling NUMA for that virtual machine.

Hyperthreaded enabled hosts may not be able to fully leverage hyperthreading on a virtual machine with CPU affinity

Reservations and shares may not fully be respected for a virtual machine configured for CPU affinity

CPU affinity might not exist for a virtual machine across all hosts in a cluster during a migration

Skills and Abilities - Configure alternate virtual machine swap locations
Virtual machine swap file location can be set on each VM or at the host level.

Cluster Level


Host Level

VM Level

No comments:

Post a Comment