From b5e52636d92d900cd01d105035ec6609c5e18e21 Mon Sep 17 00:00:00 2001 From: Angshuman Sarkar Date: Tue, 18 Feb 2020 21:58:44 -0800 Subject: [PATCH 1/3] WIP: Create benchmark for PATCH using Queues --- .../Hexastore.PerfConsole.csproj | 1 + Hexastore.PerfConsole/PatchUpdateQueue.cs | 94 +++++++++++++++++++ Hexastore.PerfConsole/Program.cs | 12 ++- Hexastore.Rocks/Hexastore.Rocks.csproj | 1 + Hexastore.Test/Hexastore.Test.csproj | 2 + .../Controllers/StoreControllerBase.cs | 5 - Hexastore.Web/Hexastore.Web.csproj | 1 + Hexastore.Web/Queue/QueueContainer.cs | 5 + Hexastore.sln | 22 +++++ Hexastore/Hexastore.csproj | 1 + 10 files changed, 134 insertions(+), 10 deletions(-) create mode 100644 Hexastore.PerfConsole/PatchUpdateQueue.cs diff --git a/Hexastore.PerfConsole/Hexastore.PerfConsole.csproj b/Hexastore.PerfConsole/Hexastore.PerfConsole.csproj index a3d1b5d..4d87cc1 100644 --- a/Hexastore.PerfConsole/Hexastore.PerfConsole.csproj +++ b/Hexastore.PerfConsole/Hexastore.PerfConsole.csproj @@ -4,6 +4,7 @@ Exe netcoreapp3.1 NU1608 + AnyCPU;x64 diff --git a/Hexastore.PerfConsole/PatchUpdateQueue.cs b/Hexastore.PerfConsole/PatchUpdateQueue.cs new file mode 100644 index 0000000..32352e1 --- /dev/null +++ b/Hexastore.PerfConsole/PatchUpdateQueue.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Engines; +using Hexastore.Errors; +using Hexastore.Processor; +using Hexastore.Resoner; +using Hexastore.Rocks; +using Hexastore.TestCommon; +using Hexastore.Web; +using Hexastore.Web.EventHubs; +using Hexastore.Web.Queue; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json.Linq; + +namespace Hexastore.PerfConsole +{ + [SimpleJob(RunStrategy.Monitoring, invocationCount: 20)] + public class PatchUpdateQueue + { + private TestFolder _testFolder; + private StoreProcessor _storeProcessor; + private QueueContainer _queueContainer; + private EventSender _eventSender; + private List _ids = new List(); + private List _dataPoints = new List(); + private const int _updateCount = 20; + private const int _maxIds = 10; + private const int _maxPoints = 3; + + [GlobalSetup] + public void Setup() + { + _testFolder = new TestFolder(); + + while (_ids.Count < _maxIds) { + _ids.Add(Guid.NewGuid().ToString()); + } + + while (_dataPoints.Count < _maxPoints) { + _dataPoints.Add(Guid.NewGuid().ToString()); + } + + var factory = new LoggerFactory(); + var logger = factory.CreateLogger(); + var storeLogger = factory.CreateLogger(); + var graphProvider = new RocksGraphProvider(logger, _testFolder); + var storeProvider = new SetProvider(graphProvider); + _storeProcessor = new StoreProcessor(storeProvider, new Reasoner(), storeLogger); + var checkpoint = new Checkpoint(graphProvider); + var storeConfig = new StoreConfig(); + var eventReceiver = new EventReceiver(_storeProcessor, checkpoint, storeConfig, factory.CreateLogger()); + _queueContainer = new QueueContainer(eventReceiver, factory.CreateLogger(), new StoreError()); + _eventSender = new EventSender(_queueContainer, eventReceiver, checkpoint, storeConfig); + } + + [GlobalCleanup] + public void Cleanup() + { + _testFolder.Dispose(); + } + + [Benchmark] + public async Task RunTest() + { + var storeId = "test"; + var points = new Dictionary(); + var pointCount = 0; + foreach (var pointId in _dataPoints) { + pointCount++; + points.Add(pointId, pointCount + 0.234); + } + + for (var i = 0; i < _updateCount; i++) { + foreach (var id in _ids) { + var json = JsonGenerator.GenerateTelemetry(id, points); + await _eventSender.SendMessage( + new StoreEvent { + Data = json, + StoreId = storeId, + PartitionId = id, + Operation = "PATCH_JSON", + }); + } + } + + while(_queueContainer.Count() != 0) { + await Task.Delay(10); + } + } + } +} diff --git a/Hexastore.PerfConsole/Program.cs b/Hexastore.PerfConsole/Program.cs index 1787635..063fdeb 100644 --- a/Hexastore.PerfConsole/Program.cs +++ b/Hexastore.PerfConsole/Program.cs @@ -1,4 +1,5 @@ -using BenchmarkDotNet.Running; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Running; namespace Hexastore.PerfConsole { @@ -9,10 +10,11 @@ static void Main(string[] args) // These can be executed with: // dotnet run -c Release // Results will be in Hexastore.PerfConsole\BenchmarkDotNet.Artifacts\results - BenchmarkRunner.Run(); - BenchmarkRunner.Run(); - BenchmarkRunner.Run(); - BenchmarkRunner.Run(); + //BenchmarkRunner.Run(); + //BenchmarkRunner.Run(); + //BenchmarkRunner.Run(); + //BenchmarkRunner.Run(); + BenchmarkRunner.Run(); } } } diff --git a/Hexastore.Rocks/Hexastore.Rocks.csproj b/Hexastore.Rocks/Hexastore.Rocks.csproj index eb3ee9d..71af3d2 100644 --- a/Hexastore.Rocks/Hexastore.Rocks.csproj +++ b/Hexastore.Rocks/Hexastore.Rocks.csproj @@ -2,6 +2,7 @@ netstandard2.0 + AnyCPU;x64 diff --git a/Hexastore.Test/Hexastore.Test.csproj b/Hexastore.Test/Hexastore.Test.csproj index 8469d0e..df1dd98 100644 --- a/Hexastore.Test/Hexastore.Test.csproj +++ b/Hexastore.Test/Hexastore.Test.csproj @@ -4,6 +4,8 @@ netcoreapp3.1 false + + AnyCPU;x64 diff --git a/Hexastore.Web/Controllers/StoreControllerBase.cs b/Hexastore.Web/Controllers/StoreControllerBase.cs index 3ddc0c4..ba9673c 100644 --- a/Hexastore.Web/Controllers/StoreControllerBase.cs +++ b/Hexastore.Web/Controllers/StoreControllerBase.cs @@ -1,8 +1,5 @@ using System; -using System.Collections.Generic; -using System.IO; using System.Linq; -using System.Text; using System.Threading.Tasks; using Hexastore.Errors; using Hexastore.Web.Errors; @@ -10,8 +7,6 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; namespace Hexastore.Web.Controllers { diff --git a/Hexastore.Web/Hexastore.Web.csproj b/Hexastore.Web/Hexastore.Web.csproj index 2f75620..3dd44d0 100644 --- a/Hexastore.Web/Hexastore.Web.csproj +++ b/Hexastore.Web/Hexastore.Web.csproj @@ -4,6 +4,7 @@ netcoreapp3.1 InProcess Linux + AnyCPU;x64 diff --git a/Hexastore.Web/Queue/QueueContainer.cs b/Hexastore.Web/Queue/QueueContainer.cs index ce44800..b5e9659 100644 --- a/Hexastore.Web/Queue/QueueContainer.cs +++ b/Hexastore.Web/Queue/QueueContainer.cs @@ -42,6 +42,11 @@ public void Send(StoreEvent storeEvent) _queueWriters[partitionId].Send(storeEvent); } + public int Count() + { + return _queueWriters.Sum(x => x.Length); + } + private async Task LogQueueLength() { while (_running) { diff --git a/Hexastore.sln b/Hexastore.sln index 7f634dd..9399ed6 100644 --- a/Hexastore.sln +++ b/Hexastore.sln @@ -24,29 +24,51 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {83C88235-3496-4B18-AC09-D0F2F48D965B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {83C88235-3496-4B18-AC09-D0F2F48D965B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {83C88235-3496-4B18-AC09-D0F2F48D965B}.Debug|x64.ActiveCfg = Debug|x64 + {83C88235-3496-4B18-AC09-D0F2F48D965B}.Debug|x64.Build.0 = Debug|x64 {83C88235-3496-4B18-AC09-D0F2F48D965B}.Release|Any CPU.ActiveCfg = Release|Any CPU {83C88235-3496-4B18-AC09-D0F2F48D965B}.Release|Any CPU.Build.0 = Release|Any CPU + {83C88235-3496-4B18-AC09-D0F2F48D965B}.Release|x64.ActiveCfg = Release|x64 + {83C88235-3496-4B18-AC09-D0F2F48D965B}.Release|x64.Build.0 = Release|x64 {E20D0035-1E52-41B4-A244-DE4142AEF45E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E20D0035-1E52-41B4-A244-DE4142AEF45E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E20D0035-1E52-41B4-A244-DE4142AEF45E}.Debug|x64.ActiveCfg = Debug|x64 + {E20D0035-1E52-41B4-A244-DE4142AEF45E}.Debug|x64.Build.0 = Debug|x64 {E20D0035-1E52-41B4-A244-DE4142AEF45E}.Release|Any CPU.ActiveCfg = Release|Any CPU {E20D0035-1E52-41B4-A244-DE4142AEF45E}.Release|Any CPU.Build.0 = Release|Any CPU + {E20D0035-1E52-41B4-A244-DE4142AEF45E}.Release|x64.ActiveCfg = Release|x64 + {E20D0035-1E52-41B4-A244-DE4142AEF45E}.Release|x64.Build.0 = Release|x64 {5083D115-4595-41B8-9D6B-8C7474905D2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {5083D115-4595-41B8-9D6B-8C7474905D2B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5083D115-4595-41B8-9D6B-8C7474905D2B}.Debug|x64.ActiveCfg = Debug|x64 + {5083D115-4595-41B8-9D6B-8C7474905D2B}.Debug|x64.Build.0 = Debug|x64 {5083D115-4595-41B8-9D6B-8C7474905D2B}.Release|Any CPU.ActiveCfg = Release|Any CPU {5083D115-4595-41B8-9D6B-8C7474905D2B}.Release|Any CPU.Build.0 = Release|Any CPU + {5083D115-4595-41B8-9D6B-8C7474905D2B}.Release|x64.ActiveCfg = Release|x64 + {5083D115-4595-41B8-9D6B-8C7474905D2B}.Release|x64.Build.0 = Release|x64 {446D86FC-60E2-4467-BFC8-AE0A22BC38B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {446D86FC-60E2-4467-BFC8-AE0A22BC38B4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {446D86FC-60E2-4467-BFC8-AE0A22BC38B4}.Debug|x64.ActiveCfg = Debug|x64 + {446D86FC-60E2-4467-BFC8-AE0A22BC38B4}.Debug|x64.Build.0 = Debug|x64 {446D86FC-60E2-4467-BFC8-AE0A22BC38B4}.Release|Any CPU.ActiveCfg = Release|Any CPU {446D86FC-60E2-4467-BFC8-AE0A22BC38B4}.Release|Any CPU.Build.0 = Release|Any CPU + {446D86FC-60E2-4467-BFC8-AE0A22BC38B4}.Release|x64.ActiveCfg = Release|x64 + {446D86FC-60E2-4467-BFC8-AE0A22BC38B4}.Release|x64.Build.0 = Release|x64 {A657D874-2D65-4823-A9FC-1B2B867C56A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A657D874-2D65-4823-A9FC-1B2B867C56A0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A657D874-2D65-4823-A9FC-1B2B867C56A0}.Debug|x64.ActiveCfg = Debug|x64 + {A657D874-2D65-4823-A9FC-1B2B867C56A0}.Debug|x64.Build.0 = Debug|x64 {A657D874-2D65-4823-A9FC-1B2B867C56A0}.Release|Any CPU.ActiveCfg = Release|Any CPU {A657D874-2D65-4823-A9FC-1B2B867C56A0}.Release|Any CPU.Build.0 = Release|Any CPU + {A657D874-2D65-4823-A9FC-1B2B867C56A0}.Release|x64.ActiveCfg = Release|x64 + {A657D874-2D65-4823-A9FC-1B2B867C56A0}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Hexastore/Hexastore.csproj b/Hexastore/Hexastore.csproj index 6ea6c5c..c1ab972 100644 --- a/Hexastore/Hexastore.csproj +++ b/Hexastore/Hexastore.csproj @@ -2,6 +2,7 @@ netstandard2.0 + AnyCPU;x64 From 3ecfec8bdeed6881bcfb65c45e1083c82dfb2311 Mon Sep 17 00:00:00 2001 From: Angshuman Sarkar Date: Tue, 18 Feb 2020 22:08:55 -0800 Subject: [PATCH 2/3] Remove x64 build option --- .../Hexastore.PerfConsole.csproj | 1 - Hexastore.Rocks/Hexastore.Rocks.csproj | 1 - Hexastore.Test/Hexastore.Test.csproj | 1 - Hexastore.Web/Hexastore.Web.csproj | 1 - Hexastore.sln | 22 ------------------- Hexastore/Hexastore.csproj | 1 - 6 files changed, 27 deletions(-) diff --git a/Hexastore.PerfConsole/Hexastore.PerfConsole.csproj b/Hexastore.PerfConsole/Hexastore.PerfConsole.csproj index 4d87cc1..a3d1b5d 100644 --- a/Hexastore.PerfConsole/Hexastore.PerfConsole.csproj +++ b/Hexastore.PerfConsole/Hexastore.PerfConsole.csproj @@ -4,7 +4,6 @@ Exe netcoreapp3.1 NU1608 - AnyCPU;x64 diff --git a/Hexastore.Rocks/Hexastore.Rocks.csproj b/Hexastore.Rocks/Hexastore.Rocks.csproj index 71af3d2..eb3ee9d 100644 --- a/Hexastore.Rocks/Hexastore.Rocks.csproj +++ b/Hexastore.Rocks/Hexastore.Rocks.csproj @@ -2,7 +2,6 @@ netstandard2.0 - AnyCPU;x64 diff --git a/Hexastore.Test/Hexastore.Test.csproj b/Hexastore.Test/Hexastore.Test.csproj index df1dd98..5094589 100644 --- a/Hexastore.Test/Hexastore.Test.csproj +++ b/Hexastore.Test/Hexastore.Test.csproj @@ -5,7 +5,6 @@ false - AnyCPU;x64 diff --git a/Hexastore.Web/Hexastore.Web.csproj b/Hexastore.Web/Hexastore.Web.csproj index 3dd44d0..2f75620 100644 --- a/Hexastore.Web/Hexastore.Web.csproj +++ b/Hexastore.Web/Hexastore.Web.csproj @@ -4,7 +4,6 @@ netcoreapp3.1 InProcess Linux - AnyCPU;x64 diff --git a/Hexastore.sln b/Hexastore.sln index 9399ed6..7f634dd 100644 --- a/Hexastore.sln +++ b/Hexastore.sln @@ -24,51 +24,29 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU - Debug|x64 = Debug|x64 Release|Any CPU = Release|Any CPU - Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {83C88235-3496-4B18-AC09-D0F2F48D965B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {83C88235-3496-4B18-AC09-D0F2F48D965B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {83C88235-3496-4B18-AC09-D0F2F48D965B}.Debug|x64.ActiveCfg = Debug|x64 - {83C88235-3496-4B18-AC09-D0F2F48D965B}.Debug|x64.Build.0 = Debug|x64 {83C88235-3496-4B18-AC09-D0F2F48D965B}.Release|Any CPU.ActiveCfg = Release|Any CPU {83C88235-3496-4B18-AC09-D0F2F48D965B}.Release|Any CPU.Build.0 = Release|Any CPU - {83C88235-3496-4B18-AC09-D0F2F48D965B}.Release|x64.ActiveCfg = Release|x64 - {83C88235-3496-4B18-AC09-D0F2F48D965B}.Release|x64.Build.0 = Release|x64 {E20D0035-1E52-41B4-A244-DE4142AEF45E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E20D0035-1E52-41B4-A244-DE4142AEF45E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E20D0035-1E52-41B4-A244-DE4142AEF45E}.Debug|x64.ActiveCfg = Debug|x64 - {E20D0035-1E52-41B4-A244-DE4142AEF45E}.Debug|x64.Build.0 = Debug|x64 {E20D0035-1E52-41B4-A244-DE4142AEF45E}.Release|Any CPU.ActiveCfg = Release|Any CPU {E20D0035-1E52-41B4-A244-DE4142AEF45E}.Release|Any CPU.Build.0 = Release|Any CPU - {E20D0035-1E52-41B4-A244-DE4142AEF45E}.Release|x64.ActiveCfg = Release|x64 - {E20D0035-1E52-41B4-A244-DE4142AEF45E}.Release|x64.Build.0 = Release|x64 {5083D115-4595-41B8-9D6B-8C7474905D2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {5083D115-4595-41B8-9D6B-8C7474905D2B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5083D115-4595-41B8-9D6B-8C7474905D2B}.Debug|x64.ActiveCfg = Debug|x64 - {5083D115-4595-41B8-9D6B-8C7474905D2B}.Debug|x64.Build.0 = Debug|x64 {5083D115-4595-41B8-9D6B-8C7474905D2B}.Release|Any CPU.ActiveCfg = Release|Any CPU {5083D115-4595-41B8-9D6B-8C7474905D2B}.Release|Any CPU.Build.0 = Release|Any CPU - {5083D115-4595-41B8-9D6B-8C7474905D2B}.Release|x64.ActiveCfg = Release|x64 - {5083D115-4595-41B8-9D6B-8C7474905D2B}.Release|x64.Build.0 = Release|x64 {446D86FC-60E2-4467-BFC8-AE0A22BC38B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {446D86FC-60E2-4467-BFC8-AE0A22BC38B4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {446D86FC-60E2-4467-BFC8-AE0A22BC38B4}.Debug|x64.ActiveCfg = Debug|x64 - {446D86FC-60E2-4467-BFC8-AE0A22BC38B4}.Debug|x64.Build.0 = Debug|x64 {446D86FC-60E2-4467-BFC8-AE0A22BC38B4}.Release|Any CPU.ActiveCfg = Release|Any CPU {446D86FC-60E2-4467-BFC8-AE0A22BC38B4}.Release|Any CPU.Build.0 = Release|Any CPU - {446D86FC-60E2-4467-BFC8-AE0A22BC38B4}.Release|x64.ActiveCfg = Release|x64 - {446D86FC-60E2-4467-BFC8-AE0A22BC38B4}.Release|x64.Build.0 = Release|x64 {A657D874-2D65-4823-A9FC-1B2B867C56A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A657D874-2D65-4823-A9FC-1B2B867C56A0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A657D874-2D65-4823-A9FC-1B2B867C56A0}.Debug|x64.ActiveCfg = Debug|x64 - {A657D874-2D65-4823-A9FC-1B2B867C56A0}.Debug|x64.Build.0 = Debug|x64 {A657D874-2D65-4823-A9FC-1B2B867C56A0}.Release|Any CPU.ActiveCfg = Release|Any CPU {A657D874-2D65-4823-A9FC-1B2B867C56A0}.Release|Any CPU.Build.0 = Release|Any CPU - {A657D874-2D65-4823-A9FC-1B2B867C56A0}.Release|x64.ActiveCfg = Release|x64 - {A657D874-2D65-4823-A9FC-1B2B867C56A0}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Hexastore/Hexastore.csproj b/Hexastore/Hexastore.csproj index c1ab972..6ea6c5c 100644 --- a/Hexastore/Hexastore.csproj +++ b/Hexastore/Hexastore.csproj @@ -2,7 +2,6 @@ netstandard2.0 - AnyCPU;x64 From 7200d427863b39f5a5305d2b2bb7ddcc5d60980f Mon Sep 17 00:00:00 2001 From: Angshuman Sarkar Date: Tue, 18 Feb 2020 23:15:07 -0800 Subject: [PATCH 3/3] change run --- Hexastore.PerfConsole/PatchUpdateQueue.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Hexastore.PerfConsole/PatchUpdateQueue.cs b/Hexastore.PerfConsole/PatchUpdateQueue.cs index 32352e1..f968083 100644 --- a/Hexastore.PerfConsole/PatchUpdateQueue.cs +++ b/Hexastore.PerfConsole/PatchUpdateQueue.cs @@ -17,7 +17,7 @@ namespace Hexastore.PerfConsole { - [SimpleJob(RunStrategy.Monitoring, invocationCount: 20)] + [SimpleJob(RunStrategy.Monitoring, invocationCount: 5)] public class PatchUpdateQueue { private TestFolder _testFolder; @@ -26,8 +26,8 @@ public class PatchUpdateQueue private EventSender _eventSender; private List _ids = new List(); private List _dataPoints = new List(); - private const int _updateCount = 20; - private const int _maxIds = 10; + private const int _updateCount = 100; + private const int _maxIds = 128; private const int _maxPoints = 3; [GlobalSetup] @@ -63,7 +63,7 @@ public void Cleanup() } [Benchmark] - public async Task RunTest() + public async Task RunTestWithQueue() { var storeId = "test"; var points = new Dictionary();