-
-
Save jermdavis/f6266438bacfc8edecfde9eabced3d4b to your computer and use it in GitHub Desktop.
A hacky test script to look at Sitecore startup times depending on what's in your data folder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# This is pretty hacky code, for the purposes of testing some | |
# startup and request times. It's not recommended you take anything | |
# here for any important work... | |
# | |
[string]$logFile = "log.csv" | |
[int]$randomFileCount = 15 * 100; | |
[int]$randomFolderCount = 15 * 100; | |
[int]$testIterations = 25; | |
function makeRandomFilesAndFolders | |
{ | |
param( | |
[string]$folderPath | |
) | |
for($id=0; $id -lt $randomFileCount; $id = $id + 1) | |
{ | |
$file = $folderPath + "\\rndFile_$($id)_stuff.txt" | |
$file | Out-File -FilePath $file -Encoding ascii | |
} | |
for($id=0; $id -lt $randomFileCount; $id = $id + 1) | |
{ | |
$folder = $folderPath + "\\rndFolder_$($id)_stuff" | |
mkdir $folder | Out-Null | |
} | |
} | |
function removeRandomFilesAndFolders | |
{ | |
param( | |
[string]$folderPath | |
) | |
del "$folderPath\\rndFile*.txt" | Out-Null | |
rmdir "$folderPath\\rndFolder_*" | Out-Null | |
} | |
function Set-DataFolder | |
{ | |
param( | |
[string]$folder | |
) | |
$patch = "<configuration xmlns:patch=""http://www.sitecore.net/xmlconfig/""><sitecore><sc.variable name=""dataFolder""><patch:attribute name=""value"">$folder</patch:attribute></sc.variable></sitecore></configuration>" | |
$patch | Out-File "C:\inetpub\wwwroot\test\Website\App_Config\Include\zzz\zz.zz.TestDataFolderOverride.config" -Encoding ascii | |
} | |
function Set-DataFolderInWebRootSibling | |
{ | |
$path = "C:\inetpub\wwwroot\test\Data" | |
Set-DataFolder $path | |
return $path | |
} | |
function Set-DataFolderInWebRootChild | |
{ | |
$path = "C:\inetpub\wwwroot\test\Website\Data" | |
Set-DataFolder $path | |
return $path | |
} | |
function Set-License | |
{ | |
param( | |
[string]$location | |
) | |
$patch = "<configuration xmlns:patch=""http://www.sitecore.net/xmlconfig/""><sitecore><settings><setting name=""LicenseFile"" value=""$location""/></settings></sitecore></configuration>" | |
$patch | Out-File "C:\inetpub\wwwroot\test\Website\App_Config\Include\zzz\zz.zz.TestLicensePathOverride.config" -Encoding ascii | |
} | |
function Set-LicenseInDataFolder | |
{ | |
param( | |
[string]$path | |
) | |
Set-License "$path\license.xml" | |
} | |
function Set-LicenseInChildFolder | |
{ | |
param( | |
[string]$path | |
) | |
Set-License "$path\license\license.xml" | |
} | |
# Sibling, NoJunk, LicenseInDataFolder | |
function ScenarioOne | |
{ | |
Write-Host "SCENARIO 01: Sibling folder, No junk, License in data folder" | |
"S01, " | Out-File -FilePath $logFile -Append -NoNewline -Encoding ascii | |
$path = Set-DataFolderInWebRootSibling | |
removeRandomFilesAndFolders $path | |
Set-LicenseInDataFolder $path | |
} | |
# Sibling, Junk, LicenseInDataFolder | |
function ScenarioTwo | |
{ | |
Write-Host "SCENARIO 02: Sibling folder, Junk, License in data folder" | |
"S02, " | Out-File -FilePath $logFile -Append -NoNewline -Encoding ascii | |
$path = Set-DataFolderInWebRootSibling | |
makeRandomFilesAndFolders $path | |
Set-LicenseInDataFolder $path | |
} | |
# Sibling, NoJunk, LicenseInChildFolder | |
function ScenarioThree | |
{ | |
Write-Host "SCENARIO 03: Sibling folder, No junk, License in child folder" | |
"S03, " | Out-File -FilePath $logFile -Append -NoNewline -Encoding ascii | |
$path = Set-DataFolderInWebRootSibling | |
removeRandomFilesAndFolders $path | |
Set-LicenseInChildFolder $path | |
} | |
# Sibling, Junk, LicenseInChildFolder | |
function ScenarioFour | |
{ | |
Write-Host "SCENARIO 04: Sibling folder, Junk, License in child folder" | |
"S04, " | Out-File -FilePath $logFile -Append -NoNewline -Encoding ascii | |
$path = Set-DataFolderInWebRootSibling | |
makeRandomFilesAndFolders $path | |
Set-LicenseInChildFolder $path | |
} | |
# Child, NoJunk, LicenseInDataFolder | |
function ScenarioFive | |
{ | |
Write-Host "SCENARIO 05: Child folder, No junk, License in data folder" | |
"S05, " | Out-File -FilePath $logFile -Append -NoNewline -Encoding ascii | |
$path = Set-DataFolderInWebRootChild | |
removeRandomFilesAndFolders $path | |
Set-LicenseInDataFolder $path | |
} | |
# Child, Junk, LicenseInDataFolder | |
function ScenarioSix | |
{ | |
Write-Host "SCENARIO 06: Child folder, Junk, License in data folder" | |
"S06, " | Out-File -FilePath $logFile -Append -NoNewline -Encoding ascii | |
$path = Set-DataFolderInWebRootChild | |
makeRandomFilesAndFolders $path | |
Set-LicenseInDataFolder $path | |
} | |
# Child, NoJunk, LicenseInChildFolder | |
function ScenarioSeven | |
{ | |
Write-Host "SCENARIO 07: Child folder, No junk, License in child folder" | |
"S07, " | Out-File -FilePath $logFile -Append -NoNewline -Encoding ascii | |
$path = Set-DataFolderInWebRootChild | |
removeRandomFilesAndFolders $path | |
Set-LicenseInChildFolder $path | |
} | |
# Child, Junk, LicenseInChildFolder | |
function ScenarioEight | |
{ | |
Write-Host "SCENARIO 08: Child folder, Junk, License in child folder" | |
"S08, " | Out-File -FilePath $logFile -Append -NoNewline -Encoding ascii | |
$path = Set-DataFolderInWebRootChild | |
makeRandomFilesAndFolders $path | |
Set-LicenseInChildFolder $path | |
} | |
function cycleServer | |
{ | |
$xml = "<configuration xmlns:patch='http://www.sitecore.net/xmlconfig/\'><sitecore></sitecore></configuration>" | |
$file = "C:\inetpub\wwwroot\test\Website\App_Config\Include\\test.config" | |
if( Test-Path $file ) | |
{ | |
del $file | |
} | |
else | |
{ | |
$xml | Out-File -FilePath $file -Encoding ascii | |
} | |
[System.Threading.Thread]::Sleep(500); | |
} | |
function timeStartup | |
{ | |
$ms = 0; | |
for($id=0; $id -lt $testIterations; $id = $id + 1) | |
{ | |
Write-Host "Cycling server for iteration $id" | |
cycleServer | |
$tmr = [System.Diagnostics.Stopwatch]::StartNew(); | |
$result = Invoke-WebRequest -Uri "http://test.local/" | |
Write-Host " Status: $($result.StatusCode) in $($tmr.ElapsedMilliseconds)" | |
$tmr.Stop(); | |
$ms = $ms + $tmr.ElapsedMilliseconds; | |
"$($tmr.ElapsedMilliseconds)," | Out-File -FilePath $logFile -Append -NoNewLine -Encoding ascii | |
} | |
Write-Host " Average First Response: $($ms / $testIterations)ms" | |
"$($ms / $testIterations), " | Out-File -FilePath $logFile -Append -NoNewline -Encoding ascii | |
} | |
function timeRequests | |
{ | |
$ms = 0; | |
for($id=0; $id -lt $testIterations; $id = $id + 1) | |
{ | |
#Write-Host "Requesting page for iteration $id" | |
$tmr = [System.Diagnostics.Stopwatch]::StartNew(); | |
$result = Invoke-WebRequest -Uri "http://test.local/" | |
#Write-Host " Status: $($result.StatusCode) in $($tmr.ElapsedMilliseconds)" | |
Write-Host "#" -NoNewline | |
$tmr.Stop(); | |
$ms = $ms + $tmr.ElapsedMilliseconds; | |
"$($tmr.ElapsedMilliseconds)," | Out-File -FilePath $logFile -Append -NoNewLine -Encoding ascii | |
} | |
Write-Host " Average Subsequent Response: $($ms / $testIterations)ms" | |
"$($ms / $testIterations)" | Out-File -FilePath $logFile -Append -Encoding ascii | |
} | |
cls | |
"Test," | Out-File -FilePath $logFile -NoNewLine -Encoding ascii | |
for($id=0; $id -lt $testIterations; $id = $id + 1) | |
{ | |
"Startup$id," | Out-File -FilePath $logFile -NoNewLine -Append -Encoding ascii | |
} | |
"AvgStartup," | Out-File -FilePath $logFile -NoNewLine -Append -Encoding ascii | |
for($id=0; $id -lt $testIterations; $id = $id + 1) | |
{ | |
"Request$id," | Out-File -FilePath $logFile -NoNewLine -Append -Encoding ascii | |
} | |
"AvgRequest" | Out-File -FilePath $logFile -Append -Encoding ascii | |
Write-Host "Test run" | |
ScenarioOne | timeStartup | timeRequests | |
ScenarioTwo | timeStartup | timeRequests | |
ScenarioThree | timeStartup | timeRequests | |
ScenarioFour | timeStartup | timeRequests | |
ScenarioFive | timeStartup | timeRequests | |
ScenarioSix | timeStartup | timeRequests | |
ScenarioSeven | timeStartup | timeRequests | |
ScenarioEight | timeStartup | timeRequests | |
Write-Host "DONE." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment