|
12 | 12 | using Microsoft.Extensions.Hosting; |
13 | 13 | using IHost = Microsoft.Extensions.Hosting.IHost; |
14 | 14 |
|
15 | | -namespace StoragesBenchmark |
| 15 | +namespace StoragesBenchmark; |
| 16 | + |
| 17 | +[SimpleJob(RunStrategy.Monitoring, iterationCount: 5)] |
| 18 | + |
| 19 | +public abstract class OrchestrationBenchmark |
16 | 20 | { |
17 | | - [SimpleJob(RunStrategy.Monitoring, iterationCount: 5)] |
| 21 | + [Params(100)] |
| 22 | + public int NumberOfOrchestrations; |
18 | 23 |
|
19 | | - public abstract class OrchestrationBenchmark |
20 | | - { |
21 | | - [Params(100)] |
22 | | - public int NumberOfOrchestrations; |
| 24 | + [Params(5)] |
| 25 | + public int NumberOfActivities; |
23 | 26 |
|
24 | | - [Params(5)] |
25 | | - public int NumberOfActivities; |
| 27 | + protected IHost _host; |
| 28 | + protected IConfiguration _configuration; |
26 | 29 |
|
27 | | - protected IHost _host; |
28 | | - protected IConfiguration _configuration; |
| 30 | + [GlobalSetup] |
| 31 | + public async Task Setup() |
| 32 | + { |
| 33 | + _configuration = new ConfigurationBuilder() |
| 34 | + .AddJsonFile("appsettings.json", false) |
| 35 | + .AddJsonFile("appsettings.private.json", true) |
| 36 | + .AddEnvironmentVariables() |
| 37 | + .Build(); |
| 38 | + |
| 39 | + _host = await Host.CreateDefaultBuilder() |
| 40 | + .ConfigureServices(services => |
| 41 | + { |
| 42 | + ConfigureStorage(services); |
29 | 43 |
|
30 | | - [GlobalSetup] |
31 | | - public async Task Setup() |
32 | | - { |
33 | | - _configuration = new ConfigurationBuilder() |
34 | | - .AddJsonFile("appsettings.json", false) |
35 | | - .AddJsonFile("appsettings.private.json", true) |
36 | | - .AddEnvironmentVariables() |
37 | | - .Build(); |
38 | | - |
39 | | - _host = await Host.CreateDefaultBuilder() |
40 | | - .ConfigureServices(services => |
| 44 | + services.AddDurableTaskClient(); |
| 45 | + |
| 46 | + services.AddDurableTaskWorker(builder => |
41 | 47 | { |
42 | | - ConfigureStorage(services); |
| 48 | + ConfigureWorker(builder); |
| 49 | + }); |
| 50 | + }).StartAsync(); |
| 51 | + } |
43 | 52 |
|
44 | | - services.AddDurableTaskClient(); |
| 53 | + [GlobalCleanup] |
| 54 | + public async Task Cleanup() |
| 55 | + { |
| 56 | + await _host.StopAsync(); |
| 57 | + _host.Dispose(); |
| 58 | + } |
45 | 59 |
|
46 | | - services.AddDurableTaskWorker(builder => |
47 | | - { |
48 | | - ConfigureWorker(builder); |
49 | | - }); |
50 | | - }).StartAsync(); |
51 | | - } |
| 60 | + protected abstract void ConfigureStorage(IServiceCollection services); |
52 | 61 |
|
53 | | - [GlobalCleanup] |
54 | | - public async Task Cleanup() |
55 | | - { |
56 | | - await _host.StopAsync(); |
57 | | - _host.Dispose(); |
58 | | - } |
| 62 | + protected virtual void ConfigureWorker(IDurableTaskWorkerBuilder builder) |
| 63 | + { |
| 64 | + builder.AddAnnotatedFrom(typeof(Orchestrations)); |
| 65 | + } |
| 66 | + |
| 67 | + [Benchmark] |
| 68 | + public async Task RunOrchestrations() |
| 69 | + { |
| 70 | + var taskHubClient = _host.Services.GetRequiredService<TaskHubClient>(); |
59 | 71 |
|
60 | | - protected abstract void ConfigureStorage(IServiceCollection services); |
| 72 | + var instances = new List<OrchestrationInstance>(); |
61 | 73 |
|
62 | | - protected virtual void ConfigureWorker(IDurableTaskWorkerBuilder builder) |
| 74 | + for (var i = 0; i < NumberOfOrchestrations; i++) |
63 | 75 | { |
64 | | - builder.AddAnnotatedFrom(typeof(Orchestrations)); |
| 76 | + var instance = await taskHubClient.CreateOrchestrationInstanceAsync("RunActivities", "", NumberOfActivities); |
| 77 | + instances.Add(instance); |
65 | 78 | } |
66 | 79 |
|
67 | | - [Benchmark] |
68 | | - public async Task RunOrchestrations() |
| 80 | + foreach (var instance in instances) |
69 | 81 | { |
70 | | - var taskHubClient = _host.Services.GetRequiredService<TaskHubClient>(); |
71 | | - |
72 | | - var instances = new List<OrchestrationInstance>(); |
73 | | - |
74 | | - for (var i = 0; i < NumberOfOrchestrations; i++) |
75 | | - { |
76 | | - var instance = await taskHubClient.CreateOrchestrationInstanceAsync("RunActivities", "", NumberOfActivities); |
77 | | - instances.Add(instance); |
78 | | - } |
79 | | - |
80 | | - foreach (var instance in instances) |
81 | | - { |
82 | | - var state = await taskHubClient.WaitForOrchestrationAsync(instance, TimeSpan.FromMinutes(30)); |
83 | | - if (state == null || state.OrchestrationStatus != OrchestrationStatus.Completed) |
84 | | - throw new Exception("Orchestration did not complete"); |
85 | | - } |
| 82 | + var state = await taskHubClient.WaitForOrchestrationAsync(instance, TimeSpan.FromMinutes(30)); |
| 83 | + if (state == null || state.OrchestrationStatus != OrchestrationStatus.Completed) |
| 84 | + throw new Exception("Orchestration did not complete"); |
86 | 85 | } |
| 86 | + } |
87 | 87 |
|
88 | | - public class Orchestrations |
| 88 | + public class Orchestrations |
| 89 | + { |
| 90 | + [Orchestration(Name = "RunActivities")] |
| 91 | + public async Task Run(OrchestrationContext context, int numberOfActivities) |
89 | 92 | { |
90 | | - [Orchestration(Name = "RunActivities")] |
91 | | - public async Task Run(OrchestrationContext context, int numberOfActivities) |
92 | | - { |
93 | | - var tasks = Enumerable.Range(0, numberOfActivities).Select(e => context.ScheduleTask<Guid>("EmptyActivity", "")); |
94 | | - await Task.WhenAll(tasks); |
95 | | - } |
| 93 | + var tasks = Enumerable.Range(0, numberOfActivities).Select(e => context.ScheduleTask<Guid>("EmptyActivity", "")); |
| 94 | + await Task.WhenAll(tasks); |
| 95 | + } |
96 | 96 |
|
97 | | - [Activity(Name = "EmptyActivity")] |
98 | | - public Guid EmptyActivity() |
99 | | - { |
100 | | - return Guid.NewGuid(); |
101 | | - } |
| 97 | + [Activity(Name = "EmptyActivity")] |
| 98 | + public Guid EmptyActivity() |
| 99 | + { |
| 100 | + return Guid.NewGuid(); |
102 | 101 | } |
103 | 102 | } |
104 | 103 | } |
0 commit comments