Tuesday, February 16, 2016

SharePoint 2013 Performance Optimization in PowerShell

SharePoint 2013 Performance Optimizations in PowerShell

Developer machines in particular need to make maximum utilization of RAM.

SetSQLInstanceMemory, sets the RAM of the SQL server.  Operating System gets 10% and at least 2GB.  SQL Server, for SharePoint, gets between 2GB and 4GB on a developer machine (its got to share RAM with Visual Studio and SharePoint).

SetSQLInstanceMemory ".\SP2013" 3072 2048

SetNodeRunnerMemoryLimit, is not supported, as the Search uses most of the memory, you can  reduce it here.  It needs at least a 1 GB, or it keeps crashing.

SetObjectCachingOnSite, can be run to make SharePoint a bit faster.  I do it on most farms.

Set-SPEnterpriseSearchService -PerformanceLevel Reduced, I only run this in developer machines, or if there is no need for full power search.

New-SPEnterpriseSearchSiteHitRule -Name $env:COMPUTERNAME -Behavior 'SimultaneousRequests' -HitRate 2,  This one I use on production and developer farms.  The search will absolutely smash your servers unless you set this in farms whithout dedicated search servers.

Set-SPLogLevel -TraceSeverity Medium -EventSeverity Information.  If the farm is stable consider setting this.  The more the information that SharePoint logs the slower your farm will be.

Set-SPDiagnosticConfig -LogMaxDiskSpaceUsageEnabled
Set-SPDiagnosticConfig -LogDiskSpaceUsageGB 1
Set-SPDiagnosticConfig -EventLogFloodProtectionEnabled
I always set these, options vary.

Get-SPUsageDefinition | ForEach-Object { if ($_.Enabled -eq "False") { Set-SPUsageDefinition -Identity $_.Name -DaysRetained 1 }}.  On a dev machine DaysRetained = 1, On production you may need several weeks.

Add-PSSnapin Microsoft.sharepoint.powershell
function SetSQLInstanceMemory ([string]$SQLInstanceName = ".", [int]$maxMem = $null, [int]$minMem = $null)
    [reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | Out-Null
    $srv = new-object Microsoft.SQLServer.Management.Smo.Server($SQLInstanceName)
    $srv.ConnectionContext.LoginSecure = $true
    $srv.Configuration.MaxServerMemory.ConfigValue = $maxMem
    $srv.Configuration.MinServerMemory.ConfigValue = $minMem
function SetNodeRunnerMemoryLimit()
    write-host -ForegroundColor Red "Setting NodeRunner memory, not supported in Production or UAT"
    #edit file for updated values
    $webConfig = "C:\Program Files\Microsoft Office Servers\15.0\Search\Runtime\1.0\noderunner.exe.config"
    $doc = (gc $webConfig) -as [xml]
    $nodeRunnerSettingsnode = $doc.SelectSingleNode('configuration/nodeRunnerSettings')
    #not support!!!!!
    #for dev only
    $nodeRunnerSettingsnode.Attributes['memoryLimitMegabytes'].Value = "1024"
    Restart-Service SPSearchHostController
    write-host -ForegroundColor Red "Setting NodeRunner memory, not supported in Production or UAT"

function GetObjectCachingOnSite([string] $siteUrl)
    $cacheSettings = new-object Microsoft.SharePoint.Publishing.SiteCacheSettingsWriter($siteUrl);
    $cacheSettings.EnableCache = $true;

#set memory used by SQL
SetSQLInstanceMemory ".\SP2013" 3072 2048
#reduce crawl
Set-SPEnterpriseSearchService -PerformanceLevel Reduced
#set crawler impact rule
New-SPEnterpriseSearchSiteHitRule -Name $env:COMPUTERNAME -Behavior 'SimultaneousRequests' -HitRate 2
#set noderunner memory
#set minumum
Set-SPLogLevel -TraceSeverity Medium -EventSeverity Information
#general settings
Set-SPDiagnosticConfig -LogMaxDiskSpaceUsageEnabled
Set-SPDiagnosticConfig -LogDiskSpaceUsageGB 1
Set-SPDiagnosticConfig -EventLogFloodProtectionEnabled
#stop logs from growing
Get-SPUsageDefinition | ForEach-Object { if ($_.Enabled -eq "False") { Set-SPUsageDefinition -Identity $_.Name -
DaysRetained 1 }}
SetObjectCachingOnSite "https://test.com"

No comments:

Post a Comment