Skip to content

Commit

Permalink
[REFACTOR] Assembler performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander van Delft committed Nov 21, 2024
1 parent a50a889 commit 0d136af
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 36 deletions.
4 changes: 2 additions & 2 deletions CDP4Common/CDP4Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net48;netstandard2.0</TargetFrameworks>
<Company>Starion Group S.A.</Company>
<Title>CDP4Common Community Edition</Title>
<VersionPrefix>27.4.0</VersionPrefix>
<VersionPrefix>27.4.1</VersionPrefix>
<Description>CDP4 Common Class Library that contains DTOs, POCOs</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael, Ahmed</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[ADD] SharpZipLibExtension Methods
[BUMP] Version to 27.4.1
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
54 changes: 54 additions & 0 deletions CDP4Dal.Tests/AssemblerTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace CDP4Dal.Tests
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;

Expand Down Expand Up @@ -191,6 +192,59 @@ public async Task AssertThatAssemblerSynchronizationWorks()
Assert.That(assembler.Cache.TryGetValue(new CacheKey(categoryToRemove.Iid, null), out lazyCat), Is.False);
}

[Test]
public async Task AssertThatAssemblerSynchronizationWorksFastEnough()
{
var assembler = new Assembler(this.uri, this.messageBus);

var domain = new Dto.DomainOfExpertise(Guid.NewGuid(), 1);
this.testInput.Add(domain);

for (var i = 0; i < 20000; i++)
{
this.testInput.Add(new Dto.ElementDefinition(Guid.NewGuid(), 1) {Owner = domain.Iid});
}

var sw = new Stopwatch();

sw.Reset();
sw.Start();

// 1st call of Synnchronize
await assembler.Synchronize(this.testInput);

sw.Stop();
var elapsed = sw.Elapsed;
await TestContext.Progress.WriteLineAsync($"First synchronize took {elapsed}");
// Modification of the input Dtos
Assert.That(assembler.Cache, Is.Not.Empty);
Assert.That(this.testInput.Count, Is.EqualTo(assembler.Cache.Count));

sw.Reset();
sw.Start();

// 1st call of Synnchronize
await assembler.Synchronize(this.testInput);

sw.Stop();
elapsed = sw.Elapsed;
await TestContext.Progress.WriteLineAsync($"Second synchronize took {elapsed}");
Assert.That(assembler.Cache, Is.Not.Empty);
Assert.That(this.testInput.Count, Is.EqualTo(assembler.Cache.Count));

sw.Reset();
sw.Start();

// 1st call of Synnchronize
await assembler.Synchronize(this.testInput);

sw.Stop();
elapsed = sw.Elapsed;
await TestContext.Progress.WriteLineAsync($"Third synchronize took {elapsed}");
Assert.That(assembler.Cache, Is.Not.Empty);
Assert.That(this.testInput.Count, Is.EqualTo(assembler.Cache.Count));
}

[Test]
public async Task AssertThatRevisionsAreCachedCorrectly()
{
Expand Down
13 changes: 4 additions & 9 deletions CDP4Dal/Assembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ public async Task Synchronize(IEnumerable<CDP4Common.DTO.Thing> dtoThings, bool
logger.Info("Start Synchronization of {0}", this.IDalUri);

var existentGuid =
this.Cache.Select(
x => new Tuple<CacheKey, int>(x.Value.Value.CacheKey, x.Value.Value.RevisionNumber))
.ToList();
new Dictionary<CacheKey, int>(this.Cache.ToDictionary(x => x.Value.Value.CacheKey, y => y.Value.Value.RevisionNumber));

this.CheckPartitionDependentContainmentContainerIds(dtoThings);

Expand Down Expand Up @@ -224,17 +222,14 @@ public async Task Synchronize(IEnumerable<CDP4Common.DTO.Thing> dtoThings, bool
if (succeed)
{
var thingObject = updatedLazyThing.Value;
var cacheId = new CacheKey(dtoThing.Iid, dtoThing.IterationContainerId);

if (!existentGuid.Select(x => x.Item1).Contains(cacheId))

if (!existentGuid.TryGetValue(cacheKey, out var cacheThingRevisionNumber))
{
this.messageBus.SendObjectChangeEvent(thingObject, EventKind.Added);
messageCounter++;
}
else
{
var cacheThingRevisionNumber = existentGuid.Single(x => x.Item1.Equals(cacheId)).Item2;

if (dtoThing.RevisionNumber > cacheThingRevisionNumber)
{
// send event if revision number has increased from the old cached version
Expand All @@ -243,7 +238,7 @@ public async Task Synchronize(IEnumerable<CDP4Common.DTO.Thing> dtoThings, bool
}
else if (dtoThing.RevisionNumber < cacheThingRevisionNumber)
{
if (this.Cache.TryGetValue(cacheId, out var cacheThing))
if (this.Cache.TryGetValue(cacheKey, out var cacheThing))
{
// send event if revision number is lower. That means that the original cached item was changed (revision was added!) ICDPMessageBus.Current.SendObjectChangeEvent(cacheThing.Value, EventKind.Updated);
this.messageBus.SendObjectChangeEvent(cacheThing.Value, EventKind.Updated);
Expand Down
4 changes: 2 additions & 2 deletions CDP4Dal/CDP4Dal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net48;netstandard2.0</TargetFrameworks>
<Company>Starion Group S.A.</Company>
<Title>CDP4Dal Community Edition</Title>
<VersionPrefix>27.4.0</VersionPrefix>
<VersionPrefix>27.4.1</VersionPrefix>
<Description>CDP4 Data Access Layer library, a consumer of an ECSS-E-TM-10-25 Annex C API</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael, Ahmed</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 27.4.0
[REFACTOR] Assembler performance
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions CDP4DalCommon/CDP4DalCommon.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Company>Starion Group S.A.</Company>
<Language>latest</Language>
<Title>CDP4DalCommon Community Edition</Title>
<VersionPrefix>27.4.0</VersionPrefix>
<VersionPrefix>27.4.1</VersionPrefix>
<Description>CDP4 Common Class Library that contains common types for any CDP4 server and the CDP4Dal</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Alex, Alexander, Nathanael, Antoine, Omar, Jaime</Authors>
Expand All @@ -21,7 +21,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 27.4.0
[BUMP] To CDP4Common 27.4.1
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
2 changes: 1 addition & 1 deletion CDP4JsonFileDal/CDP4JsonFileDal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net48;netstandard2.0</TargetFrameworks>
<Company>Starion Group S.A.</Company>
<Title>CDP4JsonFileDal Community Edition</Title>
<VersionPrefix>27.4.0</VersionPrefix>
<VersionPrefix>27.4.1</VersionPrefix>
<Description>CDP4 Json File Dal Plugin</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael</Authors>
Expand Down
4 changes: 2 additions & 2 deletions CDP4JsonSerializer/CDP4JsonSerializer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net48;netstandard2.0</TargetFrameworks>
<Company>Starion Group S.A.</Company>
<Title>CDP4JsonSerializer Community Edition</Title>
<VersionPrefix>27.4.0</VersionPrefix>
<VersionPrefix>27.4.1</VersionPrefix>
<Description>CDP4 JSON Serialization Library</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25 JSON</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 27.4.0
[BUMP] To CDP4Common 27.4.1
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
5 changes: 2 additions & 3 deletions CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net48;netstandard2.0</TargetFrameworks>
<Company>Starion Group S.A.</Company>
<Title>CDP4MessagePackSerializer Community Edition</Title>
<VersionPrefix>27.4.0</VersionPrefix>
<VersionPrefix>27.4.1</VersionPrefix>
<Description>CDP4 MessagePack Serialization Library</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Alex, Alexander, Nathanael, Antoine, Omar</Authors>
Expand All @@ -20,8 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25 MessagePack</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 27.4.0
[Update] To MessagePack 2.5.187
[BUMP] To CDP4Common 27.4.1
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions CDP4Reporting/CDP4Reporting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<Company>Starion Group S.A.</Company>
<Title>CDP4Reporting Community Edition</Title>
<VersionPrefix>27.4.0</VersionPrefix>
<VersionPrefix>27.4.1</VersionPrefix>
<Description>CDP4 Reporting</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Alex, Alexander</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 27.4.0
[BUMP] To CDP4Common 27.4.1
</PackageReleaseNotes>
<LangVersion>latest</LangVersion>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net48;netstandard2.0</TargetFrameworks>
<Company>Starion Group S.A.</Company>
<Title>CDP4RequirementsVerification Community Edition</Title>
<VersionPrefix>27.4.0</VersionPrefix>
<VersionPrefix>27.4.1</VersionPrefix>
<Description>CDP4 Class Library that provides requirement verification</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Alex, Alexander, Yevhen, Nathanael</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 27.4.0
[BUMP] To CDP4Common 27.4.1
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions CDP4Rules/CDP4Rules.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net48;netstandard2.0</TargetFrameworks>
<Company>Starion Group S.A.</Company>
<Title>CDP4Rules Community Edition</Title>
<VersionPrefix>27.4.0</VersionPrefix>
<VersionPrefix>27.4.1</VersionPrefix>
<Description>CDP4 Class Library that provides Model Analysis and Rule Checking</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Alex, Alexander, Yevhen, Nathanael</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 27.4.0
[BUMP] To CDP4Common 27.4.1
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions CDP4ServicesDal/CDP4ServicesDal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net48;netstandard2.0</TargetFrameworks>
<Company>Starion Group S.A.</Company>
<Title>CDP4ServicesDal Community Edition</Title>
<VersionPrefix>27.4.0</VersionPrefix>
<VersionPrefix>27.4.1</VersionPrefix>
<Description>CDP4ServicesDal Dal Plugin</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 27.4.0
[BUMP] To CDP4Common 27.4.1
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions CDP4ServicesMessaging/CDP4ServicesMessaging.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<Company>Starion Group S.A.</Company>
<Title>CDP4Common Community Edition</Title>
<VersionPrefix>27.4.0</VersionPrefix>
<VersionPrefix>27.4.1</VersionPrefix>
<Description>CDP4 Services Messaging is a Class Library that contains clients and messages class that can be used for inter services communication</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Alex, Alexander, Nathanael, Antoine</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 27.4.0
[BUMP] To CDP4Common 27.4.1
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
<LangVersion>latest</LangVersion>
Expand Down
4 changes: 2 additions & 2 deletions CDP4Web/CDP4Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<LangVersion>latest</LangVersion>
<Company>Starion Group S.A.</Company>
<Title>CDP4Web Community Edition</Title>
<VersionPrefix>27.4.0</VersionPrefix>
<VersionPrefix>27.4.1</VersionPrefix>
<Description>CDP4Web Dedicated Sdk for CDPServicesDal</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Alex, Alexander, Nathanael, Antoine, Omar, Jaime</Authors>
Expand All @@ -21,7 +21,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 27.4.0
[BUMP] To CDP4Common 27.4.1
[Update] to Microsoft.Extensions.Logging.Abstractions 8.0.2
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
4 changes: 2 additions & 2 deletions CDP4WspDal/CDP4WspDal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net48;netstandard2.0</TargetFrameworks>
<Company>Starion Group S.A.</Company>
<Title>CDP4WspDal Community Edition</Title>
<VersionPrefix>27.4.0</VersionPrefix>
<VersionPrefix>27.4.1</VersionPrefix>
<Description>CDP4 WSP Dal Plugin</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 27.4.0
[BUMP] To CDP4Common 27.4.1
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion pre-release.bat
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ ECHO.
for %%f in (%~dp0PreReleaseBuilds\*.nupkg) do (
(Echo "%%f" | FIND /I "symbols" 1>NUL) || (
echo Pushing %%f
dotnet nuget push "%%f" --source https://nuget.pkg.github.com/RHEAGROUP/index.json -k %apikey%
dotnet nuget push "%%f" --source https://nuget.pkg.github.com/STARIONGROUP/index.json -k %apikey%
)
)

Expand Down

0 comments on commit 0d136af

Please sign in to comment.