Search
Windows Server

SQL Server 2012 in a Virtual Environment: Managing Contention

First published Rewritten 2 min readBy Programming4us Editorial Team

Running SQL Server 2012 on Hyper-V or VMware works well, but a virtual machine shares physical resources with other VMs. When those resources are overcommitted, SQL Server slows down in ways that are hard to see from inside the guest.

CPU contention

Hypervisors let you give VMs more virtual CPUs in total than the host has physical cores. When too many vCPUs want to run at once, they wait.

  • In VMware, watch CPU Ready time; sustained values above a few percent per vCPU hurt query performance.
  • In Hyper-V, watch Hyper-V Hypervisor Virtual Processor\CPU Wait Time Per Dispatch.
  • Don't give a SQL Server VM more vCPUs than it needs; wide VMs can wait longer to be scheduled.
  • Keep a VM within one NUMA node when possible, or expose virtual NUMA that matches the host.

Memory contention

Memory overcommitment is the most damaging for SQL Server, which uses memory as cache.

  • Ballooning (VMware) or Dynamic Memory (Hyper-V) can take memory away from SQL Server, causing buffer pool shrinkage and more disk reads.
  • For production SQL Server VMs, use memory reservations (VMware) or static memory (Hyper-V) equal to the VM size.
  • Set SQL Server's max server memory to leave room for Windows, and consider Lock Pages in Memory.

Storage contention

Many VMs on the same datastore or LUN compete for I/O.

  • Monitor latency inside SQL Server with sys.dm_io_virtual_file_stats and at the hypervisor level.
  • Separate data, log and tempdb onto different virtual disks and, for busy servers, different datastores.
  • Use paravirtual SCSI controllers (PVSCSI on VMware) and fixed-size or eager-zeroed disks for performance.

Network contention

Backups and replication traffic can saturate shared physical NICs. Use separate virtual networks or QoS for backup traffic.

Monitoring both layers

SQL Server sees only its virtual world. A query slow because of CPU Ready time looks like ordinary CPU pressure inside the guest. Always correlate SQL Server wait statistics with host-level metrics, and agree with the virtualization team on reservations for database VMs.

Today's equivalent

The same principles apply to current SQL Server versions on Hyper-V, VMware and cloud VMs. In Azure, choosing memory-optimized VM sizes and Premium SSD v2 or Ultra Disk addresses many of these issues.