# # Copyright (c) 2014, 2019, 2022 by Delphix. All rights reserved. # Set-Variable UTF8_CODEPAGE 65001 -option readonly Set-Variable UTF8_ENCODING "System.Text.UTF8Encoding" -option readonly # Expand the width and height of the host's RawUI output buffer so that PS output does not get cut off or word wrapped $host.UI.RawUI.BufferSize = new-object System.Management.Automation.Host.Size(9999,220) # Turn on tracing # Set-PSDebug -Trace 2; Function CheckRegistryValue($pspath, $propertyname) { $exists = Get-ItemProperty -Path "$pspath" -Name "$propertyname" -ea SilentlyContinue If (($exists -ne $null) -and ($exists.Length -ne 0)) { Return $true } Return $false } Function CheckAndReportRegistryValues($pspath, $propertyname, $value) { if(-not [Boolean](CheckRegistryValue $pspath $propertyname)) { Write-Host -ForeGroundColor Red "ERROR: ${pspath}\${propertyname} entry not found." Write-Host -ForeGroundColor Red "ERROR: ${propertyname} needs to be created and set to ${value}." } else { $key = Get-ItemProperty -Path $pspath -Name $propertyname if ($key.$propertyname -ne $value) { Write-Host -ForeGroundColor Red "ERROR: ${pspath}\${propertyname}: " $key.$propertyname Write-Host -ForeGroundColor Red "ERROR: ${propertyname} needs to be set to ${value}." } elseif ($key.$propertyname -eq $value) { Write-Host -ForeGroundColor Green "CORRECT: ${pspath}\${propertyname}: " $key.$propertyname } } } # ReceiveSideScaling # Checks if Receive Side Scaling setting is enabled on the network adapter itself. RSS must be enabled on both # the adapter and on the TCP Global Parameters Function CheckRSS($interface){ if ($PSVersionTable.PSVersion.Major -ge 3) { if (Get-Module -ListAvailable -Name NetTCPIP) { $adapter = Get-NetIPAddress -IPAddress $interface $rss = Get-NetAdapterRss -Name $adapter.InterfaceAlias -ErrorAction SilentlyContinue -ErrorVariable GetAdatperError if ($rss -eq $null) { Write-Host -ForegroundColor Red "ERROR: Check network adapter under Windows Control Panel to see if it has an RSS property." Write-Host -ForegroundColor Red " " $GetAdatperError break } if ($rss.Enabled -match "True") { Write-Host -ForeGroundColor Green "Receive Side Scaling (RSS) is enabled on the specified network adapter." Write-Host } else { Write-Host -ForegroundColor Red "ERROR: Receive Side Scaling (RSS) is not enabled on the specified network adapter." Write-Host } } else { Write-Host -ForegroundColor Yellow -BackgroundColor Black "Unable to check RSS on network adapter due to missing module NetTCPIP." Write-Host -ForegroundColor Yellow -BackgroundColor Black "Run 'Install-Module -Name NetTCPIP' to install the module." Write-Host -ForegroundColor Yellow -BackgroundColor Black "Or check network adapter configuration under the Windows Control Panel." Write-Host } } else { Write-Host -ForegroundColor Yellow -BackgroundColor Black "Unable to check RSS on network adapter due to PowerShell version: " $PSVersionTable.PSVersion Write-Host -ForegroundColor Yellow -BackgroundColor Black "Need PowerShell version 3.0 or higher." Write-Host -ForegroundColor Yellow -BackgroundColor Black "Or check network adapter configuration under the Windows Control Panel." } } # This Sample Code is provided for the purpose of illustration only and is not intended to be used in a production environment. THIS SAMPLE CODE AND ANY RELATED INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. We grant You a nonexclusive, royalty-free right to use and modify the Sample Code and to reproduce and distribute the object code form of the Sample Code, provided that You agree: (i) to not use Our name, logo, or trademarks to market Your software product in which the Sample Code is embedded; (ii) to include a valid copyright notice on Your software product in which the Sample Code is embedded; and (iii) to indemnify, hold harmless, and defend Us and Our suppliers from and against any claims or lawsuits, including attorneys fees, that arise or result from the use or distribution of the Sample Code. # Author: Amit Banerjee # Purpose: Helps identify the number of physical processors, logical processors and hyperthreading on the server. # Provide the computer information function CheckHyperthreading() { $vComputerName = "." $vLogicalCPUs = 0 $vPhysicalCPUs = 0 $vCPUCores = 0 $vSocketDesignation = 0 $vIsHyperThreaded = -1 # Get the Processor information from the WMI object $vProcessors = [object[]]$(get-WMIObject Win32_Processor -ComputerName $vComputerName) # To account for older machines if ($vProcessors[0].NumberOfCores -eq $null) { $vSocketDesignation = new-object hashtable $vProcessors |%{$vSocketDesignation[$_.SocketDesignation] = 1} $vPhysicalCPUs = $vSocketDesignation.count $vLogicalCPUs = $vProcessors.count } # If the necessary hotfixes are installed as mentioned below, then the NumberOfCores and NumberOfLogicalProcessors can be fetched correctly else { # For any machine of Windows Server 2008 or above # For Windows Server 2003, KB932370 needs to be installed # For Windows XP, KB936235 needs to be installed $vCores = $vProcessors.count $vLogicalCPUs = $($vProcessors|measure-object NumberOfLogicalProcessors -sum).Sum $vPhysicalCPUs = $($vProcessors|measure-object NumberOfCores -sum).Sum } # Additional code can be written here to input the data below into a database "Logical CPUs: {0}; Physical CPUs: {1}; Number of Cores: {2}" -f $vLogicalCPUs,$vPhysicalCPUs,$vCores if ($vLogicalCPUs -gt $vPhysicalCPUs) { Write-Warning "Hyperthreading: Active" Write-Warning "RSS does not use hyper-threaded processors: " Write-Warning " https://docs.microsoft.com/en-us/windows-hardware/drivers/network/introduction-to-receive-side-scaling " Write-Host } else { Write-Host -ForeGroundColor Green "Hyperthreading: Inactive" } } Function PrintAdapterDetails($interface){ if ($PSVersionTable.PSVersion.Major -ge 3) { if (Get-Module -ListAvailable -Name NetTCPIP) { $adapter = Get-NetIPAddress -IPAddress $interface $net_adapter = Get-NetAdapter -Name $adapter.InterfaceAlias Write-Host "Driver Provider: " $net_adapter.DriverProvider Write-Host "Driver Description: " $net_adapter.DriverDescription Write-Host "Driver Version: " $net_adapter.DriverVersion Write-Host "Driver Date: " $net_adapter.DriverDate Write-Host "Interface Name: " $net_adapter.Name Write-Host "Network Link Speed: " $net_adapter.LinkSpeed Write-Host "Receive Link Speed: " $net_adapter.ReceiveLinkSpeed Write-Host "Transmit Link Speed: " $net_adapter.TransmitLinkSpeed Write-Host "MTU Size:" $net_adapter.MtuSize Write-Host } else { Write-Host -ForegroundColor Yellow -BackgroundColor Black "Unable to read advanced adapter settings due to missing PowerShell module NetTCPIP." Write-Host -ForegroundColor Yellow -BackgroundColor Black "Run 'Install-Module -Name NetTCPIP' to install the module." Write-Host -ForegroundColor Yellow -BackgroundColor Black "Or check network adapter configuration under the Windows Control Panel." Write-Host } } else { Write-Host -ForegroundColor Yellow -BackgroundColor Black "Unable to read advanced adapter settings due to PowerShell version: " $PSVersionTable.PSVersion Write-Host -ForegroundColor Yellow -BackgroundColor Black "Need PowerShell version 3.0 or higher." Write-Host -ForegroundColor Yellow -BackgroundColor Black "Or check network adapter configuration under the Windows Control Panel." Write-Host } } Write-Host -ForegroundColor DarkCyan "Delphix requires several registry settings be set to specific values in order for staging databases and" Write-Host -ForegroundColor DarkCyan "VDBs to perform optimally and to give them operational stability. Failure to update the registry" Write-Host -ForegroundColor DarkCyan "results in poor performance and can cause SQL Server to offline the databases." Write-Host Write-Host -ForegroundColor DarkCyan "In addition to the registry settings, Delphix recommends enabling Receive Side Scaling (RSS): " Write-Host -ForegroundColor DarkCyan " https://docs.delphix.com/docs/architecture-best-practices/architecture-best-practices-for-target-db-and-os-settings/receive-side-scaling-rss-for-windows-staging-target-and-targets" Write-Host Write-Host -ForegroundColor DarkCyan "This script reports the current values of the registry settings. It also prompts for an IP address" Write-Host -ForegroundColor DarkCyan "to allow setting TcpAckFrequency on a desired network interface. Some network interfaces may be used" Write-Host -ForegroundColor DarkCyan "for non-Delphix activity and users may wish to have a different setting." Write-Host Write-Host -ForegroundColor DarkCyan "The wildcard asterisk may be entered on the following prompt (10.43.5.*) in case you want to apply the" Write-Host -ForegroundColor DarkCyan "TcpAckFrequency setting to multiple network interfaces." Write-Host $strTargetNICAddress = Read-Host -Prompt 'Enter IP address to be used by Delphix' Write-Host # $strTargetNICAddress = "10.43.5.*" if ([string]::IsNullOrEmpty($strTargetNICAddress)) { Write-Host -ForegroundColor Red "ERROR: Please enter a valid IP address. The wildcard character '*' may be used." exit } # Try starting the Microsoft iSCSI Initiator Service # (if it hasn't run before the registry settings could be missing) # try { Start-Service MSiSCSI -ErrorAction SilentlyContinue -ErrorVariable iscsiServiceError } catch { Write-Host -ForegroundColor Yellow "WARNING: Unalbe to start Microsoft iSCSI Service: " $iscsiServiceError Write-Host } ###### Check iSCSI related properties ##### $TCPInterfaces = Get-ChildItem "HKLM:\system\currentcontrolset\services\tcpip\parameters\interfaces" -ErrorAction SilentlyContinue | ForEach-Object {Get-ItemProperty $_.pspath -ErrorAction Continue} # Loop through the network interfaces searching for TcpAckFrequencey, RSS and print adapter details # ForEach ($interface in $TCPInterfaces) { # Only look at the interfaces matching the user's entry AND that are not NULL # if((([string]$interface.IPAddress -like $strTargetNICAddress) -OR ([string]$interface.DHCPIPAddress -like $strTargetNICAddress)) -AND (($interface.IPAddress) -OR ($interface.DHCPIPAddress))) { Write-Host "Found IP: " $interface.IPAddress $interface.DHCPIPAddress Write-Host "NIC Registry Path: " $interface.PSPath Write-Host $IPAddress = If ($interface.IPAddress) {$interface.IPAddress} Else {$interface.DhcpIPAddress} PrintAdapterDetails($IPAddress) # Check if RSS is enabled on the matching network interfaces CheckRSS($IPAddress) $item_path = $interface.PSPath if(-not [Boolean](CheckRegistryValue $item_path "TcpAckFrequency")) { Write-Host -ForeGroundColor Red "ERROR: ${item_path}\TcpAckFrequency entry not found." Write-Host -ForeGroundColor Red "ERROR: TcpAckFrequency needs to be created and set to 1." Write-Host } else { if ($interface.TcpAckFrequency -ne 1) { Write-Host -ForeGroundColor Red "ERROR: ${item_path}\TcpAckFrequency: " $interface.TcpAckFrequency Write-Host -ForeGroundColor Red "ERROR: TcpAckFrequency needs to be set to 1." Write-Host } else { Write-Host -ForeGroundColor Green "CORRECT: ${item_path}\TcpAckFrequency: " $interface.TcpAckFrequency Write-Host } } } else { if (($interface.IPAddress) -OR ($interface.DHCPIPAddress)) { Write-Host -NoNewLine -ForegroundColor Yellow -BackgroundColor Black "WARNING: Registry entry found IP Address " Write-Host -NoNewline -ForegroundColor Yellow -BackgroundColor Black $interface.IPAddress $interface.DHCPIPAddress Write-Host -ForegroundColor Yellow -BackgroundColor Black " which does not match address entered: ${strTargetNICAddress}" Write-Host -ForegroundColor Yellow -BackgroundColor Black "Run 'ipconfig /all' to confirm IP address entered. Ignore this warning if correct IP address was entered." Write-Host } } } Write-Host ###### Check iSCSI related properties ##### $SCSIAdapters = Get-ChildItem "HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4D36E97B-E325-11CE-BFC1-08002BE10318}" -ErrorAction SilentlyContinue | ForEach-Object {Get-ItemProperty $_.pspath -ErrorAction Continue} ForEach ($provider in $SCSIAdapters) { if ($provider.DriverDesc -eq "Microsoft iSCSI Initiator"){ $iscsi_path = $provider.PSPath Write-Host "iSCSI initator path: " ${iscsi_path} Write-Host Break } } if (-not $iscsi_path) { Write-Host -ForegroundColor Red "ERROR: Unable to find Microsoft iSCSI Initiator registry path. Service may not be running." Write-Host -ForegroundColor Red "ERROR: Try restarting the Microsoft iSCSI Initiator service." Write-Host } else { $path = "$iscsi_path\Parameters" # iSCSI iSCSIDisableNagle # Description: Disable nagle # CheckAndReportRegistryValues $path "iSCSIDisableNagle" 1 Write-Host # iSCSI MaxRequestHoldTime # Description: Maximum time (in seconds) for which requests will be queued if connection to the target is lost and # the connection is being retried. After this hold period, requests will be failed with "error no device" and device # (disk) will be removed from the system. # CheckAndReportRegistryValues $path MaxRequestHoldTime 300 Write-Host } # iSCSI MaxRequestHoldTime # Description: Maximum time (in seconds) for which requests will be queued if connection to the target is lost # and the connection is being retried. After this hold period, requests will be failed with "error no device" # and device (disk) will be removed from the system. # CheckAndReportRegistryValues "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\iSCSI\Discovery" MaxRequestHoldTime 900 Write-Host # iSCSI TimeOutValue # CheckAndReportRegistryValues "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Disk" TimeOutValue 900 Write-Host # ReceiveSideScaling - Global TCP Parameters # Checks the TCP Global Parameters to see if Receive Side Scaling settings on the computer. # Receive Side Scaling distributes the network processing load across multiple processor cores. # In order for RSS to be active, it needs to be enabled globally on the Windows host and on the adapter itself. # if ($PSVersionTable.PSVersion.Major -ge 3) { if (Get-Module -ListAvailable -Name NetTCPIP) { $rss = Get-NetOffloadGlobalSetting if ($rss.ReceiveSideScaling -match "Enabled") { Write-Host -ForeGroundColor Green "Receive Side Scaling (RSS) is enabled in the TCP Global Parameters." Write-Host } else { Write-Host -ForegroundColor Red "ERROR: Receive Side Scaling (RSS) is not enabled in the TCP Global Parameters." Write-Host } } else { Write-Host -ForegroundColor Yellow -BackgroundColor Black "Unable to check Global TCP RSS setting via Get-NetOffloadGlobalSetting due to missing module NetTCPIP." Write-Host -ForegroundColor Yellow -BackgroundColor Black "Run 'Install-Module -Name NetTCPIP' to install the module." Write-Warning "Running 'netsh interface tcp show global' instead: " Invoke-Command -ScriptBlock {netsh interface tcp show global} Write-Host } } else { Write-Host -ForegroundColor Yellow -BackgroundColor Black "Unable to check Global TCP RSS setting via Get-NetOffloadGlobalSetting due to PowerShell version: " $PSVersionTable.PSVersion Write-Host -ForegroundColor Yellow -BackgroundColor Black "Need PowerShell version 3.0 or higher." Write-Warning "Running 'netsh interface tcp show global' instead: " Invoke-Command -ScriptBlock {netsh interface tcp show global} Write-Host } $hostinfo = Get-WmiObject -query 'select * from Win32_ComputerSystem' if ([string]$hostinfo.Manufacturer -like "Microsoft Hyper-V" ) { Write-Warning "Hypervisor is :" $hostinfo.Manufacturer Write-Warning "Microsoft recommends enabling vRSS on Hyper-V VMs:" Write-Warning " https://docs.microsoft.com/en-us/windows-server/networking/technologies/vrss/vrss-top" } CheckHyperthreading # Turn off tracing #Set-PSDebug -Trace 0;