Skip to content

Commit 5b3fa6a

Browse files
Fix perf tests
1 parent 959f23f commit 5b3fa6a

8 files changed

+89
-64
lines changed

performance/.editorconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
dotnet_diagnostic.CA1309.severity = silent # Use ordinal StringComparison - this isn't important for tests and just adds clutter
77
dotnet_diagnostic.CA1305.severity = silent # Specify IFormatProvider - this isn't important for tests and just adds clutter
88
dotnet_diagnostic.CA1707.severity = silent # Identifiers should not contain underscores - this helps make test names more readable
9-
dotnet_diagnostic.CA2201.severity = silent # Do not raise reserved exception types - tests can throw whatever they want
9+
dotnet_diagnostic.CA2201.severity = silent # Do not raise reserved exception types - tests can throw whatever they want
10+
dotnet_diagnostic.CA1051.severity = silent # Do not declare visible instance fields - doesn't matter for tests

performance/SqlTriggerBindingPerformance.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class SqlTriggerBindingPerformance : SqlTriggerBindingPerformanceTestBase
1414
[GlobalSetup]
1515
public void GlobalSetup()
1616
{
17+
this.SetChangeTrackingForTable("Products", true);
1718
this.StartFunctionHost(nameof(ProductsTrigger), SupportedLanguages.CSharp);
1819
}
1920

performance/SqlTriggerBindingPerformanceTestBase.cs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,30 @@ namespace Microsoft.Azure.WebJobs.Extensions.Sql.Performance
88
{
99
public class SqlTriggerBindingPerformanceTestBase : SqlTriggerBindingIntegrationTests
1010
{
11-
[IterationSetup]
12-
public void IterationSetup()
13-
{
14-
this.SetChangeTrackingForTable("Products", true);
15-
}
16-
1711
[IterationCleanup]
1812
public void IterationCleanup()
1913
{
20-
this.DisposeFunctionHosts();
14+
// Disable change tracking while cleaning up so we start off fresh for the next iteration
2115
this.SetChangeTrackingForTable("Products", false);
2216
// Delete all rows in Products table after each iteration so we start fresh each time
2317
this.ExecuteNonQuery("TRUNCATE TABLE Products");
24-
// Delete the leases table, otherwise we may end up getting blocked by leases from a previous run
18+
// Clear the leases table, otherwise we may end up getting blocked by leases from a previous run
2519
this.ExecuteNonQuery(@"DECLARE @cmd varchar(100)
26-
DECLARE cmds CURSOR FOR
27-
SELECT 'DROP TABLE az_func.' + Name + ''
28-
FROM sys.tables
29-
WHERE Name LIKE 'Leases_%'
20+
DECLARE cmds CURSOR FOR
21+
SELECT 'TRUNCATE TABLE az_func.' + Name + ''
22+
FROM sys.tables
23+
WHERE Name LIKE 'Leases_%'
3024
31-
OPEN cmds
32-
WHILE 1 = 1
33-
BEGIN
34-
FETCH cmds INTO @cmd
35-
IF @@fetch_status != 0 BREAK
36-
EXEC(@cmd)
37-
END
38-
CLOSE cmds;
39-
DEALLOCATE cmds");
25+
OPEN cmds
26+
WHILE 1 = 1
27+
BEGIN
28+
FETCH cmds INTO @cmd
29+
IF @@fetch_status != 0 BREAK
30+
EXEC(@cmd)
31+
END
32+
CLOSE cmds;
33+
DEALLOCATE cmds");
34+
this.SetChangeTrackingForTable("Products", true);
4035
}
4136

4237
[GlobalCleanup]

performance/SqlTriggerBindingPerformance_Parallelization.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,22 @@ namespace Microsoft.Azure.WebJobs.Extensions.Sql.Performance
1111
[MemoryDiagnoser]
1212
public class SqlTriggerBindingPerformance_Parallelization : SqlTriggerBindingPerformanceTestBase
1313
{
14-
[Benchmark]
15-
[Arguments(2)]
16-
[Arguments(5)]
17-
public async Task MultiHost(int hostCount)
14+
[Params(2, 5)]
15+
public int HostCount;
16+
17+
[GlobalSetup]
18+
public void GlobalSetup()
1819
{
19-
for (int i = 0; i < hostCount; ++i)
20+
this.SetChangeTrackingForTable("Products", true);
21+
for (int i = 0; i < this.HostCount; ++i)
2022
{
2123
this.StartFunctionHost(nameof(ProductsTrigger), SupportedLanguages.CSharp);
2224
}
25+
}
2326

27+
[Benchmark]
28+
public async Task MultiHost()
29+
{
2430
int firstId = 1;
2531
int lastId = 90;
2632
await this.WaitForProductChanges(

performance/SqlTriggerPerformance_BatchOverride.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,38 @@ namespace Microsoft.Azure.WebJobs.Extensions.Sql.Performance
1212
[MemoryDiagnoser]
1313
public class SqlTriggerBindingPerformance_BatchOverride : SqlTriggerBindingPerformanceTestBase
1414
{
15-
[Benchmark]
16-
[Arguments(10, 1000)]
17-
[Arguments(100, 1000)]
18-
[Arguments(1000, 1000)]
19-
[Arguments(5000, 1000)]
20-
public async Task Run(int count, int batchSize)
15+
16+
[Params(100, 1000)]
17+
public int BatchSize;
18+
19+
[GlobalSetup]
20+
public void GlobalSetup()
2121
{
22+
this.SetChangeTrackingForTable("Products", true);
2223
this.StartFunctionHost(
2324
nameof(ProductsTrigger),
2425
SupportedLanguages.CSharp,
2526
environmentVariables: new Dictionary<string, string>() {
26-
{ "Sql_Trigger_BatchSize", batchSize.ToString() }
27+
{ "Sql_Trigger_BatchSize", this.BatchSize.ToString() }
2728
});
29+
}
30+
31+
[Benchmark]
32+
[Arguments(0.1)]
33+
[Arguments(0.5)]
34+
[Arguments(1)]
35+
[Arguments(5)]
36+
public async Task Run(double numBatches)
37+
{
38+
int count = (int)(numBatches * this.BatchSize);
2839
await this.WaitForProductChanges(
2940
1,
3041
count,
3142
SqlChangeOperation.Insert,
3243
() => { this.InsertProducts(1, count); return Task.CompletedTask; },
3344
id => $"Product {id}",
3445
id => id * 100,
35-
this.GetBatchProcessingTimeout(1, count, batchSize: batchSize));
46+
this.GetBatchProcessingTimeout(1, count, batchSize: this.BatchSize));
3647
}
3748
}
3849
}

performance/SqlTriggerPerformance_Overrides.cs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,44 @@ namespace Microsoft.Azure.WebJobs.Extensions.Sql.Performance
1212
[MemoryDiagnoser]
1313
public class SqlTriggerPerformance_Overrides : SqlTriggerBindingPerformanceTestBase
1414
{
15-
[Benchmark]
16-
[Arguments(10, 1000, 500)]
17-
[Arguments(10, 1000, 100)]
18-
[Arguments(10, 1000, 10)]
19-
[Arguments(10, 1000, 1)]
20-
[Arguments(100, 1000, 500)]
21-
[Arguments(100, 1000, 100)]
22-
[Arguments(100, 1000, 10)]
23-
[Arguments(100, 1000, 1)]
24-
[Arguments(1000, 1000, 500)]
25-
[Arguments(1000, 1000, 100)]
26-
[Arguments(1000, 1000, 10)]
27-
[Arguments(1000, 1000, 1)]
28-
[Arguments(5000, 1000, 500)]
29-
[Arguments(5000, 1000, 100)]
30-
[Arguments(5000, 1000, 10)]
31-
[Arguments(5000, 1000, 1)]
32-
public async Task Run(int count, int batchSize, int pollingIntervalMs)
15+
// [Params(1, 10, 100, 500)]
16+
[Params(1, 10)]
17+
public int PollingIntervalMs;
18+
19+
[Params(500, 1000)]
20+
// [Params(500, 1000, 2000)]
21+
public int BatchSize;
22+
23+
[GlobalSetup]
24+
public void GlobalSetup()
3325
{
26+
this.SetChangeTrackingForTable("Products", true);
3427
this.StartFunctionHost(
3528
nameof(ProductsTrigger),
3629
SupportedLanguages.CSharp,
3730
environmentVariables: new Dictionary<string, string>() {
38-
{ "Sql_Trigger_BatchSize", batchSize.ToString() },
39-
{ "Sql_Trigger_PollingIntervalMs", pollingIntervalMs.ToString() }
31+
{ "Sql_Trigger_BatchSize", this.BatchSize.ToString() },
32+
{ "Sql_Trigger_PollingIntervalMs", this.PollingIntervalMs.ToString() }
4033
});
34+
}
35+
36+
[Benchmark]
37+
[Arguments(0.1)]
38+
[Arguments(0.5)]
39+
//[Arguments(1)]
40+
//[Arguments(5)]
41+
// [Arguments(10)]
42+
public async Task Run(double numBatches)
43+
{
44+
int count = (int)(numBatches * this.BatchSize);
4145
await this.WaitForProductChanges(
4246
1,
4347
count,
4448
SqlChangeOperation.Insert,
4549
() => { this.InsertProducts(1, count); return Task.CompletedTask; },
4650
id => $"Product {id}",
4751
id => id * 100,
48-
this.GetBatchProcessingTimeout(1, count, batchSize: batchSize));
52+
this.GetBatchProcessingTimeout(1, count, batchSize: this.BatchSize));
4953
}
5054
}
5155
}

performance/SqlTriggerPerformance_PollingIntervalOverride.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,33 @@ namespace Microsoft.Azure.WebJobs.Extensions.Sql.Performance
1212
[MemoryDiagnoser]
1313
public class SqlTriggerBindingPerformance_PollingIntervalOverride : SqlTriggerBindingPerformanceTestBase
1414
{
15-
[Benchmark]
16-
[Arguments(1000, 500)]
17-
[Arguments(1000, 100)]
18-
[Arguments(1000, 10)]
19-
[Arguments(1000, 1)]
20-
public async Task Run(int count, int pollingIntervalMs)
15+
[Params(1, 10, 100, 500, 2000)]
16+
public int PollingIntervalMs;
17+
18+
[GlobalSetup]
19+
public void GlobalSetup()
2120
{
21+
this.SetChangeTrackingForTable("Products", true);
2222
this.StartFunctionHost(
2323
nameof(ProductsTrigger),
2424
SupportedLanguages.CSharp,
2525
environmentVariables: new Dictionary<string, string>() {
26-
{ "Sql_Trigger_PollingIntervalMs", pollingIntervalMs.ToString() }
26+
{ "Sql_Trigger_PollingIntervalMs", this.PollingIntervalMs.ToString() }
2727
});
28+
}
29+
30+
[Benchmark]
31+
public async Task Run()
32+
{
33+
int count = SqlTableChangeMonitor<object>.DefaultBatchSize * 2;
2834
await this.WaitForProductChanges(
2935
1,
3036
count,
3137
SqlChangeOperation.Insert,
3238
() => { this.InsertProducts(1, count); return Task.CompletedTask; },
3339
id => $"Product {id}",
3440
id => id * 100,
35-
this.GetBatchProcessingTimeout(1, count, pollingIntervalMs: pollingIntervalMs));
41+
this.GetBatchProcessingTimeout(1, count, pollingIntervalMs: this.PollingIntervalMs));
3642
}
3743
}
3844
}

src/Microsoft.Azure.WebJobs.Extensions.Sql.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<PackageReference Include="Microsoft.AspNetCore.Http" />
3838
<InternalsVisibleTo Include="Microsoft.Azure.WebJobs.Extensions.Sql.Tests" Key="0024000004800000940000000602000000240000525341310004000001000100272736ad6e5f9586bac2d531eabc3acc666c2f8ec879fa94f8f7b0327d2ff2ed523448f83c3d5c5dd2dfc7bc99c5286b2c125117bf5cbe242b9d41750732b2bdffe649c6efb8e5526d526fdd130095ecdb7bf210809c6cdad8824faa9ac0310ac3cba2aa0523567b2dfa7fe250b30facbd62d4ec99b94ac47c7d3b28f1f6e4c8" />
3939
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" Key="0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7" />
40+
<InternalsVisibleTo Include="Microsoft.Azure.WebJobs.Extensions.Sql.Performance" Key="0024000004800000940000000602000000240000525341310004000001000100272736ad6e5f9586bac2d531eabc3acc666c2f8ec879fa94f8f7b0327d2ff2ed523448f83c3d5c5dd2dfc7bc99c5286b2c125117bf5cbe242b9d41750732b2bdffe649c6efb8e5526d526fdd130095ecdb7bf210809c6cdad8824faa9ac0310ac3cba2aa0523567b2dfa7fe250b30facbd62d4ec99b94ac47c7d3b28f1f6e4c8"/>
4041
</ItemGroup>
4142

4243
<ItemGroup>

0 commit comments

Comments
 (0)