Skip to content

Commit

Permalink
MaxDopInstance added and tested #882
Browse files Browse the repository at this point in the history
  • Loading branch information
SQLDBAWithABeard committed Apr 27, 2022
1 parent b073c19 commit 5706f31
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 11 deletions.
17 changes: 15 additions & 2 deletions Perf Testing pesterv5.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ ipmo ./dbachecks.psd1

#

$Checks = 'ModelDbGrowth','DefaultBackupCompression','SaExist','SaDisabled','SaRenamed','DefaultFilePath','AdHocDistributedQueriesEnabled','AdHocWorkload', 'DefaultTrace', 'OleAutomationProceduresDisabled', 'CrossDBOwnershipChaining', 'ScanForStartupProceduresDisabled', 'RemoteAccessDisabled', 'SQLMailXPsDisabled', 'DAC', 'OLEAutomation'
$Checks = 'ErrorLogCount'
$Checks = 'MaxDopInstance','ErrorLogCount','ModelDbGrowth','DefaultBackupCompression','SaExist','SaDisabled','SaRenamed','DefaultFilePath','AdHocDistributedQueriesEnabled','AdHocWorkload', 'DefaultTrace', 'OleAutomationProceduresDisabled', 'CrossDBOwnershipChaining', 'ScanForStartupProceduresDisabled', 'RemoteAccessDisabled', 'SQLMailXPsDisabled', 'DAC', 'OLEAutomation'
$Checks = 'MaxDopInstance'
Compare-CheckRuns -Checks $checks

<#
Expand All @@ -28,7 +28,20 @@ Get-DbcConfigValue skip.security.sadisabled
Set-DbcConfig skip.security.saexist -Value $false
Set-DbcConfig skip.security.saexist -Value $true
Get-DbcConfigValue skip.security.saexist
Get-DbcConfigValue policy.instancemaxdop.userecommended
Get-DbcConfigValue policy.instancemaxdop.maxdop
Get-DbcConfigValue policy.instancemaxdop.excludeinstance
Set-DbcConfig policy.instancemaxdop.userecommended -Value $false
Set-DbcConfig policy.instancemaxdop.userecommended -Value $true
Set-DbcConfig policy.instancemaxdop.maxdop -Value 0
Set-DbcConfig policy.instancemaxdop.excludeinstance -Value $null
Set-DbcConfig policy.instancemaxdop.excludeinstance -Value 'localhost,7401'
#>

# Load the function below and then you can keep running the checks defined above in v4 and v5 and compare the performance
# You can keep updating the .Tests.ps1 files and rerunning the function without needing to re-import hte module

Expand Down
16 changes: 14 additions & 2 deletions Validate v4 adn v5.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ ipmo ./dbachecks.psd1

#

$Checks = 'ModelDbGrowth','DefaultBackupCompression','SaExist','SaDisabled','SaRenamed','DefaultFilePath','AdHocDistributedQueriesEnabled','AdHocWorkload', 'DefaultTrace', 'OleAutomationProceduresDisabled', 'CrossDBOwnershipChaining', 'ScanForStartupProceduresDisabled', 'RemoteAccessDisabled', 'SQLMailXPsDisabled', 'DAC', 'OLEAutomation'
$Checks = 'ErrorLogCount'
$Checks = 'MaxDopInstance','ErrorLogCount','ModelDbGrowth','DefaultBackupCompression','SaExist','SaDisabled','SaRenamed','DefaultFilePath','AdHocDistributedQueriesEnabled','AdHocWorkload', 'DefaultTrace', 'OleAutomationProceduresDisabled', 'CrossDBOwnershipChaining', 'ScanForStartupProceduresDisabled', 'RemoteAccessDisabled', 'SQLMailXPsDisabled', 'DAC', 'OLEAutomation'
$Checks = 'MaxDopInstance'
Compare-v4andv5Results -Checks $Checks

<#
Expand All @@ -28,6 +28,18 @@ Get-DbcConfigValue skip.security.sadisabled
Set-DbcConfig skip.security.saexist -Value $false
Set-DbcConfig skip.security.saexist -Value $true
Get-DbcConfigValue skip.security.saexist
Get-DbcConfigValue policy.instancemaxdop.userecommended
Get-DbcConfigValue policy.instancemaxdop.maxdop
Get-DbcConfigValue policy.instancemaxdop.excludeinstance
Set-DbcConfig policy.instancemaxdop.userecommended -Value $false
Set-DbcConfig policy.instancemaxdop.userecommended -Value $true
Set-DbcConfig policy.instancemaxdop.maxdop -Value 0
Set-DbcConfig policy.instancemaxdop.excludeinstance -Value $null
Set-DbcConfig policy.instancemaxdop.excludeinstance -Value 'localhost,7402'
#>

# Load the function below and then you can keep running the checks defined above in v4 and v5 and compare the performance
Expand Down
18 changes: 15 additions & 3 deletions checks/Instancev5.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,22 @@ Describe "Model Database Growth" -Tag ModelDbGrowth, Low, Instance -ForEach $Ins
Describe "Error Log Count" -Tag ErrorLogCount, CIS, Low, Instance -ForEach $InstancesToTest {
$skip = Get-DbcConfigValue skip.instance.ErrorLogCount
Context "Checking error log count on <_.Name>" {
It "Error log count should be greater or equal to <_.ConfigValues.errorLogCount> on <_.Name>" -Skip:$skip{
$psitem.NumberOfLogFiles | Should -BeGreaterOrEqual $psitem.ConfigValues.errorLogCount -Because "We expect to have at least $($psitem.ConfigValues.errorLogCount) number of error log files"
It "Error log count should be greater or equal to <_.ConfigValues.errorLogCount> on <_.Name>" -Skip:$skip {
$psitem.NumberOfLogFiles | Should -BeGreaterOrEqual $psitem.ConfigValues.errorLogCount -Because "We expect to have at least $($psitem.ConfigValues.errorLogCount) number of error log files"
}
}
}


Describe "Instance MaxDop" -Tag MaxDopInstance, MaxDop, Medium, Instance -ForEach ($InstancesToTest | Where-Object { $psitem.Name -notin $psitem.ConfigValues.ExcludeInstanceMaxDop }) {
$skip = Get-DbcConfigValue skip.instance.MaxDopInstance
Context "Testing Instance MaxDop Value on <_.Name>" {
#if UseRecommended - check that the CurrentInstanceMaxDop property returned from Test-DbaMaxDop matches the the RecommendedMaxDop property
It "Instance Level MaxDop setting should be correct on <_.Name>" -Skip:$Skip -ForEach ($Psitem | Where-Object { $psitem.ConfigValues.UseRecommendedMaxDop -eq $true }) {
$psitem.MaxDopSettings.CurrentInstanceMaxDop | Should -Be $psitem.MaxDopSettings.RecommendedMaxDop -Because "We expect the MaxDop Setting to be the default recommended value $($psitem.MaxDopSettings.RecommendedMaxDop)"
}
#if not UseRecommended - check that the CurrentInstanceMaxDop property returned from Test-DbaMaxDop matches the MaxDopValue parameter
It "Instance Level MaxDop setting should be correct on <_.Name>" -Skip:$Skip -ForEach($Psitem | Where-Object { $psitem.ConfigValues.UseRecommendedMaxDop -ne $true }) {
$psitem.MaxDopSettings.CurrentInstanceMaxDop | Should -Be $psitem.ConfigValues.InstanceMaxDop -Because "We expect the MaxDop Setting to be the value you specified $($psitem.ConfigValues.InstanceMaxDop)"
}
}
}
24 changes: 20 additions & 4 deletions internal/functions/NewGet-AllInstanceInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ function NewGet-AllInstanceInfo {
$Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.LogFile], $false)
$Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.DataFile], $false)


# set the default init fields for all the tags

# Server Initial fields
$ServerInitFields = $Instance.GetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Server])
$ServerInitFields.Add("VersionMajor") | Out-Null # so we can check versions
Expand Down Expand Up @@ -117,20 +118,34 @@ function NewGet-AllInstanceInfo {

}
'ErrorlogCount' {
$ServerInitFields = $Instance.GetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Server])

$ServerInitFields.Add("NumberOfLogFiles") | Out-Null # so we can check versions
$Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Server], $ServerInitFields)
$ServerInitFields = $Instance.GetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Server]) # I think we need to re-initialise here

$ConfigValues | Add-Member -MemberType NoteProperty -Name 'errorLogCount' -Value (Get-DbcConfigValue policy.errorlog.logcount)

}
'MaxDopInstance' {
#Test-DbaMaxDop needs these because it checks every database as well
$DatabaseInitFields.Add("IsAccessible") | Out-Null # so we can check if its accessible
$DatabaseInitFields.Add("IsSystemObject ") | Out-Null # so we can check if its accessible
$DatabaseInitFields.Add("MaxDop ") | Out-Null # so we can check if its accessible
$DatabaseInitFields.Add("Name ") | Out-Null # so we can check if its accessible
$Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Database], $DatabaseInitFields)
$DatabaseInitFields = $Instance.GetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Database]) # I think we need to re-initialise here

$ConfigValues | Add-Member -MemberType NoteProperty -Name 'UseRecommendedMaxDop' -Value (Get-DbcConfigValue policy.instancemaxdop.userecommended)
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'InstanceMaxDop' -Value (Get-DbcConfigValue policy.instancemaxdop.maxdop)
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'ExcludeInstanceMaxDop' -Value (Get-DbcConfigValue policy.instancemaxdop.excludeinstance)
if ($Instance.Name -notin $ConfigValues.ExcludeInstanceMaxDop) {
$MaxDopSettings = (Test-DbaMaxDop -SqlInstance $Instance)[0] # because we dont care about the database maxdops here - potentially we could store it and use it for DatabaseMaxDop ?
}
}

Default { }
}

# set the default init fields for all the tags

#build the object

$testInstanceObject = [PSCustomObject]@{
Expand All @@ -144,6 +159,7 @@ function NewGet-AllInstanceInfo {
Logins = $Instance.Logins
Databases = $Instance.Databases
NumberOfLogFiles = $Instance.NumberOfLogFiles
MaxDopSettings = $MaxDopSettings
}
if ($ScanForStartupProceduresDisabled) {
$StartUpSPs = $Instance.Databases['master'].StoredProcedures.Where{ $_. Name -ne 'sp_MSrepl_startup' -and $_.StartUp -eq $true }.count
Expand Down

0 comments on commit 5706f31

Please sign in to comment.