Skip to content

Commit ceaf75b

Browse files
committed
Put Temp on RAM Disk for Azure Pipelines tests
Profiling on Azure Pipelines indicates that the majority of our time is spent waiting for filesystem operations to complete. As a quick way to improve our test speed in this area, we can do operations on a RAM disk instead of the default SSDs.
1 parent be13cf9 commit ceaf75b

File tree

2 files changed

+93
-3
lines changed

2 files changed

+93
-3
lines changed
+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
[CmdletBinding()]
2+
param(
3+
[Parameter(Mandatory=$true,
4+
HelpMessage="Drive letter to use for the RAMDisk")]
5+
[String]$drive,
6+
[Parameter(HelpMessage="Size to allocate to the RAMDisk")]
7+
[UInt64]$size=1GB
8+
)
9+
10+
$ErrorActionPreference = "Stop"
11+
Set-StrictMode -Version Latest
12+
13+
Write-Output "Installing FS-iSCSITarget-Server"
14+
Install-WindowsFeature -Name FS-iSCSITarget-Server
15+
16+
Write-Output "Starting MSiSCSI"
17+
Start-Service MSiSCSI
18+
$retry = 10
19+
do {
20+
$service = Get-Service MSiSCSI
21+
if ($service.Status -eq "Running") {
22+
break;
23+
}
24+
$retry--
25+
Start-Sleep -Milliseconds 500
26+
} until ($retry -eq 0)
27+
28+
$service = Get-Service MSiSCSI
29+
if ($service.Status -ne "Running") {
30+
throw "MSiSCSI is not running"
31+
}
32+
33+
Write-Output "Configuring Firewall"
34+
Get-NetFirewallServiceFilter -Service MSiSCSI | Enable-NetFirewallRule
35+
36+
Write-Output "Configuring RAMDisk"
37+
# Must use external-facing IP address, otherwise New-IscsiTargetPortal is
38+
# unable to connect.
39+
$ip = (
40+
Get-NetIPAddress -AddressFamily IPv4 |
41+
Where-Object {$_.IPAddress -ne "127.0.0.1"}
42+
)[0].IPAddress
43+
if (
44+
-not (Get-IscsiServerTarget -ComputerName localhost | Where-Object {$_.TargetName -eq "ramdisks"})
45+
) {
46+
New-IscsiServerTarget `
47+
-ComputerName localhost `
48+
-TargetName ramdisks `
49+
-InitiatorId IPAddress:$ip
50+
}
51+
52+
$newVirtualDisk = New-IscsiVirtualDisk `
53+
-ComputerName localhost `
54+
-Path ramdisk:local$drive.vhdx `
55+
-Size $size
56+
Add-IscsiVirtualDiskTargetMapping `
57+
-ComputerName localhost `
58+
-TargetName ramdisks `
59+
-Path ramdisk:local$drive.vhdx
60+
61+
Write-Output "Connecting to iSCSI"
62+
New-IscsiTargetPortal -TargetPortalAddress $ip
63+
Get-IscsiTarget | Where-Object {!$_.IsConnected} | Connect-IscsiTarget
64+
65+
Write-Output "Configuring disk"
66+
$newDisk = Get-IscsiConnection |
67+
Get-Disk |
68+
Where-Object {$_.SerialNumber -eq $newVirtualDisk.SerialNumber}
69+
70+
Set-Disk -InputObject $newDisk -IsOffline $false
71+
Initialize-Disk -InputObject $newDisk -PartitionStyle MBR
72+
New-Partition -InputObject $newDisk -UseMaximumSize -DriveLetter $drive
73+
74+
Format-Volume -DriveLetter $drive -NewFileSystemLabel Temp -FileSystem NTFS

.azure-pipelines/steps/run-tests-windows.yml

+19-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,28 @@ steps:
88
versionSpec: '$(python.version)'
99
architecture: '$(python.architecture)'
1010

11+
- task: PowerShell@2
12+
inputs:
13+
filePath: .azure-pipelines/scripts/New-RAMDisk.ps1
14+
arguments: "-Drive R -Size 1GB"
15+
displayName: Setup RAMDisk
16+
17+
- powershell: |
18+
mkdir R:\Temp
19+
$acl = Get-Acl "R:\Temp"
20+
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule(
21+
"Everyone", "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow"
22+
)
23+
$acl.AddAccessRule($rule)
24+
Set-Acl "R:\Temp" $acl
25+
displayName: Set RAMDisk Permissions
26+
1127
- bash: pip install --upgrade setuptools tox
1228
displayName: Install Tox
1329

1430
- script: tox -e py -- -m unit -n 3 --junit-xml=junit/unit-test.xml
31+
env:
32+
TEMP: "R:\\Temp"
1533
displayName: Tox run unit tests
1634

1735
- ${{ if eq(parameters.runIntegrationTests, 'true') }}:
@@ -23,9 +41,7 @@ steps:
2341
2442
# Shorten paths to get under MAX_PATH or else integration tests will fail
2543
# https://bugs.python.org/issue18199
26-
subst T: $env:TEMP
27-
$env:TEMP = "T:\"
28-
$env:TMP = "T:\"
44+
$env:TEMP = "R:\Temp"
2945
3046
tox -e py -- -m integration -n 3 --duration=5 --junit-xml=junit/integration-test.xml
3147
displayName: Tox run integration tests

0 commit comments

Comments
 (0)