Skip to content

Commit b00445d

Browse files
Thierry Habarthabarthierry-hue
authored andcommitted
Ticket #10 : Add benchmark
1 parent 9e03bf7 commit b00445d

17 files changed

Lines changed: 367 additions & 19 deletions

File tree

CaseManagement.sln

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CaseManagement.Workflow.Tes
2929
EndProject
3030
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CaseManagement.CMMN.Tests", "tests\CaseManagement.CMMN.Tests\CaseManagement.CMMN.Tests.csproj", "{F005FA4D-312C-428C-93A7-4F02C01136A8}"
3131
EndProject
32+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "05. Benchmark", "05. Benchmark", "{73DCE7A3-F336-4E72-B36C-9D88860BC897}"
33+
EndProject
34+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CaseManagement.CMMN.Benchmark", "src\CaseManagement.CMMN.Benchmark\CaseManagement.CMMN.Benchmark.csproj", "{3DFF3970-7721-4087-8E41-F478D39C2095}"
35+
EndProject
3236
Global
3337
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3438
Debug|Any CPU = Debug|Any CPU
@@ -67,6 +71,10 @@ Global
6771
{F005FA4D-312C-428C-93A7-4F02C01136A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
6872
{F005FA4D-312C-428C-93A7-4F02C01136A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
6973
{F005FA4D-312C-428C-93A7-4F02C01136A8}.Release|Any CPU.Build.0 = Release|Any CPU
74+
{3DFF3970-7721-4087-8E41-F478D39C2095}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
75+
{3DFF3970-7721-4087-8E41-F478D39C2095}.Debug|Any CPU.Build.0 = Debug|Any CPU
76+
{3DFF3970-7721-4087-8E41-F478D39C2095}.Release|Any CPU.ActiveCfg = Release|Any CPU
77+
{3DFF3970-7721-4087-8E41-F478D39C2095}.Release|Any CPU.Build.0 = Release|Any CPU
7078
EndGlobalSection
7179
GlobalSection(SolutionProperties) = preSolution
7280
HideSolutionNode = FALSE
@@ -80,6 +88,7 @@ Global
8088
{E4C5F767-299D-4D26-916B-59EC7C93CE90} = {CD2E7CFE-4E9C-4308-A0D3-41CD5AD90FD8}
8189
{77FF9E1D-A705-4E04-84CA-FF42D3563F77} = {A632EFC3-730B-46D7-B669-91962DFA8947}
8290
{F005FA4D-312C-428C-93A7-4F02C01136A8} = {A632EFC3-730B-46D7-B669-91962DFA8947}
91+
{3DFF3970-7721-4087-8E41-F478D39C2095} = {73DCE7A3-F336-4E72-B36C-9D88860BC897}
8392
EndGlobalSection
8493
GlobalSection(ExtensibilityGlobals) = postSolution
8594
SolutionGuid = {D2CFBF2E-D493-42F7-B339-01A3070C2B5E}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
``` ini
2+
3+
BenchmarkDotNet=v0.12.0, OS=Windows 10.0.18362
4+
Intel Core i7-8750H CPU 2.20GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores
5+
.NET Core SDK=3.0.100
6+
[Host] : .NET Core 2.2.5 (CoreCLR 4.6.27617.05, CoreFX 4.6.27618.01), X64 RyuJIT
7+
8+
Job=InProcess Toolchain=InProcessEmitToolchain
9+
10+
```
11+
| Method | Mean | Error | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
12+
|---------------------------- |-------------:|----------:|----------:|-----------:|------:|------:|----------:|
13+
| CreateCaseInstance | 1.069 ms | 0.0621 ms | 0.1782 ms | - | - | - | 11.52 KB |
14+
| LaunchEventListener2Seconds | 2,006.229 ms | 1.3547 ms | 1.2672 ms | 64000.0000 | - | - | 11.52 KB |
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
using BenchmarkDotNet.Attributes;
2+
using CaseManagement.CMMN.CaseInstance.Commands;
3+
using Newtonsoft.Json;
4+
using Newtonsoft.Json.Linq;
5+
using System;
6+
using System.Net.Http;
7+
using System.Text;
8+
using System.Threading;
9+
using System.Threading.Tasks;
10+
11+
namespace CaseManagement.CMMN.Benchmark
12+
{
13+
[InProcess]
14+
[MemoryDiagnoser]
15+
[RPlotExporter]
16+
public class CaseInstanceControllerBenchmark
17+
{
18+
private HttpClient _client;
19+
20+
[GlobalSetup]
21+
public void GlobalSetup()
22+
{
23+
var factory = new CustomWebApplicationFactory<Startup>();
24+
_client = factory.CreateClient();
25+
}
26+
27+
[Benchmark]
28+
public async Task CreateCaseInstance()
29+
{
30+
var cmd = new CreateCaseInstanceCommand
31+
{
32+
CaseDefinitionId = "caseWithTimerEventListener",
33+
CasesId = "Case_0d1ujq8"
34+
};
35+
var httpRequestMessage = new HttpRequestMessage
36+
{
37+
Method = HttpMethod.Post,
38+
RequestUri = new Uri("http://localhost/case-instances"),
39+
Content = new StringContent(JsonConvert.SerializeObject(cmd), Encoding.UTF8, "application/json")
40+
};
41+
var httpResult = await _client.SendAsync(httpRequestMessage);
42+
var json = await httpResult.Content.ReadAsStringAsync();
43+
var id = JsonConvert.DeserializeObject<JObject>(json)["id"].ToString();
44+
await PollCaseInstanceCreated(id);
45+
}
46+
47+
[Benchmark]
48+
public async Task LaunchEventListener2Seconds()
49+
{
50+
var cmd = new CreateCaseInstanceCommand
51+
{
52+
CaseDefinitionId = "caseWithTimerEventListener",
53+
CasesId = "Case_0d1ujq8"
54+
};
55+
var httpRequestMessage = new HttpRequestMessage
56+
{
57+
Method = HttpMethod.Post,
58+
RequestUri = new Uri("http://localhost/case-instances"),
59+
Content = new StringContent(JsonConvert.SerializeObject(cmd), Encoding.UTF8, "application/json")
60+
};
61+
var httpResult = await _client.SendAsync(httpRequestMessage);
62+
var json = await httpResult.Content.ReadAsStringAsync();
63+
var id = JsonConvert.DeserializeObject<JObject>(json)["id"].ToString();
64+
await _client.GetAsync($"http://localhost/case-instances/{id}/launch");
65+
await PollCaseInstanceCompleted(id);
66+
}
67+
68+
public async Task PollCaseInstanceCreated(string id)
69+
{
70+
var httpResult = await _client.GetAsync($"http://localhost/case-instances/{id}");
71+
if (!httpResult.IsSuccessStatusCode)
72+
{
73+
await PollCaseInstanceCreated(id);
74+
return;
75+
}
76+
}
77+
78+
public async Task PollCaseInstanceCompleted(string id)
79+
{
80+
var httpResult = await _client.GetAsync($"http://localhost/case-instances/{id}");
81+
if (!httpResult.IsSuccessStatusCode)
82+
{
83+
Thread.Sleep(2);
84+
await PollCaseInstanceCompleted(id);
85+
return;
86+
}
87+
88+
var json = await httpResult.Content.ReadAsStringAsync();
89+
var jObj = JsonConvert.DeserializeObject<JObject>(json);
90+
if (!jObj.ContainsKey("status"))
91+
{
92+
Thread.Sleep(2);
93+
await PollCaseInstanceCompleted(id);
94+
return;
95+
}
96+
97+
var status = jObj["status"].ToString();
98+
if (status != "completed")
99+
{
100+
Thread.Sleep(2);
101+
await PollCaseInstanceCompleted(id);
102+
return;
103+
}
104+
}
105+
}
106+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
<PropertyGroup>
3+
<TargetFramework>netcoreapp2.2</TargetFramework>
4+
<OutputType>Exe</OutputType>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<PackageReference Include="Microsoft.AspNetCore.App" />
8+
<PackageReference Include="BenchmarkDotNet" Version="0.12.0" />
9+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="2.2.0" />
10+
</ItemGroup>
11+
<ItemGroup>
12+
<ProjectReference Include="..\CaseManagement.CMMN\CaseManagement.CMMN.csproj" />
13+
</ItemGroup>
14+
<ItemGroup>
15+
<None Update="Cmmns\caseWithTimerEventListener.cmmn">
16+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
17+
</None>
18+
</ItemGroup>
19+
</Project>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<cmmn:definitions xmlns:dc="http://www.omg.org/spec/CMMN/20151109/DC" xmlns:cmmndi="http://www.omg.org/spec/CMMN/20151109/CMMNDI" xmlns:cmmn="http://www.omg.org/spec/CMMN/20151109/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:di="http://www.omg.org/spec/CMMN/20151109/DI" id="caseWithTimerEventListener" targetNamespace="http://bpmn.io/schema/cmmn" exporter="cmmn-js (https://demo.bpmn.io/cmmn)" exporterVersion="0.19.2">
3+
<cmmn:case id="Case_0d1ujq8">
4+
<cmmn:casePlanModel id="CasePlanModel_0qazg9e" name="A case with TimerEvent">
5+
<cmmn:planItem id="PlanItem_04t8i1g" name="Send EMAIL" definitionRef="Task_1xaq99o">
6+
<cmmn:entryCriterion id="EntryCriterion_1emixlz" sentryRef="Sentry_1wpskn6" />
7+
</cmmn:planItem>
8+
<cmmn:planItem id="PlanItem_1wwlyh1" name="Timer" definitionRef="TimerEventListener_0shtnuf" />
9+
<cmmn:sentry id="Sentry_1wpskn6">
10+
<cmmn:planItemOnPart id="PlanItemOnPart_1xvq8dc" sourceRef="PlanItem_1wwlyh1">
11+
<cmmn:standardEvent>occur</cmmn:standardEvent>
12+
</cmmn:planItemOnPart>
13+
</cmmn:sentry>
14+
<cmmn:task id="Task_1xaq99o" name="Send EMAIL" />
15+
<cmmn:timerEventListener id="TimerEventListener_0shtnuf">
16+
<cmmn:timerExpression>R2/P0Y0M0DT0H0M2S</cmmn:timerExpression>
17+
</cmmn:timerEventListener>
18+
</cmmn:casePlanModel>
19+
</cmmn:case>
20+
<cmmndi:CMMNDI>
21+
<cmmndi:CMMNDiagram id="CMMNDiagram_1">
22+
<cmmndi:Size width="500" height="500" />
23+
<cmmndi:CMMNShape id="DI_CasePlanModel_0qazg9e" cmmnElementRef="CasePlanModel_0qazg9e">
24+
<dc:Bounds x="156" y="99" width="516" height="161" />
25+
<cmmndi:CMMNLabel />
26+
</cmmndi:CMMNShape>
27+
<cmmndi:CMMNShape id="PlanItem_04t8i1g_di" cmmnElementRef="PlanItem_04t8i1g">
28+
<dc:Bounds x="473" y="132" width="100" height="80" />
29+
<cmmndi:CMMNLabel />
30+
</cmmndi:CMMNShape>
31+
<cmmndi:CMMNShape id="EntryCriterion_1emixlz_di" cmmnElementRef="EntryCriterion_1emixlz">
32+
<dc:Bounds x="463" y="158" width="20" height="28" />
33+
<cmmndi:CMMNLabel />
34+
</cmmndi:CMMNShape>
35+
<cmmndi:CMMNEdge id="PlanItemOnPart_1xvq8dc_di" cmmnElementRef="PlanItemOnPart_1xvq8dc" targetCMMNElementRef="EntryCriterion_1emixlz" isStandardEventVisible="true">
36+
<di:waypoint x="315" y="172" />
37+
<di:waypoint x="463" y="172" />
38+
<cmmndi:CMMNLabel>
39+
<dc:Bounds x="372" y="162" width="34" height="13" />
40+
</cmmndi:CMMNLabel>
41+
</cmmndi:CMMNEdge>
42+
<cmmndi:CMMNShape id="PlanItem_05m34bi_di" cmmnElementRef="PlanItem_1wwlyh1">
43+
<dc:Bounds x="279" y="154" width="36" height="36" />
44+
<cmmndi:CMMNLabel>
45+
<dc:Bounds x="297" y="190" width="0" height="0" />
46+
</cmmndi:CMMNLabel>
47+
</cmmndi:CMMNShape>
48+
</cmmndi:CMMNDiagram>
49+
</cmmndi:CMMNDI>
50+
</cmmn:definitions>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Microsoft.AspNetCore;
2+
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.AspNetCore.Mvc.Testing;
4+
using Microsoft.Extensions.DependencyInjection;
5+
using System;
6+
7+
namespace CaseManagement.CMMN.Benchmark
8+
{
9+
public class CustomWebApplicationFactory<T> : WebApplicationFactory<T> where T : class
10+
{
11+
private readonly Action<IServiceCollection> _configureTestServices;
12+
13+
public CustomWebApplicationFactory(Action<IServiceCollection> configureTestServices = null)
14+
{
15+
_configureTestServices = configureTestServices;
16+
}
17+
18+
protected override IWebHostBuilder CreateWebHostBuilder()
19+
{
20+
return WebHost.CreateDefaultBuilder()
21+
.UseStartup(typeof(T));
22+
}
23+
24+
protected override void ConfigureWebHost(IWebHostBuilder builder)
25+
{
26+
base.ConfigureWebHost(builder);
27+
builder.UseContentRoot(".");
28+
builder.ConfigureServices(collection =>
29+
{
30+
_configureTestServices?.Invoke(collection);
31+
});
32+
}
33+
}
34+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using BenchmarkDotNet.Configs;
2+
using BenchmarkDotNet.Diagnosers;
3+
using BenchmarkDotNet.Exporters;
4+
using BenchmarkDotNet.Running;
5+
using System.Linq;
6+
7+
namespace CaseManagement.CMMN.Benchmark
8+
{
9+
public class Program
10+
{
11+
public static void Main(string[] args)
12+
{
13+
new BenchmarkSwitcher(typeof(Program).Assembly).Run(args, new Config());
14+
}
15+
16+
private class Config : ManualConfig
17+
{
18+
public Config()
19+
{
20+
Add(MemoryDiagnoser.Default);
21+
Add(MarkdownExporter.GitHub);
22+
Add(DefaultConfig.Instance.GetLoggers().ToArray());
23+
Add(DefaultConfig.Instance.GetColumnProviders().ToArray());
24+
}
25+
}
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:59507/",
7+
"sslPort": 0
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"environmentVariables": {
15+
"ASPNETCORE_ENVIRONMENT": "Development"
16+
}
17+
},
18+
"CaseManagement.CMMN.Benchmark": {
19+
"commandName": "Project",
20+
"launchBrowser": true,
21+
"environmentVariables": {
22+
"ASPNETCORE_ENVIRONMENT": "Development"
23+
},
24+
"applicationUrl": "http://localhost:59508/"
25+
}
26+
}
27+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using CaseManagement.Workflow.Domains;
2+
using Microsoft.AspNetCore.Builder;
3+
using Microsoft.AspNetCore.Hosting;
4+
using Microsoft.Extensions.DependencyInjection;
5+
using Microsoft.Extensions.Logging;
6+
using System.Collections.Generic;
7+
using System.IO;
8+
9+
namespace CaseManagement.CMMN.Benchmark
10+
{
11+
public class Startup
12+
{
13+
public void ConfigureServices(IServiceCollection services)
14+
{
15+
var builder = services.AddCMMN();
16+
builder.AddDefinitions(c =>
17+
{
18+
foreach (var file in Directory.EnumerateFiles(Path.Combine(Directory.GetCurrentDirectory(), "Cmmns"), "*.cmmn"))
19+
{
20+
c.ImportDefinition(file);
21+
}
22+
})
23+
.AddForms(new List<Form>
24+
{
25+
new Form
26+
{
27+
Id = "createMeetingForm",
28+
Elements = new List<FormElement>
29+
{
30+
new FormElement
31+
{
32+
Id = "name",
33+
Type = FormElementTypes.TXT
34+
}
35+
}
36+
}
37+
});
38+
services.AddLogging(b =>
39+
{
40+
b.AddFilter("Hangfire", LogLevel.Error);
41+
b.AddFilter("Microsoft", LogLevel.Error);
42+
b.AddFilter("System", LogLevel.Error);
43+
b.AddFilter("CaseManagement", LogLevel.Error);
44+
});
45+
}
46+
47+
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
48+
{
49+
app.UseCMMN();
50+
}
51+
}
52+
}

src/CaseManagement.CMMN/CaseInstance/CommandHandlers/LaunchCaseInstanceCommandHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public async Task Handle(LaunchCaseInstanceCommand launchCaseInstanceCommand)
3030
}
3131

3232

33-
caseInstance.Launch();
34-
await _commitAggregateHelper.Commit(caseInstance, caseInstance.GetStreamName());
33+
// caseInstance.Launch();
34+
// await _commitAggregateHelper.Commit(caseInstance, caseInstance.GetStreamName());
3535
await _queueProvider.QueueLaunchProcess(caseInstance.Id);
3636
}
3737
}

0 commit comments

Comments
 (0)